mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-05-02 00:58:21 +00:00
Add translation support to website, read user's language from settings
This commit is contained in:
parent
bfec7d788e
commit
3e18d79fa5
8 changed files with 103 additions and 33 deletions
|
@ -15,15 +15,12 @@ public static class LocalizationManager
|
|||
Console.WriteLine($"Attempting to load '{key}' for '{language}'");
|
||||
#endif
|
||||
|
||||
string resourceBasename;
|
||||
if (language == defaultLang)
|
||||
{
|
||||
resourceBasename = $"{namespaceStr}.{translationArea.ToString()}";
|
||||
}
|
||||
else
|
||||
{
|
||||
resourceBasename = $"{namespaceStr}.{translationArea.ToString()}.lang-{language}";
|
||||
}
|
||||
string resourceBasename = $"{namespaceStr}.{translationArea.ToString()}";
|
||||
|
||||
// We don't have an en-US .resx, so if we aren't using en-US then we need to add the appropriate language.
|
||||
// Otherwise, keep it to the normal .resx file
|
||||
// e.g. BaseLayout.resx as opposed to BaseLayout.lang-da-DK.resx.
|
||||
if (language != defaultLang) resourceBasename += $".lang-{language}";
|
||||
|
||||
ResourceManager resourceManager = new(resourceBasename, Assembly.GetExecutingAssembly());
|
||||
|
||||
|
@ -39,12 +36,12 @@ public static class LocalizationManager
|
|||
return localizedString;
|
||||
}
|
||||
|
||||
public static IEnumerable<string> GetAvailableLanguages(TranslationAreas translationArea)
|
||||
// This is a bit scuffed, but it will work for what I need it to do.
|
||||
public static IEnumerable<string> GetAvailableLanguages()
|
||||
{
|
||||
string area = translationArea.ToString();
|
||||
string area = TranslationAreas.BaseLayout.ToString();
|
||||
|
||||
// scuffed but it will work for now
|
||||
List<string> langs = Assembly.GetExecutingAssembly()
|
||||
List<string> languages = 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))
|
||||
|
@ -53,8 +50,8 @@ public static class LocalizationManager
|
|||
.Where(r => r != "resources")
|
||||
.ToList();
|
||||
|
||||
langs.Add(defaultLang);
|
||||
languages.Add(defaultLang);
|
||||
|
||||
return langs;
|
||||
return languages;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue