How to use localization in C#

后端 未结 9 2454
栀梦
栀梦 2020-11-22 02:59

I just can\'t seem to get localization to work.

I have a class library. Now I want to create resx files in there, and return some values based on the threa

9条回答
  •  盖世英雄少女心
    2020-11-22 03:07

    Great answer by F.Mörk. But if you want to update translation, or add new languages once the application is released, you're stuck, because you always have to recompile it to generate the resources.dll.

    Here is a solution to manually compile a resource dll. It uses the resgen.exe and al.exe tools (installed with the sdk).

    Say you have a Strings.fr.resx resource file, you can compile a resources dll with the following batch:

    resgen.exe /compile Strings.fr.resx,WpfRibbonApplication1.Strings.fr.resources 
    Al.exe /t:lib /embed:WpfRibbonApplication1.Strings.fr.resources /culture:"fr" /out:"WpfRibbonApplication1.resources.dll"
    del WpfRibbonApplication1.Strings.fr.resources
    pause
    

    Be sure to keep the original namespace in the file names (here "WpfRibbonApplication1")

提交回复
热议问题