mirror of https://github.com/abpframework/abp.git
6 changed files with 73 additions and 23 deletions
@ -0,0 +1,13 @@ |
|||||
|
namespace Volo.Abp.Localization |
||||
|
{ |
||||
|
public interface ILanguageInfo |
||||
|
{ |
||||
|
string CultureName { get; } |
||||
|
|
||||
|
string UiCultureName { get; } |
||||
|
|
||||
|
string DisplayName { get; } |
||||
|
|
||||
|
string FlagIcon { get; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,27 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using JetBrains.Annotations; |
||||
|
|
||||
|
namespace Volo.Abp.Localization |
||||
|
{ |
||||
|
public static class LanguageInfoExtensions |
||||
|
{ |
||||
|
public static T FindByCulture<T>( |
||||
|
[NotNull] this IEnumerable<T> languages, |
||||
|
[NotNull] string cultureName, |
||||
|
[CanBeNull] string uiCultureName = null) |
||||
|
where T : class, ILanguageInfo |
||||
|
{ |
||||
|
if (uiCultureName == null) |
||||
|
{ |
||||
|
uiCultureName = cultureName; |
||||
|
} |
||||
|
|
||||
|
var languageList = languages.ToList(); |
||||
|
|
||||
|
return languageList.FirstOrDefault(l => l.CultureName == cultureName && l.UiCultureName == uiCultureName) |
||||
|
?? languageList.FirstOrDefault(l => l.CultureName == cultureName) |
||||
|
?? languageList.FirstOrDefault(l => l.UiCultureName == uiCultureName); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,25 @@ |
|||||
|
using JetBrains.Annotations; |
||||
|
|
||||
|
namespace Volo.Abp.Localization |
||||
|
{ |
||||
|
public static class LocalizationSettingHelper |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Gets a setting value like "en-US;en" and returns as splitted values like ("en-US", "en").
|
||||
|
/// </summary>
|
||||
|
/// <param name="settingValue"></param>
|
||||
|
/// <returns></returns>
|
||||
|
public static (string cultureName, string uiCultureName) ParseLanguageSetting([NotNull] string settingValue) |
||||
|
{ |
||||
|
Check.NotNull(settingValue, nameof(settingValue)); |
||||
|
|
||||
|
if (!settingValue.Contains(";")) |
||||
|
{ |
||||
|
return (settingValue, settingValue); |
||||
|
} |
||||
|
|
||||
|
var splitted = settingValue.Split(';'); |
||||
|
return (splitted[0], splitted[1]); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue