Localize a .NET application with locbaml – excel – csvtransformer

illustration traduction pays et texte traduire

Your latest software creation is ready and should be disseminated beyond your borders? So it’s time to translate (localization) the resources used.

We will see in this ticket a simple way to do it using the appropriate tools:

• Visual studio compiler msbuild
• free tool Visual Locbaml

1. Preparing the application for localization

The localization of an application is the management of program elements that depend on a culture, which includes the notion of language, but also representations, such as dates and numbers with commas, and also the images (texts in the text). image or images adapted to the tastes of a culture).
The .NET framework manages culture for us, and the msbuild compilation plateform includes a task to prepare XAML files for translation.
Once the application is ready for translation, it must be prepared to run the tools. The first step is to indicate the language of development of the application so that msbuild can:

  • generate a main assembly
  • generate a satellite assembly (file with the .resources.dll extension) to contain the application’s neutral language resources

STEP 1: n the application’s .csproj file , add or edit the following line:

<UICulture>en-US</UICulture>

In the Properties/AssemblyInfo.cs, file , make sure you have the following line (add if necessary):

[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]

Replace en-US(the language of development of the application) by the one you used if it is not en-US.

STEP 2: Add Uids to XAMLs: Uids are used to keep track of file changes and to identify items that need to be translated. To add UIDs to XAML files you must start the task updateuid of msbiuld on the project file (from the Visual Studio command line):

msbuild /t:updateuid yourproject.csproj

Replace yourproject with the real name of your project file. Tip: UIds are generated from existing identifiers (id attribute) if they exist, otherwise from the name if defined, otherwise they are formed by the name of the tag postfixed by a number. It is always better to have a clear identifier that provides information on the nature of the text to be translated rather than a tag name.

It is possible to check that there are no missing or duplicate Uids using the task:

msbuild /t:checkuid yourproject.csproj

STEP 3: Recompile your project to generate a resource assembly of the neutral language. The satellite assemblies are placed in the compile output directory (eg bin / debug) in a subdirectory with the name of the culture (eg en-US)

2. Translation of resources with Visual Locbaml

Start by downloading the Visual Locbaml tool from the site visuallocbaml.com : visual locbaml download

Step 1: Launch Visual Locbaml, choose the option “Create a new project”. In the next window, specify the project’s compilation output path:

visual locbaml add binaries

The satellite assemblies are then identified by the tool and it is necessary to indicate the assembly which must be located (it corresponds to the main assembly):

visual locbaml select assembly

Then select Next . The tool scans the resources and the visual project Locbaml is ready to save texts to translate and integrate translations. Remember to save the project (.tsf file):

visual locbaml projet

Step 2: Add a translation. Click the Translations and then Add language, select the language from the drop-down list:

v

then click the Add button. The tool then allows to edit the translations for this new language in an integrated table. As we prefer to work in our favorite spreadsheet, we use the option Export for translation (also check the export already translated strings), which is used to make a CSV file:

visual locbaml export

After formatting, we obtain a sheet that should be informed:

feuille de traduction des textes

Then export to CSV format. Oops: Excel does not export with comma separator (Visual Locbaml prerequisites) … Choose to export in UNICODE text, which produces a UTF16LE file (you will keep all extended characters) with TAB as separator. We can then use the tool CSVTransformer proposed on this site which allows to change the separator used.

Download it from the page: Transform separators from a CSV file

we then use the command csvtransformer.exe as in the following example:

 > csvtransformer.exe
CSV Transformer 1.0.2.0
(c) 2018 Franck Gaspoz http://franckgaspoz.fr

command line syntax: inputFile inputFileFormat outputFile outputFileFormat [opts]
inputFileFormat,outputFileFormat: comma | semicolon | tab | space
opts:
-q : supress all outputs except errors
-f : force add of separators

wrong number of arguments

> csvtransformer translation_fr.txt tab import\translation_fr.csv comma -f
CSV Transformer 1.0.2.0
(c) 2018 Franck Gaspoz http://franckgaspoz.fr

transform: translation_fr.txt : tab -> import\translation_fr.csv : comma
done.

> more import\translation_fr.csv

"Id","Original string","Translation"
"1","Helvetica, Arial","Helvetica, Arial"
"2","M 0 4 L 8 4 L 4 0 Z","M 0 4 L 8 4 L 4 0 Z"
"3","M 0 0 L 4 4 L 8 0 Z","M 0 0 L 4 4 L 8 0 Z"
"4","M 4 0 L 4 8 L 0 4 Z","M 4 0 L 4 8 L 0 4 Z"
"5","M 0 0 L 4 4 L 0 8 Z","M 0 0 L 4 4 L 0 8 Z"
"6","Window border","Bordure de la fenêtre"
"7","Paint border","Paint border"
"8","Always","Always"
"9","When mouse is over border","When mouse is over border"
"10","Transparent border","Transparent border"
"11","No border (no move & no resize)","No border (no move & no resize)"
"12","Currently open","Currently open"
"13","Current language: ","Current language: "
...

note: you should use the option -f option to keep the spaces at the beginning and end of the text in the original file.

The resulting file is imported into the Visual Locbaml project via the Import translation button.

Step 3: Generate the satellite assembly for the new language. Click the Assemblies button and then Generate satellite assemblies. Visual Locbaml then builds a new directory named as the code of the new language that contains the satellite assembly of the translations:

visual locbaml generate assemblies

note: To change the language association with the satellite assembly, just change the directory name. For example, here we have a directory fr, we can rename it by fr-CA to associate the translation with the language French Canada.

The culture codes used by Microsoft are listed on the page: Culture Names and Identifiers (RFC 1766)

At this state the addition of the support of a new language in your application is effective and the translated texts will be used when the language of the OS will correspond to the language of the added translations (in this case French)

Leave a Reply