Globalizing and Localizing .Net Class Library

In this page I'll explain how to localize a .net class library.

This in .Net 4.0 Context.
Step 1:
Add the <UICulture>en-US</UICulture> in the <Property Group> Section in the .csproj file. This informs the build process that you are creating a assembly which is targeted for "en-US" culture. After successful build it creates en-US folder next to the assembly to place the satellite assembly.
Step 2:
Add [assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] to the AssemblyInfo.cs. This adds information about the fallback localized resources location to the meta data. If the run time didn't found the en-US satellite assembly in the en-US folder, it won't load the assembly.
Step3:
To add localizable string resources add a resx file. As mentioned in step 2 en-US is the default culture of this assembly. So the file name should be like this. "Sample.en-US.resx"

This completes the globalizing process. 
After successful compilation you see LocDemo.dll in debug folder.
and in debug\en-US folder you see LocDemo.resources.dll.
[LocDemo is the assembly name]
Now Localize to a specific culture.
Step 4: Create a new resx file. Lets the target culture is de-DE. So the file name should be "Sample.de-DE.resx" in the Project folder next to "Sample.en-US.resx" but don't add to project which the Deutsche strings. 
Step 5: User resgen to generate the .resources for Sample.de-DE.resx. 
How?
1.Open visual studio command prompt
2.Set directory path to the project folder path.
3. sample command "resgen Sample.de-DE.resx LocDemo.Sample.de-DE.resources"
The out put file name should exactly the same as the one for en-US which is generated by the compiler. You can locate that in "obj\debug" folder.
Step 6: Now we need to generate the satellite assembly. Using "al" Assembly Linker.
Now type the following command in console
"al /t:lib /template:bin\debug\LocDemo.dll /embed:LocDemo.Sample.de-DE.resources /culture:de-DE /out:LocDemo.resource.dll
7. Now take this create folder "de-DE" next to LocDemo.dll and copy there.

This completes the de-DE localization process.
Comments