mirror of
https://github.com/bitwarden/android.git
synced 2024-11-01 15:45:42 +03:00
44 lines
1.3 KiB
C#
44 lines
1.3 KiB
C#
|
using System;
|
|||
|
|
|||
|
namespace Bit.App.Models
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// Helper class for splitting locales like
|
|||
|
/// iOS: ms_MY, gsw_CH
|
|||
|
/// Android: in-ID
|
|||
|
/// into parts so we can create a .NET culture (or fallback culture)
|
|||
|
/// </summary>
|
|||
|
public class PlatformCulture
|
|||
|
{
|
|||
|
public PlatformCulture(string platformCultureString)
|
|||
|
{
|
|||
|
if(string.IsNullOrWhiteSpace(platformCultureString))
|
|||
|
{
|
|||
|
throw new ArgumentException("Expected culture identifier", nameof(platformCultureString));
|
|||
|
}
|
|||
|
|
|||
|
// .NET expects dash, not underscore
|
|||
|
PlatformString = platformCultureString.Replace("_", "-");
|
|||
|
var dashIndex = PlatformString.IndexOf("-", StringComparison.Ordinal);
|
|||
|
if(dashIndex > 0)
|
|||
|
{
|
|||
|
var parts = PlatformString.Split('-');
|
|||
|
LanguageCode = parts[0];
|
|||
|
LocaleCode = parts[1];
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
LanguageCode = PlatformString;
|
|||
|
LocaleCode = "";
|
|||
|
}
|
|||
|
}
|
|||
|
public string PlatformString { get; private set; }
|
|||
|
public string LanguageCode { get; private set; }
|
|||
|
public string LocaleCode { get; private set; }
|
|||
|
public override string ToString()
|
|||
|
{
|
|||
|
return PlatformString;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|