Changes between Version 34 and Version 35 of DevelopersGuide/StyleGuide
- Timestamp:
- 2020-03-01T15:40:44+01:00 (5 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
DevelopersGuide/StyleGuide
v34 v35 1 1 [[TranslatedPages]] 2 2 = Development Guidelines = 3 4 [[PageOutline(2-2,Table of content,inline)]] 3 5 4 6 == How your code should look like == … … 69 71 * make sure you use {{{tr(...)}}} for all localized strings 70 72 {{{ 73 #!java 71 74 import import static org.openstreetmap.josm.tools.I18n.tr; 72 75 … … 82 85 }}} 83 86 84 85 87 * never assemble localized messages with {{{+}}}. Use format 86 88 placeholders instead. … … 89 91 {{{new JLabel(tr("My Label " + labelId));}}} 90 92 91 92 93 '''DO''' 93 94 {{{new JLabel(tr("My Label {0}",labelId));}}} 94 95 95 96 Only exception: {{{+}}} can be used to break long lines of non-variable texts. 97 The placeholders are mandatory in simple translations. 96 98 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 }}} 98 103 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 }}} 101 109 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 }}} 103 122 104 123 ---- 105 Back to [wiki:/DevelopersGuide Developers Guide] 124 Back to [wikitr:/DevelopersGuide Developers Guide]