如何从dll获取可用的翻译
是否可以获取.net dll的可用资源转换?
Is there a way to get the available resource translations of a .net dll?
我们的软件正在以几种不同的语言进行翻译,尽管我只希望让他们仅在已翻译的语言之间进行选择,但我还是希望让用户选择该软件所使用的语言.
Our software is being translated in some different languages, and I would like to give the user the choise of what language the software is in, although I would only like to let them choose only between the languages it has been translated in.
我刚刚遇到了类似的问题,仅供将来参考.
I just got similar problem so just for future reference.
对于我的软件,翻译都位于program文件夹中,每个翻译都在以文化名称命名的自己的子文件夹下.代码说明了一切:
For my software translations are in the program folder, each under their own subfolder named after culture name. Code explains it all:
private void SettingsForm_Load(object sender, EventArgs e)
{
// load default language to the list
languageList.Add(new Language("English", "en"));
string fileName = "myProgram.resources.dll";
// load other languages available in the folder
DirectoryInfo di = new DirectoryInfo(Application.StartupPath);
foreach (DirectoryInfo dir in di.GetDirectories())
{
if (File.Exists(dir.FullName + "\\" + fileName))
{
try
{
CultureInfo ci = new CultureInfo(dir.Name);
languageList.Add(new Language(ci.NativeName, ci.Name));
}
catch
{
// whatever happens just don't load the language and proceed ;)
continue;
}
}
}
}
它增加了一些异常处理开销,但是有多少用户将在安装目录中创建带有自定义文件的伪造资源的自定义文件夹? :P
It ads some exception handling overhead but how many users will create custom folders in the installation directory with the fake resource named exactly as localization file?? :P