Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Info
titleI18n (internationalization)

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

Table of Contents
outlinetrue

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:

...

  • 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:

    No Format
    
    myplugin.foo=This is a message with 2 params: the first "{0}" and the second "{1}".
    

...

This API is used when implementing Ruby widgets or pages. It's really simple, a single method must be used :

Code Block

message(property_key, options={})

...

  • :default is the default value when the property key does not exist in bundles. If it's not set, then the key itself is returned.
  • :params is an array of string message arguments.

Examples :

Code Block

message('cloud.size')
message('cloud.size', :default => 'Cloud')
message('with.arguments', :params => ['First', 'Two'])
message('with.arguments', :params => ['First', 'Two'], :default => 'Not found')

Of course the Rails framework provides other formatting methods like :

Code Block

# localize dates or datetimes
l(date_or_time)

...

The component org.sonar.api.i18n.I18n is available for server extensions. Batch extensions are not supported yet and can not load bundles.

How to contribute

How to

...

localize a

...

Simply copy and translate the English bundles :

...

plugin

A plugin can embed its own bundles, for example to translate the labels used in its web extensions. Bundles must be added to src/main/resources

...

with the following convention names :

  • Standard messages : org/sonar/l10n/<plugin key>_<language>.properties
  • rule Rule descriptions : src/main/resources/ org/sonar/l10n/<plugin key>_<language>/*.html

The english bundle is mandatory. For example the plugin with key "technicaldebt" must define the following files in order to enable the french bundle :

  • org/sonar/l10n/technicaldebt.properties
  • org/sonar/l10n/technicaldebt_fr.properties

How to add a language to core platform

...