Papyrus Banner

Internationalization

Requirements

Requirements for the internationalization are this following:

Use case

The principal use case for this feature is this following:

Description

The internationalization is the way to manage your model with a specific language by labels. Like Eclipse, the internationalization is managed by the 'properties' file which are defined depending language as following (with for example, english language in US country):

Properties files in Model Explorer

Plugins

The plugins for the internationalization are the following:

How to use internationalization

Instead of name, the label of objects must be displayed in Papyrus.

How the labels are managed in properties file

Each element which have a label must be written in the properties file as following:

Example of internationalization labels

Infra (Diagrams and Tables)

For the Diagrams and the Tables, UML is not needed. So to use the internationalization, you just need to:

The LabelInternationalization class contains the following needed methods/functions:

Method/Function Parameters Description
getInstance The the instance of LabelInternationalization
getDiagramLabelWithoutName Diagram Get the label of the diagram without getting its name if label is not available
getDiagramLabel Diagram Get the label of the diagram or the name if the diagram label is not available
setDiagramLabel Diagram, String, Locale Set the label (in parameter) of the Diagram for the locale needed (if null, the current must be used) without using command
getSetDiagramLabelCommand EditingDomain, Diagram, String, Locale Get the command to set the label (in parameter) of the Diagram for the locale needed (if null, the current must be used)
getTableLabelWithoutName Table Get the label of the Table without getting its name if label is not available
getTableLabel Table Get the label of the Table or the name if the Table label is not available
setDiagramLabel Table, String, Locale Set the label (in prameter) of the Table for the locale needed (if null, the current must be used) without using command
getSetTableLabelCommand EditingDomain, Table, String, Locale Get the command to set the label (in parameter) of the Table for the locale needed (if null, the current must be used)

UML Named Elements

For the UML NamedElement, to use the internationalization, you just need to:

The UMLLabelInternationalization class contains following needed methods/functions:

Method/Function Parameters Description
getInstance The the instance of LabelInternationalization
getLabelWithoutName NamedElement Get the label of the NamedElement without getting its name if label is not available
getLabel NamedElement Get the label of the NamedElement or the name if the NamedElement label is not available
setLabel NamedElement, String, Locale Set the label (in parameter) of the NamedElement for the locale needed (if null, the current must be used) without using command
getSetLabelCommand EditingDomain, NamedElement, String, Locale Get the command to set the label (in parameter) of the NamedElement for the locale needed (if null, the current must be used)
getKeywordWithoutName Stereotype Get the keyword of the Stereotype without getting its name if keyword is not available
getKeyword Stereotype Get the keyword of the Stereotype or the name if the Stereotype keyword is not available
setKeyword Stereotype, String, Locale Set the keyword (in parameter) of the Stereotype for the locale needed (if null, the current must be used) without using command
getSetKeywordCommand EditingDomain, Stereotype, String, Locale Get the command to set the keyword (in parameter) of the Stereotype for the locale needed (if null, the current must be used)

Internationalization preferences

Preferences for internationalization usability

Two preferences are managed in the Papyrus model:

The preferences are stored as EAnnotation:

Internationalization model preferences management

Those preferences are managed in a PreferenceStore in the activator of org.eclipse.papyrus.infra.internationalization.common plugin.

The PapyrusProjectScope allows to manage the preferences for the Eclipse project with Papyrus model name.

Preferences for internationalization activation

Two preferences are managed for the internationalization activation:

Internationalization preferences management

Thoses preferences are stored in the PreferenceStore in the activator of org.eclipse.papyrus.infra.internationalization.common plugin and are managed by the org.eclipse.papyrus.infra.internationalization.common plugin.

Control mode

The sub-models are managed with the properties files. Indeed, when an object is created as sub-model, the key representing this object or its descendance in the properties files must be moved in sub-properties files corresponding to the controlled object. During this sub-model creation, the qualified names of the keys that are moved change, the new qualified names are calculated from the root of the sub-model.

What is it managed

The managed files/objects are:

How is it managed

The org.eclipse.papyrus.infra.internationalization.controlmode manage all the control mode for the internationalization.

The properties files are managed by:

The notation and the internationalization preference storage are managed by:

Specificities

Loading properties resources

The properties resources are loaded and managed by the InternationalizationResource class. The load is managed as following:

  1. Load the properties file contents (keys, values)
  2. Create the InternationalizationLibrary
  3. Loop on each keys, create the InternationalizationEntry (added in library) and try to resolve the key as object (Diagram, Table or UML element) with the InternationalizationKeyResolver.
  4. Set the InternationalizationLibrary to the resource contents

The InternationalizationResource need options for its load and save:

Model Resource

The InternationalizationResource are managed with a ModelResource. For the internationalization, the model resource is the UMLInternationalizationModelResource (UML plugins) inherit from InternationalizationModelResource (infra plugins).

The internationalization must be managed by a resource containing data from EMF meta-model according to the ‘*.properties’ file. The EMF meta-model can be similar to this one:

This data must be loaded and set when the resource set of the project will be opened. This must be managed as following:

To read the ‘*.properties’ file (if exists), the ‘ResourceBundle’ simplify this one. By example:

InternationalisationLibrary library = InternationalisationFactory.eINSTANCE.createInternationalisationLibrary();

ResourceBundle resourceBundle = ResourceBundle.getBundle(eObject, localize);

Enumeration keys = resourceBundle.getKeys();

while (keys.hasMoreElements()) {

    InternationalisationEntry entry = InternationalisationFactory.eINSTANCE.createInternationalisationEntry();

    String key = (String)keys.nextElement();

    entry.setKey(key);

    entry.setValue(resourceBundle.getString(key));

    library.getEntries().add(entry);

}

The internationalization library must be created as previously with String ‘key’ in a first way. To create the UML Element reference in a second way, two ways are possible:

InternationalizationKeyResolver

The InternationalizationKeyResolver and UMLInternationalizationKeyResolver manage the correct retrieve of Diagrams, Tables (infra plugins) and UML elements (UML plugins) by the keys and the correct save elements keys as specified previously.

Those ones are created respectively in the InternationalizationModelResource and UMLInternationalizationModelResource. This key resolver is needed for the InternationalizationResource and must be added to its options.

InternationalizationUMLItemProviderAdapterFactory

The InternationalizationUMLItemProviderAdapterFactory extends UMLItemProviderAdapterFactory and allows to redefine the ItemProvider of UML elements to get the Papyrus internationalization getLabel instead of UML getLabel.

If an ItemProvider of UML element needs to be redefined, the ItemProviderAdapterFactory must ihnerit from this class instead of UMLItemProviderAdapterFactory.

Diagram and Table owner QualifiedName

The diagrams and the tables are managed in the infra plugins, however, the owner of the diagram or table must be serialized in the properties file by its QualifiedName. So the owner QualifiedName is managed by the class QualifiedNameUtils and calculated manually.

Editors

The diagrams and tables are managed by the internationalization. To do this, the diagram and table editor must inherit from IInternationalizationEditor which allows to modify part name and refresh the editor with the label. If any new editor is comming with internationalization management, this one must ihnerit from IInternationalizationEditor too.