获取所有可用的文化从.resx文件组 [英] Get all available cultures from a .resx file group

查看:157
本文介绍了获取所有可用的文化从.resx文件组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要以编程方式列出一个RESX文件组可用的文化,但ResourceManager类似乎并没有帮助。

I need to programatically list the available cultures in a resx file group, but the ResourceManager class doesn't seem to help.

我可能有:

Labels.resx
Labels.fr-FR.resx
Labels.ro-RO.resx

但是,我怎么能找到这三个(或多少会有)文化在运行时?

However, how can I find these three (or how many would there be) cultures at runtime?

推荐答案

查找附属程序集的应用程序的目录:对于每个子目录,检查它的名字对应一个文化的名字,如果它包含了一个.resources.dll 文件:

Look for satellite assemblies in your application's directory : for each subdirectory, check if it's name corresponds to a culture name, and if it contains a '.resources.dll' file :

public IEnumerable<CultureInfo> GetAvailableCultures()
{
    var programLocation = Process.GetCurrentProcess().MainModule.FileName;
    var resourceFileName = Path.GetFileNameWithoutExtension(programLocation) + ".resources.dll";
    var rootDir = new DirectoryInfo(Path.GetDirectoryName(programLocation));
    return from c in CultureInfo.GetCultures(CultureTypes.AllCultures)
           join d in rootDir.GetDirectories() on c.IetfLanguageTag equals d.Name
           where d.GetFiles(resourceFileName).Any()
           select c;
}

这篇关于获取所有可用的文化从.resx文件组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆