C# WPF 应用程序中提供的区域性

本文关键字:区域性 WPF 应用程序 | 更新日期: 2023-09-27 18:32:47

我正在根据在 bin 中创建的文件夹进行本地化和拉取所有可用的区域性。 然后将文件夹的名称转换为区域性信息。

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 的一个运行时本地化示例的一部分

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

提前致谢

C# WPF 应用程序中提供的区域性

可以使用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)
{
    // ...
}