Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Papyrus/Papyrus Developer Guide/Externalize Strings In Java"

 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
====in java code====
+
==How to process to manage strings in your java plugin?==
 
#messages/string visible by the user must be in a Messages.properties file, located in a java package called '''your.plugin.name.messages'''
 
#messages/string visible by the user must be in a Messages.properties file, located in a java package called '''your.plugin.name.messages'''
 
#Exception message must not be translated, even if they are visible by the final user. We need to avoid to receive bugs with exception message in another language than english.
 
#Exception message must not be translated, even if they are visible by the final user. We need to avoid to receive bugs with exception message in another language than english.
Line 23: Line 23:
 
The method <code>String#format</code> should work fine too.
 
The method <code>String#format</code> should work fine too.
  
=====How to process to manage strings in your java file?=====
 
 
*step 1: Open the Externalization menu: Left Click -> Source-> Externalize Strings...:
 
  
 +
===step 1: Open the Externalization menu===
 +
Left Click -> Source-> Externalize Strings...:
  
 
[[File:ExternalizationMenu.png |1000px]]
 
[[File:ExternalizationMenu.png |1000px]]
  
*step 2: give a nice name to the string
 
  
 +
===step 2: Name the String===
 +
Give a nice name to the string
  
 
[[File:giveAniceName.png |1000px]]
 
[[File:giveAniceName.png |1000px]]
  
*step3: configure the output package
 
  
 +
===step 3: Configure the output package===
  
 
[[File:configureOutput.png |1000px]]
 
[[File:configureOutput.png |1000px]]
  
*step 4: the result
 
  
 +
===step 4: View the result===
  
 
[[File:resultExternalizationt.png |1000px]]
 
[[File:resultExternalizationt.png |1000px]]
  
=====How to process to manage strings in your plugin.xml file?=====
 
In plugin.xml, you should do the same thing, from the Overview tab. The output folder shouldn't changed:
 
  
 +
 +
==How to process to manage strings in your plugin.xml file?==
 +
In plugin.xml, you should do the same thing, from the Overview tab. The output folder shouldn't changed:
  
 
[[File:pluginExternalization.png |1000px]]
 
[[File:pluginExternalization.png |1000px]]
  
=====How to define if a string must be externalized creating a new extension point?=====
 
Set the field '''translatable''' to <code>true</code>:
 
  
 +
 +
==How to define if a string must be externalized creating a new extension point?==
 +
Set the field '''translatable''' to <code>true</code>:
  
 
[[File:pluginTranslatable.png |1000px]]
 
[[File:pluginTranslatable.png |1000px]]

Latest revision as of 05:09, 26 January 2018

How to process to manage strings in your java plugin?

  1. messages/string visible by the user must be in a Messages.properties file, located in a java package called your.plugin.name.messages
  2. Exception message must not be translated, even if they are visible by the final user. We need to avoid to receive bugs with exception message in another language than english.
  3. String hidden for the final user, must have the tag //$NON-NLS-index. (index starting to 1, with no space between the // and the $.
  4. Each string displayed to the user, must be written in one string:

Bad code:

String fileName = "aFileName";

String message = "The file " + fileName + " can't be found";

This message is splitted in 2 strings. It is not good, because the translator doesn't know what he is translating and the order of the words can change from english to another language, so we recommand:

Good code:

String fileName = "aFileName";

String message = NLS.bind("The file {0} can't be found", fileName);

In this message, there is only one string to translate, the translator, can move the {0} to the good location in the new language. The method String#format should work fine too.


step 1: Open the Externalization menu

Left Click -> Source-> Externalize Strings...:

ExternalizationMenu.png


step 2: Name the String

Give a nice name to the string

GiveAniceName.png


step 3: Configure the output package

ConfigureOutput.png


step 4: View the result

ResultExternalizationt.png


How to process to manage strings in your plugin.xml file?

In plugin.xml, you should do the same thing, from the Overview tab. The output folder shouldn't changed:

PluginExternalization.png


How to define if a string must be externalized creating a new extension point?

Set the field translatable to true:

PluginTranslatable.png

Back to the top