Changes between Version 34 and Version 35 of DevelopersGuide/StyleGuide


Ignore:
Timestamp:
2020-03-01T15:40:44+01:00 (4 years ago)
Author:
Hb---
Comment:

trn(), trc() and translator hints to Internationalization

Legend:

Unmodified
Added
Removed
Modified
  • DevelopersGuide/StyleGuide

    v34 v35  
    11[[TranslatedPages]]
    22= Development Guidelines =
     3
     4[[PageOutline(2-2,Table of content,inline)]]
    35
    46== How your code should look like ==
     
    6971 * make sure you use {{{tr(...)}}} for all localized strings
    7072   {{{
     73   #!java
    7174   import import static org.openstreetmap.josm.tools.I18n.tr;
    7275
     
    8285   }}}
    8386
    84 
    8587 * never assemble localized messages with {{{+}}}. Use format
    8688   placeholders instead.
     
    8991   {{{new JLabel(tr("My Label " + labelId));}}}
    9092
    91 
    9293   '''DO'''
    9394   {{{new JLabel(tr("My Label {0}",labelId));}}}
    9495
    9596   Only exception: {{{+}}} can be used to break long lines of non-variable texts.
     97   The placeholders are mandatory in simple translations.
    9698
    97  * When using apostrophe, the following rules apply:
     99 * When using apostrophe in the source string, it needs to be escaped by another apostrophe (Like backslash in C):[[BR]]
     100   {{{#!java
     101   new JButton(tr("Don''t press me!"))
     102   }}}
    98103
    99    For all {{{tr}}} the apostrophe is special. (Like backslash in C)[[BR]]
    100    It needs to be escaped by another apostrophe:
     104 * A translation context can be set with trc(...). Additional hints to translators are given by java comments at the function:
     105   {{{#!java
     106   /* I18n: house number, street as parameter; place number first for visibility */
     107   msg = tr("House number {0} at {1}", s, t);
     108   }}}
    101109
    102    {{{new JButton(tr("Don''t press me more than {0} times!", n))}}}
     110 * Use {{{trn(...)}}} to let translators choose the language specific plural:
     111   {{{#!java
     112   new JButton(trn(/* I18n: times needed, some name as parameter */
     113                       "Press {1} {0} times!", n, n, someName))
     114   }}}
     115
     116 In plural segments the placeholders are not mandatory to translators.
     117
     118 The English singular source string must be given even when a its logically invalid (identification and consistency) :
     119   {{{#!java
     120   trn("Combine {0} way", "Combine {0} ways", n, n)
     121   }}}
    103122
    104123----
    105 Back to [wiki:/DevelopersGuide Developers Guide]
     124Back to [wikitr:/DevelopersGuide Developers Guide]