SubtitleEdit/libse/CultureExtensions.cs
Nikolaj Olsson 3153326be6 Encapsulate "CultureInfo.ThreeLetterISOLanguageName"
(fix problems with Mono/Wine)
2020-04-16 10:31:27 +02:00

29 lines
1.1 KiB
C#

using System.Globalization;
namespace Nikse.SubtitleEdit.Core
{
public static class CultureExtensions
{
/// <summary>
/// Get three letter ISO code from CultureInfo object (three letter ISO code seems to be blank sometimes on Mono/Wine).
/// </summary>
/// <param name="cultureInfo">CultureInfo object</param>
/// <returns>Three letter ISO language code, if failure then string.Empty is returned.</returns>
public static string GetThreeLetterIsoLanguageName(this CultureInfo cultureInfo)
{
if (cultureInfo == null)
{
return string.Empty;
}
var cultureThreeLetterIsoLanguageName = cultureInfo.ThreeLetterISOLanguageName;
if (string.IsNullOrEmpty(cultureThreeLetterIsoLanguageName))
{
cultureThreeLetterIsoLanguageName = Iso639Dash2LanguageCode.GetThreeLetterCodeFromTwoLetterCode(cultureInfo.TwoLetterISOLanguageName);
}
return cultureThreeLetterIsoLanguageName;
}
}
}