initial
This commit is contained in:
61
Billing.Shared/Languages/PlatformCulture.cs
Normal file
61
Billing.Shared/Languages/PlatformCulture.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
namespace Billing.Languages
|
||||
{
|
||||
public partial class PlatformCulture
|
||||
{
|
||||
public string PlatformString { get; set; }
|
||||
public string LanguageCode { get; set; }
|
||||
public string LocaleCode { get; set; }
|
||||
|
||||
public string Language => string.IsNullOrEmpty(LocaleCode) ? LanguageCode : LanguageCode + "-" + LocaleCode;
|
||||
|
||||
public partial string GetNamespace();
|
||||
public partial void Init();
|
||||
|
||||
public PlatformCulture()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
private void Init(string cultureString)
|
||||
{
|
||||
if (string.IsNullOrEmpty(cultureString))
|
||||
{
|
||||
cultureString = "zh-CN";
|
||||
}
|
||||
|
||||
PlatformString = cultureString.Replace('_', '-');
|
||||
if (PlatformString.Contains('-'))
|
||||
{
|
||||
var parts = PlatformString.Split('-');
|
||||
LanguageCode = parts[0];
|
||||
LocaleCode = parts[^1];
|
||||
}
|
||||
else
|
||||
{
|
||||
LanguageCode = PlatformString;
|
||||
LocaleCode = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
private string ToDotnetFallbackLanguage()
|
||||
{
|
||||
string netLanguage = LanguageCode switch
|
||||
{
|
||||
// fallback to Portuguese (Portugal)
|
||||
"pt" => "pt-PT",
|
||||
// equivalent to German (Switzerland) for this app
|
||||
"gsw" => "de-CH",
|
||||
|
||||
// add more application-specific cases here (if required)
|
||||
// ONLY use cultures that have been tested and known to work
|
||||
|
||||
// use the first part of the identifier (two chars, usually);
|
||||
_ => LanguageCode,
|
||||
};
|
||||
Helper.Debug($".NET Fallback Language/Locale: {LanguageCode} to {netLanguage} (application-specific)");
|
||||
return netLanguage;
|
||||
}
|
||||
|
||||
public override string ToString() => PlatformString;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user