-
Notifications
You must be signed in to change notification settings - Fork 522
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use 1 locales file instead of individual files for each langauge. This makes it easier to keep track of what is missing. The PR will automatically fix missing locales and throw an error if anything is incorrect, by running the emulator. That way the person adding a new locale or new language can just run the emulator once to populate all the fields, so they can easily begin translating.
- Loading branch information
Showing
28 changed files
with
21,728 additions
and
16,810 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using System; | ||
using Microsoft.Build.Utilities; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.IO; | ||
using Newtonsoft.Json; | ||
using Microsoft.Build.Framework; | ||
|
||
namespace Ryujinx.BuildValidationTasks | ||
{ | ||
public class LocaleValidationTask : Task | ||
{ | ||
public override bool Execute() | ||
{ | ||
string path = System.Reflection.Assembly.GetExecutingAssembly().Location; | ||
|
||
if (path.Split(new string[] { "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; | ||
} | ||
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; | ||
} | ||
|
||
string data; | ||
|
||
using (StreamReader sr = new StreamReader(path)) | ||
{ | ||
data = sr.ReadToEnd(); | ||
} | ||
|
||
LocalesJson json = JsonConvert.DeserializeObject<LocalesJson>(data); | ||
|
||
for (int i = 0; i < json.Locales.Count; i++) | ||
{ | ||
LocalesEntry locale = json.Locales[i]; | ||
|
||
foreach (string language in json.Languages) | ||
{ | ||
if (!locale.Translations.ContainsKey(language)) | ||
{ | ||
locale.Translations.Add(language, ""); | ||
Log.LogMessage(MessageImportance.High, $"Added {{{language}}} to Locale {{{locale.ID}}}"); | ||
} | ||
} | ||
|
||
locale.Translations = locale.Translations.OrderBy(pair => pair.Key).ToDictionary(pair => pair.Key, pair => pair.Value); | ||
json.Locales[i] = locale; | ||
} | ||
|
||
string jsonString = JsonConvert.SerializeObject(json, Formatting.Indented); | ||
|
||
using (StreamWriter sw = new StreamWriter(path)) | ||
{ | ||
sw.Write(jsonString); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
struct LocalesJson | ||
{ | ||
public List<string> Languages { get; set; } | ||
public List<LocalesEntry> Locales { get; set; } | ||
} | ||
|
||
struct LocalesEntry | ||
{ | ||
public string ID { get; set; } | ||
public Dictionary<string, string> Translations { get; set; } | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/Ryujinx.BuildValidationTasks/Ryujinx.BuildValidationTasks.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Build.Utilities.Core" /> | ||
<PackageReference Include="Newtonsoft.Json" /> | ||
</ItemGroup> | ||
|
||
<UsingTask TaskName="Ryujinx.BuildValidationTasks.LocaleValidationTask" TaskFactory="TaskHostFactory" AssemblyFile="$(OutDir)Ryujinx.BuildValidationTasks.dll" /> | ||
|
||
<Target Name="LocalesJsonValidation" AfterTargets="AfterRebuild"> | ||
<LocaleValidationTask /> | ||
</Target> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.