Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 21 Next »

Icon

Available since Sonar 2.10

I18n (internationalization)

Icon

This page gives guidelines to I18n for:

  • Plugin developers who would like to apply the i18n mechanism in their own plugin, so that this plugin can be available in several languages
  • People who would like to help the community by making the platform available in a new language

Principles

Although the basics of the i18n mechanism are the same for every part of the ecosystem, the packaging differs if you want to apply this mechanism to the Sonar core platform or to a plugin:

  • Making the Sonar core platform available in a new language requires to develop and publish a new Language Pack plugin. By default Sonar embeds the English Pack. All other Language Pack plugins, like the French Pack plugin, are hosted in the plugins forge (https://svn.codehaus.org/sonar-plugins/trunk/l10n/), are maintained by the community and are available through Update Center (category "Localization").
  • This is different for plugins, each plugin is in charge to embed its own translations. Of course supporting i18n mechanism is not mandatory for a plugin but in that case it will only be available in the default implemented language.

To sum up

Icon
  • Sonar platform relies on plugins to get translations
  • Sonar plugins embed by themselves all the translations they need

Translation bundles

There are 2 types of files for localized messages:

Properties files

  • These are regular properties files with key/value pairs where you will put most translations
  • These files must be stored in the package "org.sonar.l10n" (usually in the directory src/main/resources/org/sonar/l10n)
  • The name of these files must respect the convention "<plugin key>_<language>.properties", for example "technicaldebt_fr.properties"
  • Messages accept arguments. Such entries would look like:
    myplugin.foo=This is a message with 2 params: the first "{0}" and the second "{1}".
    

HTML files

  • They are used for rule descriptions, which might be long and need HTML tags
  • These files must be stored in the package org.sonar.l10n.<plugin key>_<language>, for example org.sonar.l10n.checkstyle_fr
  • The name of these files must be the key of the rule they translate
  • E.g.: the French description of the Squid Architectural Constraint rule is "src/main/resources/org/sonar/i18n/squidjava_fr/ArchitecturalConstraint.html"

UTF-8 encoding

Icon

In the Java API, properties files are supposed to be encoded in ISO-8859 charset. Without good tooling, this can be quite annoying to write translation for languages that do not fit in this charset.
This is why we deciced to encode the properties files in UTF-8, and let Maven turn them into ASCII at build time thanks to native2ascii-maven-plugin (check the French plugin POM). This makes the process of writing translations with a standard editor far easier.
HTML files must also be encoded in UTF-8.

Naming conventions for keys

Here are the conventions you have to know about keys :

Key

Description

Example

metric.<key>.name

Metric name

metric.ncloc=Lines of code

metric.<key>.description

Metric description

metric.ncloc=Non Commenting Lines of Code

notification.channel.<channel key>

Name of notification channel

notification.channel.EmailNotificationChannel=Email

notification.dispatcher.<dispatcher key>

Subscription to notification channel

notification.dispatcher.ChangesInReviewAssignedToMeOrCreatedByMe=Changes in review assigned to me or created by me

rule.<repository>.<key>.name

Rule name

rule.pmd.StringInstantiation.name=String Instantiation

rule.<repository>.<key>.param.<param key>

Description of rule parameter

rule.pmd.VariableNamingConventions.param.memberSuffix=Suffix for member variables

widget.<key>.name

Widget name

widget.alerts.name=Alerts

widget.<key>.description

Widget description

widget.alerts.description=Display project alerts

widget.<key>.param.<property key>

Description of widget property

widget.alerts.param.threshold=Threshold

widget.<key>.*

Any other widget message

widget.alerts.tooltip=Threshold is raised

<page key>.page

Page names shown in the left sidebar

cloud.page=Cloud

<page key>.*

Any other keys used in a page

cloud.size=Size

<plugin key>.*

Any other keys used by plugin

 

How to use localized messages ?

TO BE DEFINED: Ruby and GWT API

How to contribute?

You are a plugin developer

Here are the main steps:

  1. Implement the LanguagePack extension point :
    • #getPluginKeys() should return only the key of your plugin
    • For each language that you want to support, you should add the corresponding locale to #getLocales() method

  2. Once you've implemented this extension point, you obviously have to declare this extension in your plugin class

  3. Use the I18n mechanism in your code
    • On Java side, use the I18nManager class
    • On Ruby on Rails side, use the #message helper method to translate your text
      • message('mypluginkey.a_key')
      • message('mypluginkey.a_key', :default => 'This is the default message')
      • message('mypluginkey.a_key'), :params => [rule.name, profile.name])

  4. Add translation files into the "src/main/resources/org/sonar/i18n/" folder
    • 1 properties file per language
    • 1 folder per language if you define new rules in your plugin and you need to translate their description

  5. And finally, translate the keys within those files!

You want to create a Language Pack plugin to offer a new translation to the Sonar platform

Here are the main steps:

  1. Check out the "I18n French Pack"

  2. *Create a new plugin, let's say the "I18n Japanese Pack", where you will copy and adapt files from the "I18n French Pack"
    • Create a JapanesePack extension, where you will just change the locale (not the #getPluginKeys() method)
    • Add the "_jp" extension to all the *.properties files that you have copied
    • Add the "_jp" extension to all the folders located in the same directory as the *.properties files

  3. And finally, translate the keys within those files!
  • No labels