如何嵌入多语言*的.resx(或*的.resources)文件中的单EXE? [英] How to embed multilanguage *.resx (or *.resources) files in single EXE?

查看:128
本文介绍了如何嵌入多语言*的.resx(或*的.resources)文件中的单EXE?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有很多教程如何建立多语言RESX文件,以及如何创建具有卫星Al.exe工具集,但我还没有找到工作示例如何嵌入在单EXE文件RESX /资源/卫星DLL文件并分发整个多语言应用本身EXE。

There are plenty of tutorials how to create multilanguage RESX files and how to create satellite assemblies with AL.exe, but I haven't found working example how to embed RESX/Resources/satellite-DLL files in single EXE file and distribute whole multilanguage app as such EXE.

我试图用ilmerge.exe,但它看起来像它不具有相同名称的多个DLL(文化卫星工作的DLL具有相同的名称,原来居住在培养后命名的子目录不同)。

I tried to use ilmerge.exe, but it looks like it doesn't work for multiple DLLs with the same name (culture satellite DLLs have identical names, originally residing in different subdirs named after culture).

我也不知道如何创建ResourceManager的实例内嵌资源工作。

I also don't know how to create ResourceManager instance to work with embedded resources.

我的目标是使封闭,组预定义的语言之间切换动力。我需要的类/方法,将根据获得文化的字符串(如去DE),资源名称(即CancelText),并返回翻译文本的嵌入式的RESX /资源/ DLL。

My goals is to enable dynamical switching between closed, pre-defined set of languages. I need class/method which will get culture string (i.e. "de-DE"), resource name (i.e. "CancelText") and return translated text based on embedded resx/resource/dll.

我使用VS2008,请注意,建设行动是什么设置是必要的RESX /资源文件属性表。 。工作示例代码或链接教程项目将是最好的。

I'm using VS2008, please note what setting for "build action" is needed in resx/resource files properties sheet. Working code sample or link to tutorial project would be the best.

推荐答案

我的解决方案:方案只包含一个默认的语言资源文件( RESX)。其他所有的语言都将从给的.resx编译的.resources和嵌入式的资源文件。重要!我已经改变了扩展的原因的.resources被公认为是一种特殊类型的资源,所以我的法文文件被命名为PIAE.LangResources.fr。

My solution: program contains only one default language resource file (resx). All other languages are compiled from .resx to .resources and embedded as resource file. Important! I have changed extension because ".resources" is recognized as a special type of resource, so my French files is named "PIAE.LangResources.fr".

下面是简单

    internal static string GetString(string str, string lang)
    {

        if (string.IsNullOrEmpty(str)) throw new ArgumentNullException("empty language query string");
        if (string.IsNullOrEmpty(lang)) throw new ArgumentNullException("no language resource given");

        // culture-specific file, i.e. "LangResources.fr"
        Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("PIAE.LangResources."+lang);

        // resource not found, revert to default resource
        if (null == stream)
        {                                                                   
            stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("PIAE.Properties.LangResources.resources");
        }

        ResourceReader reader = new ResourceReader(stream);
        IDictionaryEnumerator en= reader.GetEnumerator();
        while (en.MoveNext())
        {
            if (en.Key.Equals(str))
            {
                return en.Value.ToString();
            }
        }

        // string not translated, revert to default resource
        return LangResources.ResourceManager.GetString(str);
    }

这篇关于如何嵌入多语言*的.resx(或*的.resources)文件中的单EXE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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