diff --git a/ProjectLighthouse.Localization/BaseLayout.da-DK.resx b/ProjectLighthouse.Localization/BaseLayout.lang-da-DK.resx similarity index 94% rename from ProjectLighthouse.Localization/BaseLayout.da-DK.resx rename to ProjectLighthouse.Localization/BaseLayout.lang-da-DK.resx index e9e24854..50a2339a 100644 --- a/ProjectLighthouse.Localization/BaseLayout.da-DK.resx +++ b/ProjectLighthouse.Localization/BaseLayout.lang-da-DK.resx @@ -1,6 +1,7 @@ - + diff --git a/ProjectLighthouse.Localization/BaseLayout.en-UD.resx b/ProjectLighthouse.Localization/BaseLayout.lang-en-UD.resx similarity index 94% rename from ProjectLighthouse.Localization/BaseLayout.en-UD.resx rename to ProjectLighthouse.Localization/BaseLayout.lang-en-UD.resx index 9192fd03..0931388f 100644 --- a/ProjectLighthouse.Localization/BaseLayout.en-UD.resx +++ b/ProjectLighthouse.Localization/BaseLayout.lang-en-UD.resx @@ -1,6 +1,7 @@ - + diff --git a/ProjectLighthouse.Localization/BaseLayout.es-MX.resx b/ProjectLighthouse.Localization/BaseLayout.lang-es-MX.resx similarity index 94% rename from ProjectLighthouse.Localization/BaseLayout.es-MX.resx rename to ProjectLighthouse.Localization/BaseLayout.lang-es-MX.resx index 72657d39..a4498b21 100644 --- a/ProjectLighthouse.Localization/BaseLayout.es-MX.resx +++ b/ProjectLighthouse.Localization/BaseLayout.lang-es-MX.resx @@ -1,6 +1,7 @@ - + diff --git a/ProjectLighthouse.Localization/BaseLayout.ja-JP.resx b/ProjectLighthouse.Localization/BaseLayout.lang-ja-JP.resx similarity index 94% rename from ProjectLighthouse.Localization/BaseLayout.ja-JP.resx rename to ProjectLighthouse.Localization/BaseLayout.lang-ja-JP.resx index 2a576551..110c8042 100644 --- a/ProjectLighthouse.Localization/BaseLayout.ja-JP.resx +++ b/ProjectLighthouse.Localization/BaseLayout.lang-ja-JP.resx @@ -1,6 +1,7 @@ - + diff --git a/ProjectLighthouse.Localization/BaseLayout.pl-PL.resx b/ProjectLighthouse.Localization/BaseLayout.lang-pl-PL.resx similarity index 94% rename from ProjectLighthouse.Localization/BaseLayout.pl-PL.resx rename to ProjectLighthouse.Localization/BaseLayout.lang-pl-PL.resx index c6d5fd7e..cb01d7d1 100644 --- a/ProjectLighthouse.Localization/BaseLayout.pl-PL.resx +++ b/ProjectLighthouse.Localization/BaseLayout.lang-pl-PL.resx @@ -1,6 +1,7 @@ - + diff --git a/ProjectLighthouse.Localization/BaseLayout.ru-RU.resx b/ProjectLighthouse.Localization/BaseLayout.lang-ru-RU.resx similarity index 94% rename from ProjectLighthouse.Localization/BaseLayout.ru-RU.resx rename to ProjectLighthouse.Localization/BaseLayout.lang-ru-RU.resx index 85cb71dc..a95f118b 100644 --- a/ProjectLighthouse.Localization/BaseLayout.ru-RU.resx +++ b/ProjectLighthouse.Localization/BaseLayout.lang-ru-RU.resx @@ -1,6 +1,7 @@ - + diff --git a/ProjectLighthouse.Localization/BaseLayout.sv-SE.resx b/ProjectLighthouse.Localization/BaseLayout.lang-sv-SE.resx similarity index 94% rename from ProjectLighthouse.Localization/BaseLayout.sv-SE.resx rename to ProjectLighthouse.Localization/BaseLayout.lang-sv-SE.resx index fbf660ec..9b290691 100644 --- a/ProjectLighthouse.Localization/BaseLayout.sv-SE.resx +++ b/ProjectLighthouse.Localization/BaseLayout.lang-sv-SE.resx @@ -1,6 +1,7 @@ - + diff --git a/ProjectLighthouse.Localization/BaseLayout.zh-CN.resx b/ProjectLighthouse.Localization/BaseLayout.lang-zh-CN.resx similarity index 94% rename from ProjectLighthouse.Localization/BaseLayout.zh-CN.resx rename to ProjectLighthouse.Localization/BaseLayout.lang-zh-CN.resx index 3de6a44d..9a349a1b 100644 --- a/ProjectLighthouse.Localization/BaseLayout.zh-CN.resx +++ b/ProjectLighthouse.Localization/BaseLayout.lang-zh-CN.resx @@ -1,6 +1,7 @@ - + diff --git a/ProjectLighthouse.Localization/LocalizationManager.cs b/ProjectLighthouse.Localization/LocalizationManager.cs index 944947bb..1f3a2d30 100644 --- a/ProjectLighthouse.Localization/LocalizationManager.cs +++ b/ProjectLighthouse.Localization/LocalizationManager.cs @@ -7,14 +7,24 @@ namespace LBPUnion.ProjectLighthouse.Localization; public static class LocalizationManager { private static readonly string namespaceStr = typeof(LocalizationManager).Namespace ?? ""; + private const string defaultLang = "en-US"; public static string GetLocalizedString(TranslationAreas translationArea, string language, string key) { #if DEBUG - Console.WriteLine($"Attempting to load '{key}' for '{language}' "); + Console.WriteLine($"Attempting to load '{key}' for '{language}'"); #endif - string resourceBasename = $"{namespaceStr}.{translationArea.ToString()}.{language}"; + string resourceBasename; + if (language == defaultLang) + { + resourceBasename = $"{namespaceStr}.{translationArea.ToString()}"; + } + else + { + resourceBasename = $"{namespaceStr}.{translationArea.ToString()}.lang-{language}"; + } + ResourceManager resourceManager = new(resourceBasename, Assembly.GetExecutingAssembly()); string? localizedString = resourceManager.GetString(key); @@ -31,6 +41,20 @@ public static class LocalizationManager public static IEnumerable GetAvailableLanguages(TranslationAreas translationArea) { - return Assembly.GetExecutingAssembly().GetManifestResourceNames().Where(r => r.StartsWith($"{namespaceStr}.{translationArea.ToString()}")); + string area = translationArea.ToString(); + + // scuffed but it will work for now + List langs = Assembly.GetExecutingAssembly() + .GetManifestResourceNames() + .Where(r => r.StartsWith($"{namespaceStr}.{area}")) + .Select(r => r.Substring(r.IndexOf(area), r.Length - r.IndexOf(area)).Substring(area.Length + 1)) + .Select(r => r.Replace(".resources", string.Empty)) // Remove .resources + .Select(r => r.Replace("lang-", string.Empty)) // Remove 'lang-' prefix from languages + .Where(r => r != "resources") + .ToList(); + + langs.Add(defaultLang); + + return langs; } } \ No newline at end of file diff --git a/ProjectLighthouse.Localization/Program.cs b/ProjectLighthouse.Localization/Program.cs index 1e073030..45af94c6 100644 --- a/ProjectLighthouse.Localization/Program.cs +++ b/ProjectLighthouse.Localization/Program.cs @@ -1,14 +1,22 @@ +using System.Reflection; + namespace LBPUnion.ProjectLighthouse.Localization; public static class Program { public static void Main() { - Console.WriteLine(LocalizationManager.GetLocalizedString(TranslationAreas.BaseLayout, "en-UD", "header_home")); - Console.WriteLine("Available languages:"); + Console.WriteLine("Resource files loaded:"); + foreach (string resourceFile in Assembly.GetExecutingAssembly().GetManifestResourceNames()) + { + Console.WriteLine(" " + resourceFile); + } + + Console.Write('\n'); + foreach (string language in LocalizationManager.GetAvailableLanguages(TranslationAreas.BaseLayout)) { - Console.WriteLine(language); + Console.WriteLine(LocalizationManager.GetLocalizedString(TranslationAreas.BaseLayout, language, "header_home")); } } } \ No newline at end of file diff --git a/crowdin.yml b/crowdin.yml index de770400..2e6c5d14 100644 --- a/crowdin.yml +++ b/crowdin.yml @@ -1,6 +1,6 @@ preserve_hierarchy: true files: - source: /ProjectLighthouse.Localization/*.resx - translation: /ProjectLighthouse.Localization/%file_name%.%locale%.%file_extension% + translation: /ProjectLighthouse.Localization/%file_name%.lang-%locale%.%file_extension% ignore: - /ProjectLighthouse.Localization/%file_name%.*.%file_extension%