Jefim Borissov Житие мое

19Mar/102

Localizing a WPF application

I know, Google knows so much about this, yet still, no clear and simple step-by-step guide. So here it goes:

  • Download LocBaml tool here
  • Compile it and get the LocBaml.exe
  • Open your project file with Notepad.
  • Add the following there: <UICulture>en-US</UICulture> under all <PropertyGroup> tags (for all build configs that is).
  • In your XAML files add x:Uid="someUniqueUid" to any element you want to localize.
  • Build your project.
  • Navigate your explorer to the build folder - you will see that it has a new subfolder called en-US. Inside you will find a file - YourProject.resources.dll
  • Copy the binary of your project (e.g. YourProject.exe), LocBaml.exe and any referenced project binaries into this en-US folder.
  • Open a command line prompt in this folder (under Windows seven you can press [Shift] + Right click and choose the command prompt window from the context menu).
  • Run the following: locbaml /parse YourProject.resources.dll /out:YourProject.txt - a human-readable text file will appear in the folder.
  • Edit the text file (translate the values in it). Excel is your best option - open the file from Excel menu and it will ask you if you want to treat tab symbols as text separators).
  • Run the following after you localized the text file: locbaml /generate /trans:YourProject.txt /out:..\ru-RU /cul:ru-RU YourProject.resources.dll (replace ru-RU with the culture you are localizing into).
  • Now all you have to do is to set the CultureInfo for your application thread like this:
var cultureInfo = new CultureInfo("ru-RU");
System.Threading.CurrentThread.CurrentCulture = cultureInfo;
System.Threading.CurrentThread.CurrentUICulture = cultureInfo;

And you are done. You app should be localized now!

Filed under: Programming, WPF 2 Comments
19Mar/100

Loading Assebmlies with references

Recently I encountered this thing again and had to look for an answer for quite some time (again :) ).

Just an example of the assembly structure I wanted to have:

  • Main.exe
    • lib (folder)
      • Shared.dll (used by Main.exe, Plugin1.dll and Plugin2.dll)
      • Plugin1.dll
      • Plugin2.dll

The answer – open up your app.config from Main.exe project and add the following (under <configuration> tag):

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <probing privatePath="lib"/>
  </assemblyBinding>
</runtime>

That is it. Now it will also search for referenced libraries in the lib folder :)

Filed under: Assorted No Comments