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:

  • 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

HTML files

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

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>.title

Widget name

widget.alerts.title=Alerts

widget.<key>.description

Widget description

widget.alerts.description=Display project alerts

widget.<key>.*

Any other widget message

widget.alerts.tooltip=Threshold is raised

<page key>.page

Page name shown in the left sidebar

cloud.page=Cloud

<plugin key>.*

Any other keys used by plugin

How to contribute?

You are a plugin developer

Here are the main steps:

  1. Implement the LanguagePack extension point :
  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
  4. Add translation files into the "src/main/resources/org/sonar/i18n/" folder
  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"
  3. And finally, translate the keys within those files!