Beispiel #1
0
        public static async Task TranslateLanguage(CTranslation sourceTranslation, CCulture @from, CCulture to, bool closeProgress = false)
        {
            await Common.ShowProgressMessage("Translating " + sourceTranslation.Culture.DisplayName + " language...", true);

            foreach (var node in sourceTranslation.Nodes)
            {
                node.Items = await TranslateNode(node.Title, node.Items, @from, to);
            }
            if (closeProgress)
            {
                await Common.ProgressController.CloseAsync();
            }
        }
Beispiel #2
0
 /// <summary>
 ///     Builds the languages list (on the left side of app)
 /// </summary>
 /// <returns></returns>
 public static async Task LoadTranslations(bool closeProgressAfterExecution)
 {
     await Task.Run(async() =>
     {
         await Common.ShowProgressMessage("Loading translations...", true);
         foreach (var lang in Projects.CurrentProject.Languages)
         {
             if (Directory.Exists(Path.Combine(Projects.CurrentProject.GetProjectRoot(), Projects.CurrentProject.SourcePath)))
             {
                 try
                 {
                     var files = Directory.GetFiles(CUtils.FixPath(Path.Combine(Projects.CurrentProject.GetProjectRoot(), Projects.CurrentProject.SourcePath, lang.ISO)), "*.archive");
                     if (files.Any())
                     {
                         var deserializedTranslation = JObject.Parse(File.ReadAllText(files[0]));
                         JToken vars;
                         JToken subnamespaces;
                         var isVarsValid          = deserializedTranslation.TryGetValue("Children", out vars);
                         var isSubnamespacesValid = deserializedTranslation.TryGetValue("Subnamespaces", out subnamespaces);
                         if (isVarsValid || isSubnamespacesValid)
                         {
                             var translationInstance = new CTranslation {
                                 Culture = lang, Path = files[0]
                             };
                             if (isVarsValid)
                             {
                                 var varsNode = new CTranslationNode {
                                     IsTopLevel = true, Title = "Variables"
                                 };
                                 foreach (var var in vars.Children())
                                 {
                                     var item = new CTranslationNodeItem {
                                         Source = var.Value <JToken>("Source").Value <string>("Text"), Translation = var.Value <JToken>("Translation").Value <string>("Text")
                                     };
                                     varsNode.Items.Add(item);
                                 }
                                 translationInstance.Nodes.Add(varsNode);
                             }
                             if (isSubnamespacesValid)
                             {
                                 foreach (var subnamespace in subnamespaces)
                                 {
                                     var subnamespacesNode = new CTranslationNode {
                                         Title = subnamespace.Value <string>("Namespace")
                                     };
                                     foreach (var val in subnamespace.Value <JToken>("Children").Children())
                                     {
                                         var item = new CTranslationNodeItem {
                                             Source = val.Value <JToken>("Source").Value <string>("Text"), Translation = val.Value <JToken>("Translation").Value <string>("Text")
                                         };
                                         subnamespacesNode.Items.Add(item);
                                     }
                                     translationInstance.Nodes.Add(subnamespacesNode);
                                 }
                             }
                             Projects.CurrentProject.Translations.Add(translationInstance);
                         }
                         else
                         {
                             Common.WriteToConsole("Something wrong with translation file. Please, run repair using Tools->Repair.", MessageType.Error);
                         }
                     }
                     else
                     {
                         Common.WriteToConsole("Translation file for " + lang.DisplayName + " language doesn't exist.", MessageType.Error);
                     }
                 }
                 catch (Exception ex)
                 {
                     Common.WriteToConsole(ex.Message, MessageType.Error);
                 }
             }
             else
             {
                 Common.WriteToConsole("Folder for " + lang.DisplayName + " language doesn't exist.", MessageType.Error);
             }
         }
         await Common.ShowProgressMessage("Sorting...", true);
         Projects.CurrentProject.Translations          = Projects.CurrentProject.Translations.OrderBy(translation => translation.Culture.ISO).ToObservableList();
         Projects.CurrentProject.IsTranslationsChanged = false;
         await Application.Current.Dispatcher.InvokeAsync(() => ((MainWindow)Application.Current.MainWindow).LanguagesList.SelectedIndex = 0);
         if (closeProgressAfterExecution)
         {
             await Common.ProgressController.CloseAsync();
         }
     });
 }