0

我正在根据 bin 中创建的文件夹进行本地化并提取所有可用的文化。然后将文件夹的名称转换为culturesInfo。

if (!bFoundInstalledCultures)
{
    //determine which cultures are available to this application
    Debug.WriteLine("Get Installed cultures:");
    CultureInfo tCulture = new CultureInfo("");
    foreach (string dir in Directory.GetDirectories(Application.StartupPath))
    {
        try
        {
            //see if this directory corresponds to a valid culture name
            DirectoryInfo dirinfo = new DirectoryInfo(dir);
            tCulture = CultureInfo.GetCultureInfo(dirinfo.Name);

            //determine if a resources dll exists in this directory that matches the executable name
            if (dirinfo.GetFiles(Path.GetFileNameWithoutExtension(Application.ExecutablePath) + ".resources.dll").Length > 0)
            {
                pSupportedCultures.Add(tCulture);
                Debug.WriteLine(string.Format(" Found Culture: {0} [{1}]", tCulture.DisplayName, tCulture.Name));
            }
        }
        catch(ArgumentException e) //ignore exceptions generated for any unrelated directories in the bin folder
        {
        }
    }
    bFoundInstalledCultures = true;

以上代码是 Codeproject.com 上的一个运行时本地化示例的一部分

是否有任何方法可以通过我们获取此信息并且我们可以使用反射。

提前致谢

4

1 回答 1

1

您可以使用CultureInfo.GetCultures获取所有已安装的文化:

//create an array of CultureInfo to hold all the cultures found, these include the users local cluture, and all the
//cultures installed with the .Net Framework
CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures & ~CultureTypes.NeutralCultures);

//loop through all the cultures found
foreach (CultureInfo culture in cultures)
{
    // ...
}
于 2013-09-24T14:38:41.827 回答