You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

82 lines
2.2 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Sog.Lang
{
public static class LanguageUtils
{
public const string DEFAULT_LANGUAGE = "en";
//尝试获取多语言字符串
public static string GetLanguageString(string content, string lang)
{
if(string.IsNullOrEmpty(content))
{
return content;
}
if(content.Length < 1)
{
return content;
}
//#开头的字符串表示是配置在多语言文件里的
if(content[0] == '#')
{
string lang_key = content.Substring(1);
LanguageDesc desc = LanguageDescMgr.Instance.GetConfig(lang_key);
if(desc == null)
{
return content;
}
string result = null;
if(lang == "en")
{
result = desc.EN;
}
else if(lang == "zh")
{
result = desc.ZH;
}
else
{
result = desc.EN;
}
return result;
}
else
{
return content;
}
}
/// <summary>
/// 根据客户端android,ios的语言转化成游戏里的语言标准配置字符(tk,en,zh,配表),
/// </summary>
/// <param name="language"></param>
/// <returns></returns>
public static string GetLangByClientOsLanguage(string language)
{
if(string.IsNullOrEmpty(language))
{
return DEFAULT_LANGUAGE;
}
string lower_language = language.ToLower();
var descList = LanguageAbbrCfgDescMgr.Instance.ItemTable;
foreach (var one in descList.Values)
{
if (lower_language == one.lang_abbr)
{
return one.lang_abbr;
}
}
return DEFAULT_LANGUAGE;
}
}
}