74 lines
2.2 KiB
C#
74 lines
2.2 KiB
C#
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
|
|
namespace Kreta.Framework.Util
|
|
{
|
|
/// <summary>
|
|
/// LCID alapján megmondja, hogy hanyadik indexű nyelv mezőt kell nézni.
|
|
/// </summary>
|
|
public class LanguageUtil
|
|
{
|
|
static Dictionary<string, int> m_LanguageIndexes = null;
|
|
|
|
private static LanguageUtil _instance;
|
|
public static LanguageUtil Instance
|
|
{
|
|
get
|
|
{
|
|
if (_instance == null)
|
|
{
|
|
_instance = new LanguageUtil();
|
|
}
|
|
|
|
return _instance;
|
|
}
|
|
}
|
|
|
|
private LanguageUtil()
|
|
{
|
|
InitializeLanguageIndexes();
|
|
}
|
|
|
|
static void InitializeLanguageIndexes()
|
|
{
|
|
Dictionary<string, int> result = new Dictionary<string, int>();
|
|
using (SDA.DataProvider.SDAConnection connection = SDAServer.Instance.CreateConnection())
|
|
{
|
|
connection.Open();
|
|
using (SDA.DataProvider.SDACommand command = connection.CreateCommand())
|
|
{
|
|
command.CommandText = @"select C_VALUE from T_SYSTEMPARAMETER where C_NAME = 'LANGUAGES'";
|
|
string temp = command.ExecuteScalar() as string;
|
|
if (temp != null)
|
|
{
|
|
string[] languages = temp.Split(',', ';');
|
|
for (int index = 0; index < languages.Length; index++)
|
|
{
|
|
result[languages[index].Trim().ToLower()] = index;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
m_LanguageIndexes = result;
|
|
}
|
|
|
|
public int GetLanguageIndex(int LCID)
|
|
{
|
|
var cultureInfo = new CultureInfo(LCID);
|
|
|
|
string key = cultureInfo.Name.ToLower().Substring(0, 2);
|
|
if (m_LanguageIndexes.TryGetValue(key, out int value))
|
|
{
|
|
return value;
|
|
}
|
|
|
|
if (!cultureInfo.IsNeutralCulture)
|
|
{
|
|
return GetLanguageIndex(cultureInfo.Parent.LCID);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
}
|
|
}
|