mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-05-01 00:38:21 +00:00
Working localization implementation!
This commit is contained in:
parent
be9ed3ac71
commit
c1e9fd361b
11 changed files with 55 additions and 15 deletions
|
@ -1,6 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<xsd:schema xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root">
|
||||
<xsd:schema xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root">
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
|
||||
</xsd:element>
|
|
@ -1,6 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<xsd:schema xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root">
|
||||
<xsd:schema xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root">
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
|
||||
</xsd:element>
|
|
@ -1,6 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<xsd:schema xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root">
|
||||
<xsd:schema xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root">
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
|
||||
</xsd:element>
|
|
@ -1,6 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<xsd:schema xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root">
|
||||
<xsd:schema xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root">
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
|
||||
</xsd:element>
|
|
@ -1,6 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<xsd:schema xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root">
|
||||
<xsd:schema xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root">
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
|
||||
</xsd:element>
|
|
@ -1,6 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<xsd:schema xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root">
|
||||
<xsd:schema xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root">
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
|
||||
</xsd:element>
|
|
@ -1,6 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<xsd:schema xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root">
|
||||
<xsd:schema xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root">
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
|
||||
</xsd:element>
|
|
@ -1,6 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<xsd:schema xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root">
|
||||
<xsd:schema xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root">
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
|
||||
</xsd:element>
|
|
@ -7,6 +7,7 @@ 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)
|
||||
{
|
||||
|
@ -14,7 +15,16 @@ public static class LocalizationManager
|
|||
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<string> 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<string> 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;
|
||||
}
|
||||
}
|
|
@ -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"));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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%
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue