简体   繁体   中英

localisation in vsto add-in

Is this the right way to implement localisation in VSTO Word Addin? Right now I just adhere to a naming convention where I append the Current Culture to the resource file it searches for. I've read enough different materials to be confused, one way was to use Resgen.exe then Al.exe to generate the .dll but I'm not understanding exactly why, is it to be able to update the language without having to recompile?

System.Resources.ResourceManager resMgr;
System.Globalization.CultureInfo ci = System.Threading.Thread.CurrentThread.CurrentCulture;
try
{
    // somehow I feel this isn't how it was meant to be? but it works
    resMgr = new System.Resources.ResourceManager("MyAddin.MyLocalisation." + ci, Assembly.GetExecutingAssembly());
    string title = resMgr.GetString("MyTitle");
}

The confusion is probably because there are (5) different ways to create resource files for desktop apps . Assembly Linker ( al.exe ) & Resource File Generator ( resgen.exe ) are the main tools used when working with localized resources. Resgen.exe will compile the resx ( XML ) into resources ( binary ), while al.exe will combine the resources ( binary ) into satellite assemblies ( dll ). Satellite assemblies are typically defined for each supported culture ( hub & spoke ). Satellite assemblies can be updated without requiring the application to be recompiled.


From MSDN :

You can include resources, such as strings, images, or object data, in resources files to make them easily available to your application. The .NET Framework offers five ways to create resources files :

1. Create a text file that contains string resources. You can use Resource File Generator (Resgen.exe) to convert the text file into a binary resource (.resources) file. You can then embed the binary resource file in an application executable or an application library by using a language compiler, or you can embed it in a satellite assembly by using Assembly Linker (Al.exe). For more information, see the Resources in Text Files section.

2. Create an XML resource (.resx) file that contains string, image, or object data. You can use Resource File Generator (Resgen.exe) to convert the .resx file into a binary resource (.resources) file. You can then embed the binary resource file in an application executable or an application library by using a language compiler, or you can embed it in a satellite assembly by using Assembly Linker (Al.exe). For more information, see the Resources in .resx Files section.

3. Create an XML resource (.resx) file programmatically by using types in the System.Resources namespace. You can create a .resx file, enumerate its resources, and retrieve specific resources by name. For more information, see the topic Working with .resx Files Programmatically.

4. Create a binary resource (.resources) file programmatically. You can then embed the file in an application executable or an application library by using a language compiler, or you can embed it in a satellite assembly by using Assembly Linker (Al.exe). For more information, see the Resources in .resources Files section.

5. Use Visual Studio to create a resource file and include it in your project. Visual Studio provides a resource editor that lets you add, delete, and modify resources. At compile time, the resource file is automatically converted to a binary .resources file and embedded in an application assembly or satellite assembly. For more information, see the Resource Files in Visual Studio section.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM