📜 ⬆️ ⬇️

Localization of Eclipse plug-ins using the standard localization wizard

Recently, I started working on a Java project based on the Eclipse RCP platform and PDE . To localize the project, I used a fairly convenient standard localization wizard. It should be noted that there are two wizards: for localizing java code and for localizing the plugin.xml file, which includes the names of menus, dialogs, and so on. I will review both.

Code localization

- choose any class, package or entire src folder
')
image

- select “Source code” in the main menu - “Export lines” or press Alt + Shift + S and select “Export lines” in the context menu

image

- choose a class by double clicking or click the button “Export”

image

- then in the export dialog, select the lines that do not need to be localized (several lines can be selected with Ctrl or Shift), and on the right we press the “Ignore” button, or you can uncheck the box to the left, turning it into a cross.

image

- it is also desirable to have one access class in which to save all localizations. Initially, the class must be generated, and later it can be used for subsequent localizations, entering it in a special dialog or choosing from the drop-down list.

image

- after marking the lines that do not require localization and selecting the access class, press the “Next” button. The export dialog will show diff changes. As you can see, the localized lines are replaced with calls to a static variable from the Messages class, where values ​​from the properties file are inserted, and a comment like // $ NON-NLS-1 $ is added to the lines that do not require localization, where the digit indicates the fragment number, not to be localized (because there may be several).

image

- click "Finish" and the class is localized, go to the next.

There is a possibility that the class will not be localized correctly if there is a fragment that requires and does not require localization in one line. To check this, close the export dialog completely and re-open the list of classes requiring localization. Correctly localized classes will disappear from the list, and in the remaining ones, you need to correct the indexes in the $ NON-NLS comments - they must begin with 1 in ascending order and correspond to the number of fragments that do not require localization. To fix this is better using the Eclipse code editor.

image

After the code has been localized, you need to copy the messages.properties file into messages_ru.properties and translate all the lines into Russian, it will be automatically included in the distribution.

Localization plugin.xml

- select the plugin.xml file
- press the right mouse button and select “PDE Tools” - “Export Strings” in the context menu

image

- in the dialog that appears, uncheck the lines that do not require localization

image

- click "Next", look diff

image

- click “Finish”, copy bundle.properties to bundle_ru.properties, translate strings.

You must also include bundle_ru.properties in build.properties for localization to fall into the distribution.

PS Unfortunately, I could not localize the standard dialog wizards Search, Import, Export. Who knows how to do this, write to me in your personal mail.

Source: https://habr.com/ru/post/143742/


All Articles