コード例 #1
0
 public static IDictionary <string, TranslationFile> GetTranslation(string translationName)
 {
     if (string.IsNullOrEmpty(translationName))
     {
         _translation = new Dictionary <string, TranslationFile>();
     }
     else if (!translationName.Equals(_name))
     {
         _translation = new Dictionary <string, TranslationFile>();
         string translationsDir = GetTranslationDir();
         if (Directory.Exists(translationsDir))
         {
             var result = Directory.EnumerateFiles(translationsDir, translationName + "*.xlf");
             foreach (var file in result)
             {
                 var name = Path.GetFileNameWithoutExtension(file).Substring(translationName.Length);
                 var t    = TranslationSerializer.Deserialize(file) ??
                            new TranslationFile();
                 t.SourceLanguage   = t.TranslationCategories.FirstOrDefault()?.SourceLanguage;
                 t.TargetLanguage   = t.TranslationCategories.FirstOrDefault()?.TargetLanguage;
                 _translation[name] = t;
             }
         }
     }
     _name = translationName;
     return(_translation);
 }
コード例 #2
0
        public static void SaveTranslation(string languageCode, IEnumerable <TranslationItemWithCategory> items, string filename)
        {
            Translation foreignTranslation = new Translation {
                GitExVersion = GitCommands.Settings.GitExtensionsVersionString,
                LanguageCode = languageCode
            };

            foreach (TranslationItemWithCategory translateItem in items)
            {
                if (translateItem.Status == TranslationType.Obsolete &&
                    (String.IsNullOrEmpty(translateItem.TranslatedValue) || String.IsNullOrEmpty(translateItem.NeutralValue)))
                {
                    continue;
                }

                TranslationItem ti = translateItem.GetTranslationItem().Clone();
                if (ti.Status == TranslationType.New)
                {
                    ti.Status = TranslationType.Unfinished;
                }
                Debug.Assert(!string.IsNullOrEmpty(ti.Value) || ti.Status != TranslationType.Translated);
                ti.Value = ti.Value ?? String.Empty;
                Debug.Assert(ti.Status != TranslationType.Translated || translateItem.IsSourceEqual(ti.Source));
                foreignTranslation.FindOrAddTranslationCategory(translateItem.Category).AddTranslationItem(ti);
            }
            TranslationSerializer.Serialize(foreignTranslation, filename);
        }
コード例 #3
0
        private void SaveAs()
        {
            var foreignTranslation = new Translation {
                LanguageCode = GetSelectedLanguageCode()
            };

            foreach (TranslateItem translateItem in translate)
            {
                //Item is not translated (yet), skip it
                if (string.IsNullOrEmpty(translateItem.TranslatedValue))
                {
                    continue;
                }

                if (!foreignTranslation.HasTranslationCategory(translateItem.Category))
                {
                    foreignTranslation.AddTranslationCategory(new TranslationCategory(translateItem.Category));
                }

                foreignTranslation.GetTranslationCategory(translateItem.Category).AddTranslationItem(new TranslationItem(translateItem.Name, translateItem.Property, translateItem.TranslatedValue));
            }

            var fileDialog = new SaveFileDialog {
                Title = saveAsText.Text, FileName = translations.Text + ".xml"
            };

            if (fileDialog.ShowDialog(this) == DialogResult.OK)
            {
                TranslationSerializer.Serialize(foreignTranslation, fileDialog.FileName);
                changesMade = false;
            }
        }
コード例 #4
0
        private void SaveAs()
        {
            var foreignTranslation = new Translation {
                LanguageCode = GetSelectedLanguageCode()
            };

            foreach (TranslateItem translateItem in translate)
            {
                string          value = translateItem.TranslatedValue ?? String.Empty;
                TranslationItem ti    = new TranslationItem(translateItem.Name, translateItem.Property,
                                                            translateItem.NeutralValue, value);
                ti.Status = translateItem.Status;
                if (ti.Status == TranslationType.Obsolete &&
                    (String.IsNullOrEmpty(value) || String.IsNullOrEmpty(translateItem.NeutralValue)))
                {
                    continue;
                }
                if (string.IsNullOrEmpty(value))
                {
                    if (ti.Status == TranslationType.Translated || ti.Status == TranslationType.New)
                    {
                        ti.Status = TranslationType.Unfinished;
                    }
                }
                else
                {
                    // TODO: Support in form
                    if (ti.Status == TranslationType.Unfinished)
                    {
                        ti.Status = TranslationType.Translated;
                    }
                }
                foreignTranslation.FindOrAddTranslationCategory(translateItem.Category).AddTranslationItem(ti);
            }

            using (var fileDialog =
                       new SaveFileDialog
            {
                Title = saveAsText.Text,
                FileName = translations.Text + ".xml",
                Filter = saveAsTextFilter.Text + "|*.xml",
                DefaultExt = ".xml",
                AddExtension = true
            })
            {
                if (fileDialog.ShowDialog(this) == DialogResult.OK)
                {
                    TranslationSerializer.Serialize(foreignTranslation, fileDialog.FileName);
                    changesMade = false;
                }
            }
        }
コード例 #5
0
ファイル: Translator.cs プロジェクト: serco425/gitextensions
 public static ITranslation GetTranslation(string translationName)
 {
     if (string.IsNullOrEmpty(translationName))
     {
         _translation = null;
     }
     else if (!translationName.Equals(_name))
     {
         _translation = TranslationSerializer.Deserialize(Path.Combine(GetTranslationDir(), translationName + ".xlf"));
     }
     _name = translationName;
     return(_translation);
 }
コード例 #6
0
        public static void SaveTranslation(string languageCode, IEnumerable <TranslationItemWithCategory> items, string filename)
        {
            var foreignTranslation = new Translation(GitCommands.AppSettings.GitExtensionsVersionString, languageCode);

            foreach (TranslationItemWithCategory translateItem in items)
            {
                var item = translateItem.GetTranslationItem();

                var ti = new TranslationItem(item.Name, item.Property, item.Source, item.Value);
                ti.Value = ti.Value ?? String.Empty;
                foreignTranslation.FindOrAddTranslationCategory(translateItem.Category).Body.AddTranslationItem(ti);
            }
            TranslationSerializer.Serialize(foreignTranslation, filename);
        }
コード例 #7
0
        public TranslationSerializerTest()
        {
            _target = new TranslationSerializer(CreateCatalog);

            _enCatalog.GetParticularString("Some context", "English message").Returns("English message");
            _enCatalog.GetString("Other English message").Returns("Other English message");
            _enCatalog.GetString("Quotes \"").Returns("Quotes \"");
            _enCatalog.GetParticularString("Some context", "English message {0}", 42).Returns("English message 42");
            _enCatalog.GetString("Other English message {0}", 42).Returns("Other English message 42");

            _daCatalog.GetParticularString("Some context", "English message").Returns("Dansk besked");
            _daCatalog.GetString("Other English message").Returns("Anden dansk besked");
            _daCatalog.GetString("Quotes \"").Returns("Gåseøjne \"");
            _daCatalog.GetParticularString("Some context", "English message {0}", 42).Returns("Dansk besked 42");
            _daCatalog.GetString("Other English message {0}", 42).Returns("Anden dansk besked 42");
        }
コード例 #8
0
        public static string SerializedGettext(IEnumerable <CultureInfo> cultureInfos, string msgId, params object[] args)
        {
            if (Localizer is null)
            {
                var message = args.Any() ? Localizer.Gettext(msgId, args) : Localizer.Gettext(msgId);

                return("{" + string.Join(", ", cultureInfos.Select(c => $"\"{c.Name}\": \"{HttpUtility.JavaScriptStringEncode(message)}\"")) + "}");
            }

            if (_translationSerializer == null)
            {
                _translationSerializer = new TranslationSerializer(Localizer.GetCatalog);
            }

            return(_translationSerializer.SerializedGettext(cultureInfos, msgId, args));
        }
コード例 #9
0
        private void SaveAs()
        {
            var foreignTranslation = new Translation {
                LanguageCode = GetSelectedLanguageCode()
            };

            if (foreignTranslation.LanguageCode != null)
            {
                foreach (TranslateItem translateItem in translate)
                {
                    //Item is not translated (yet), skip it
                    if (string.IsNullOrEmpty(translateItem.TranslatedValue))
                    {
                        continue;
                    }

                    TranslationItem ti = new TranslationItem(translateItem.Name, translateItem.Property, translateItem.TranslatedValue);
                    foreignTranslation.FindOrAddTranslationCategory(translateItem.Category).AddTranslationItem(ti);
                }
            }
            else
            {
                // English language
                foreach (TranslateItem translateItem in translate)
                {
                    TranslationItem ti = new TranslationItem(translateItem.Name, translateItem.Property, translateItem.NeutralValue);
                    foreignTranslation.FindOrAddTranslationCategory(translateItem.Category).AddTranslationItem(ti);
                }
            }

            var fileDialog =
                new SaveFileDialog
            {
                Title        = saveAsText.Text,
                FileName     = translations.Text + ".xml",
                Filter       = saveAsTextFilter.Text + "|*.xml",
                DefaultExt   = ".xml",
                AddExtension = true
            };

            if (fileDialog.ShowDialog(this) == DialogResult.OK)
            {
                TranslationSerializer.Serialize(foreignTranslation, fileDialog.FileName);
                changesMade = false;
            }
        }
コード例 #10
0
        public static void SaveTranslation(string targetLanguageCode,
                                           IDictionary <string, List <TranslationItemWithCategory> > items, string filename)
        {
            var ext = Path.GetExtension(filename);

            foreach (var pair in items)
            {
                var foreignTranslation = new TranslationFile(GitCommands.AppSettings.ProductVersion, "en", targetLanguageCode);
                foreach (var translateItem in pair.Value)
                {
                    var item = translateItem.GetTranslationItem();

                    var ti = new TranslationItem(item.Name, item.Property, item.Source, item.Value);
                    ti.Value = ti.Value ?? String.Empty;
                    foreignTranslation.FindOrAddTranslationCategory(translateItem.Category)
                    .Body.AddTranslationItem(ti);
                }
                var newfilename = Path.ChangeExtension(filename, pair.Key + ext);
                TranslationSerializer.Serialize(foreignTranslation, newfilename);
            }
        }
コード例 #11
0
 public static IDictionary <string, TranslationFile> GetTranslation(string translationName)
 {
     if (string.IsNullOrEmpty(translationName))
     {
         _translation = new Dictionary <string, TranslationFile>();
     }
     else if (!translationName.Equals(_name))
     {
         _translation = new Dictionary <string, TranslationFile>();
         var result = Directory.EnumerateFiles(GetTranslationDir(), translationName + "*.xlf");
         foreach (var file in result)
         {
             var name = Path.GetFileNameWithoutExtension(file).Substring(translationName.Length);
             var t    = TranslationSerializer.Deserialize(file) ??
                        new TranslationFile();
             _translation[name] = t;
         }
     }
     _name = translationName;
     return(_translation);
 }