wiki:Internationalization

Version 1 (modified by Sven Rech, 11 years ago) (diff)

--

This manual shows you how to internationalize your CrypTool 2.0 plugin. At the moment, we have the goal to completely support two languages: german and english.

Internationalizing your plugin consists of two steps: First externalize all your strings. After that, you can start translating. Of course, the first step is the most annoying one.

In the following steps, it is assumed, that you have ReSharper installed. ReSharper is a Visual Studio plugin which gives you a lot of cool features and makes your life much easier. It includes some very useful functions for internationalizing as you will see.

Externalizing your strings

First you have to externalize all the strings in your project that you want to translate. This means, that you want to redirect the access of these to strings to a resource file. When having multiple versions of this resource file (e.g. german and english), CrypTool will automatically choose the strings in the current language.

First we should discuss, which strings you should externalize and which not. You should externalize all strings which somehow appear on the GUI, so the end user can see them. Excluded from these are most of the GuiLogMessage strings, because they provide informations to experienced users (mostly developers) and don't aim at the end user. Also, you should never externalize strings which are for technical purposes only (e.g. file names).

When starting to externalize, you first need a resource file. If you don't already have one (which is the case for must plugin projects), you can create one by going to you project properties and choose the tab "Resources" on the left side. Than click on the appearing label to generate you resource file. IMAGE HERE

Now you need to externalize three things:

  • Strings from all your code files (i.e. from .cs files)
  • Strings from all your XAML files
  • MetaInformation Strings.

Lets start with the strings from your code files.

Externalizing strings from code

Go through all the code files of your project and watch out for strings you want to externalize.

For instance, I want to externalize the following string from the RSA class (I know I just said, that externalizing GuiLogMessages is not needed, but this is a very good example anyway): IMAGE HERE First, what annoys us here, is the string concatenation. We don't want to externalize this as two seperat strings, especially because it makes translating these strings harder. So we make use of the string.Format feature of .Net, by changing the code to the following:

GuiLogMessage(string.Format("Finished RSA on texts in {0} seconds!", duration.TotalSeconds), NotificationLevel.Info);

As you see, we only have one string now, which will be much easier to translate, because the context won't be lost. (By the way: ReSharper helps you forming your strings to the string.Format notation, just try it!)

After that, we can externalize the string. Move your cursor over the string. Then simply press Ctrl+Shift+R. The following should happen: IMAGE HERE Press enter (to choose the "Move to Resource..." feature). A ReSharper Dialog will open now: IMAGE HERE You should take special care of the proposed name and the selected Resource file. The name can't contain special characters like whitespaces. It follows the same rules as variable name in .Net. The proposed name "Finished_RSA_on_texts_in0seconds_" is ok, so we don't have to change it here. The selected Resource file is also the right one. But please always take a look at this, becaue sometimes ReSharper falsely chooses the resource file from the CrypPluginBase project, which should not be used''' So now press "Next" (or simply hit enter) and your string will be externalized:

GuiLogMessage(string.Format(Resources.Finished_RSA_on_texts_in__0__seconds_, duration.TotalSeconds), NotificationLevel.Info);

Externalizing strings from XAML

Externalizing strings from XAML is much harder, especially because ReSharper can't help you very much here (mostly because it seems to have a lot of bugs in its XAML externalizing functionality).

First you have to find out, in which namespace you resource class lies. You can do this by opening the Resources.Designer.cs class and take a look: IMAGE HERE So in the example, we know now, that our Resource class has the following path:

Cryptool.Plugins.Cryptography.Encryption.Properties.Resources

This is important now. Open the .xaml.cs file of the XAML file you want to externalize. Immediately before the class declaration, set the attribute:

[Cryptool.PluginBase.Attributes.Localization("RESOURCECLASSPATH")]

Here, you should replace RESOURCECLASSPATH by the above obtained resource class path: IMAGE HERE

Now your xaml file is ready to be externalized. Open the the .xaml file and watch out for all strings you want to externalize (Of course, you DON'T want to externalize things Attribtes like "Name" or "Visiblity").

Lets assume you want to externalize the following text attribute: IMAGE HERE

Simply replace this by:

<TextBlock Width="117.812" Height="29.237" Canvas.Left="112.482" Text="{Loc Encryption}" TextWrapping="Wrap" FontSize="24"/>

Now instead of setting the string "Encryption" directly, XAML gets the string from you resource file under the key "Encryption". So you have to create a new entry in your resource file with the key "Encryption" and the value "Encryption" (of course again you must take care that your key does not contain special characters. So when externalizing the string "Hello World", the key can be named something like "Hello_World") You can do this by opening your project settings and clicking the "Resources" tab. It shows you all entries. Simply add your new one: IMAGE HERE

Externalizing MetaInformation strings

TODO

Translating the resource file

TODO

Attachments (14)

Download all attachments as: .zip