Procházet zdrojové kódy

misc: Cleanup locale validator

Evan Husted před 1 rokem
rodič
revize
8259f790d7

+ 9 - 12
src/Ryujinx.BuildValidationTasks/LocaleValidationTask.cs

@@ -14,20 +14,20 @@ namespace Ryujinx.BuildValidationTasks
         {
             string path = System.Reflection.Assembly.GetExecutingAssembly().Location;
 
-            if (path.Split(new string[] { "src" }, StringSplitOptions.None).Length == 1 )
+            if (path.Split(["src"], StringSplitOptions.None).Length == 1)
             {
                 //i assume that we are in a build directory in the solution dir
-                path = new FileInfo(path).Directory.Parent.GetDirectories("src")[0].GetDirectories("Ryujinx")[0].GetDirectories("Assets")[0].GetFiles("locales.json")[0].FullName;
+                path = new FileInfo(path).Directory!.Parent!.GetDirectories("src")[0].GetDirectories("Ryujinx")[0].GetDirectories("Assets")[0].GetFiles("locales.json")[0].FullName;
             }
             else
             {
-                path = path.Split(new string[] { "src" }, StringSplitOptions.None)[0];
-                path = new FileInfo(path).Directory.GetDirectories("src")[0].GetDirectories("Ryujinx")[0].GetDirectories("Assets")[0].GetFiles("locales.json")[0].FullName;
+                path = path.Split(["src"], StringSplitOptions.None)[0];
+                path = new FileInfo(path).Directory!.GetDirectories("src")[0].GetDirectories("Ryujinx")[0].GetDirectories("Assets")[0].GetFiles("locales.json")[0].FullName;
             }
 
             string data;
 
-            using (StreamReader sr = new StreamReader(path))
+            using (StreamReader sr = new(path))
             {
                 data = sr.ReadToEnd();
             }
@@ -38,13 +38,10 @@ namespace Ryujinx.BuildValidationTasks
             {
                 LocalesEntry locale = json.Locales[i];
 
-                foreach (string language in json.Languages)
+                foreach (string langCode in json.Languages.Where(it => !locale.Translations.ContainsKey(it)))
                 {
-                    if (!locale.Translations.ContainsKey(language))
-                    {
-                        locale.Translations.Add(language, "");
-                        Log.LogMessage(MessageImportance.High, $"Added {{{language}}} to Locale {{{locale.ID}}}");
-                    }
+                    locale.Translations.Add(langCode, string.Empty);
+                    Log.LogMessage(MessageImportance.High, $"Added '{langCode}' to Locale '{locale.ID}'");
                 }
 
                 locale.Translations = locale.Translations.OrderBy(pair => pair.Key).ToDictionary(pair => pair.Key, pair => pair.Value);
@@ -53,7 +50,7 @@ namespace Ryujinx.BuildValidationTasks
 
             string jsonString = JsonConvert.SerializeObject(json, Formatting.Indented);
 
-            using (StreamWriter sw = new StreamWriter(path))
+            using (StreamWriter sw = new(path))
             {
                 sw.Write(jsonString);
             }

+ 1 - 1
src/Ryujinx/Assets/locales.json

@@ -21574,4 +21574,4 @@
       }
     }
   ]
-}
+}