如何从dll获取可用的翻译 [英] How to get the available translations from a dll

查看:222
本文介绍了如何从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

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

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