1

有没有办法获得 .net dll 的可用资源翻译?

我们的软件正在被翻译成一些不同的语言,我想让用户选择软件的语言,尽管我只想让他们在已翻译的语言之间进行选择。

4

2 回答 2

2

我刚遇到类似的问题,仅供参考。

对于我的软件翻译都在程序文件夹中,每个都在以文化名称命名的自己的子文件夹下。代码说明了一切:

    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

于 2009-09-07T13:22:36.290 回答
1

所以你需要能够得到base dll的culture,然后枚举所有satellite dll?

第一部分很简单(只需获取程序集级别属性)。

对于后者,ResourceManager 类似乎没有帮助器,这意味着您需要模拟其探测机制(可能包括所有可用于属性和 .config 文件的覆盖)。

另一种方法是在构建或安装时构建列表(如果以后可以添加其他语言,后者会更好),为 .config 文件创建一个列表。

于 2009-02-25T11:50:27.267 回答