Package org.openstreetmap.josm.tools
Class I18n
- java.lang.Object
-
- org.openstreetmap.josm.tools.I18n
-
public final class I18n extends java.lang.Object
Internationalisation support.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classI18n.PluralModeEnumeration of possible plural modes.static interfaceI18n.QuirkyPluralStringThis annotates strings which do not permit a clean i18n.
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringBOPOMOFOprivate static java.lang.StringCORE_TRANS_DIRECTORYprivate static java.lang.StringHANIprivate static java.lang.StringHANSprivate static java.lang.StringHANTprivate static java.lang.StringHIRAGANAprivate static java.lang.StringKATAKANAprivate static java.util.regex.PatternLANGUAGE_NAMESprivate static java.util.Map<java.lang.String,I18n.PluralMode>languagesprivate static java.lang.StringLATINprivate static java.lang.StringLATINPINYINprivate static java.lang.StringloadedCodeprivate static java.util.LocaleoriginalLocaleprivate static java.lang.StringPINYINprivate static java.lang.StringPLUGIN_TRANS_DIRECTORYprivate static I18n.PluralModepluralModeprivate static java.util.Map<java.lang.String,java.lang.String[]>pstringsMap (english/locale) of plural stringsprivate static java.lang.StringROMAJIprivate static java.util.Map<java.lang.String,java.lang.String>stringsMap (english/locale) of singular strings
-
Constructor Summary
Constructors Modifier Constructor Description privateI18n()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddTexts(java.io.File source)I18n initialization for plugins.static java.lang.Stringescape(java.lang.String msg)Escapes the special i18n characters'{}with quotes.private static java.lang.Stringformat(java.lang.String text, java.lang.Object... objects)static java.util.stream.Stream<java.util.Locale>getAvailableTranslations()Get a list of all available JOSM Translations.static Pair<java.lang.String,java.lang.Boolean>getLocalizedLanguageName(java.lang.String language)Returns the localized name of the given language and optional script.static java.lang.StringgetLocalizedScript(java.lang.String script)Returns the localized name of the given script.static java.util.LocalegetOriginalLocale()Returns the original default locale found when the JVM started.static java.util.Map<java.lang.String,java.lang.String[]>getPluralTranslations()Returns the map of plural translations.static java.util.Map<java.lang.String,java.lang.String>getSingularTranslations()Returns the map of singular translations.private static java.lang.Stringgettext(java.lang.String text, java.lang.String ctx)private static java.lang.Stringgettext(java.lang.String text, java.lang.String ctx, boolean lazy)private static java.lang.StringgettextLazy(java.lang.String text, java.lang.String ctx)private static java.lang.Stringgettextn(java.lang.String text, java.lang.String plural, java.lang.String ctx, long num)private static java.net.URLgetTranslationFile(java.lang.String lang)static booleanhasCode(java.lang.String code)Determines if a language exists for the given code.static voidinit()I18n initialization.static voidinitializeNumberingFormat()Updates the default locale: overrides the numbering system, if defined in internal boundaries.xml for the current language/country.private static booleanload(java.io.InputStream en, java.io.InputStream tr, boolean add)private static booleanload(java.lang.String l)static java.lang.Stringmarktr(java.lang.String text)Marks a string for translation (such that a script can harvest the translatable strings from the source files).static java.lang.Stringmarktrc(java.lang.String context, java.lang.String text)private static intpluralEval(long n)static voidset(java.lang.String localeName)Sets the default locale (seeLocale.setDefault(Locale)to the local given bylocalName.(package private) static java.lang.StringsetupJavaLocaleProviders()static java.lang.Stringtr(java.lang.String text, java.lang.Object... objects)Translates some text for the current locale.static java.lang.Stringtrc(java.lang.String context, java.lang.String text)Translates some text in a context for the current locale.static java.lang.StringtrcLazy(java.lang.String context, java.lang.String text)static java.lang.Stringtrn(java.lang.String singularText, java.lang.String pluralText, long n, java.lang.Object... objects)Translates some text for the current locale and distinguishes betweensingularTextandpluralTextdepending onn.static java.lang.Stringtrnc(java.lang.String context, java.lang.String singularText, java.lang.String pluralText, long n, java.lang.Object... objects)Translates some text in a context for the current locale and distinguishes betweensingularTextandpluralTextdepending onn.
-
-
-
Field Detail
-
CORE_TRANS_DIRECTORY
private static final java.lang.String CORE_TRANS_DIRECTORY
- See Also:
- Constant Field Values
-
PLUGIN_TRANS_DIRECTORY
private static final java.lang.String PLUGIN_TRANS_DIRECTORY
- See Also:
- Constant Field Values
-
pluralMode
private static volatile I18n.PluralMode pluralMode
-
loadedCode
private static volatile java.lang.String loadedCode
-
strings
private static volatile java.util.Map<java.lang.String,java.lang.String> strings
Map (english/locale) of singular strings
-
pstrings
private static volatile java.util.Map<java.lang.String,java.lang.String[]> pstrings
Map (english/locale) of plural strings
-
originalLocale
private static final java.util.Locale originalLocale
-
languages
private static final java.util.Map<java.lang.String,I18n.PluralMode> languages
-
HIRAGANA
private static final java.lang.String HIRAGANA
- See Also:
- Constant Field Values
-
KATAKANA
private static final java.lang.String KATAKANA
- See Also:
- Constant Field Values
-
LATIN
private static final java.lang.String LATIN
- See Also:
- Constant Field Values
-
PINYIN
private static final java.lang.String PINYIN
- See Also:
- Constant Field Values
-
LATINPINYIN
private static final java.lang.String LATINPINYIN
- See Also:
- Constant Field Values
-
ROMAJI
private static final java.lang.String ROMAJI
- See Also:
- Constant Field Values
-
HANI
private static final java.lang.String HANI
- See Also:
- Constant Field Values
-
HANT
private static final java.lang.String HANT
- See Also:
- Constant Field Values
-
HANS
private static final java.lang.String HANS
- See Also:
- Constant Field Values
-
BOPOMOFO
private static final java.lang.String BOPOMOFO
- See Also:
- Constant Field Values
-
LANGUAGE_NAMES
private static final java.util.regex.Pattern LANGUAGE_NAMES
-
-
Constructor Detail
-
I18n
private I18n()
-
-
Method Detail
-
format
private static java.lang.String format(java.lang.String text, java.lang.Object... objects)
-
tr
public static java.lang.String tr(java.lang.String text, java.lang.Object... objects)
Translates some text for the current locale. These strings are collected by a script that runs on the source code files. After translation, the localizations are distributed with the main program.
For example,tr("JOSM''s default value is ''{0}''.", val).
Usetrn(java.lang.String, java.lang.String, long, java.lang.Object...)for distinguishing singular from plural text, i.e., do not usetr(size == 1 ? "singular" : "plural")norsize == 1 ? tr("singular") : tr("plural")- Parameters:
text- the text to translate. Must be a string literal. (No constants or local vars.) Can be broken over multiple lines. An apostrophe ' must be quoted by another apostrophe.objects- the parameters for the string. Mark occurrences intextwith{0},{1}, ...- Returns:
- the translated string.
- See Also:
trn(java.lang.String, java.lang.String, long, java.lang.Object...),trc(java.lang.String, java.lang.String),trnc(java.lang.String, java.lang.String, java.lang.String, long, java.lang.Object...)
-
trc
public static java.lang.String trc(java.lang.String context, java.lang.String text)
Translates some text in a context for the current locale. There can be different translations for the same text within different contexts.- Parameters:
context- string that helps translators to find an appropriate translation fortext.text- the text to translate.- Returns:
- the translated string.
- See Also:
tr(java.lang.String, java.lang.Object...),trn(java.lang.String, java.lang.String, long, java.lang.Object...),trnc(java.lang.String, java.lang.String, java.lang.String, long, java.lang.Object...)
-
trcLazy
public static java.lang.String trcLazy(java.lang.String context, java.lang.String text)
-
marktr
public static java.lang.String marktr(java.lang.String text)
Marks a string for translation (such that a script can harvest the translatable strings from the source files). For example,String[] options = new String[] {marktr("up"), marktr("down")}; lbl.setText(tr(options[0]));- Parameters:
text- the string to be marked for translation.- Returns:
textunmodified.
-
marktrc
public static java.lang.String marktrc(java.lang.String context, java.lang.String text)
-
trn
public static java.lang.String trn(java.lang.String singularText, java.lang.String pluralText, long n, java.lang.Object... objects)
Translates some text for the current locale and distinguishes betweensingularTextandpluralTextdepending onn.
For instance,trn("There was an error!", "There were errors!", i)ortrn("Found {0} error in {1}!", "Found {0} errors in {1}!", i, Integer.toString(i), url).- Parameters:
singularText- the singular text to translate. Must be a string literal. (No constants or local vars.) Can be broken over multiple lines. An apostrophe ' must be quoted by another apostrophe.pluralText- the plural text to translate. Must be a string literal. (No constants or local vars.) Can be broken over multiple lines. An apostrophe ' must be quoted by another apostrophe.n- a number to determine whethersingularTextorpluralTextis used.objects- the parameters for the string. Mark occurrences insingularTextandpluralTextwith{0},{1}, ...- Returns:
- the translated string.
- See Also:
tr(java.lang.String, java.lang.Object...),trc(java.lang.String, java.lang.String),trnc(java.lang.String, java.lang.String, java.lang.String, long, java.lang.Object...)
-
trnc
public static java.lang.String trnc(java.lang.String context, java.lang.String singularText, java.lang.String pluralText, long n, java.lang.Object... objects)
Translates some text in a context for the current locale and distinguishes betweensingularTextandpluralTextdepending onn. There can be different translations for the same text within different contexts.- Parameters:
context- string that helps translators to find an appropriate translation fortext.singularText- the singular text to translate. Must be a string literal. (No constants or local vars.) Can be broken over multiple lines. An apostrophe ' must be quoted by another apostrophe.pluralText- the plural text to translate. Must be a string literal. (No constants or local vars.) Can be broken over multiple lines. An apostrophe ' must be quoted by another apostrophe.n- a number to determine whethersingularTextorpluralTextis used.objects- the parameters for the string. Mark occurrences insingularTextandpluralTextwith{0},{1}, ...- Returns:
- the translated string.
- See Also:
tr(java.lang.String, java.lang.Object...),trc(java.lang.String, java.lang.String),trn(java.lang.String, java.lang.String, long, java.lang.Object...)
-
gettext
private static java.lang.String gettext(java.lang.String text, java.lang.String ctx, boolean lazy)
-
gettext
private static java.lang.String gettext(java.lang.String text, java.lang.String ctx)
-
gettextLazy
private static java.lang.String gettextLazy(java.lang.String text, java.lang.String ctx)
-
gettextn
private static java.lang.String gettextn(java.lang.String text, java.lang.String plural, java.lang.String ctx, long num)
-
escape
public static java.lang.String escape(java.lang.String msg)
Escapes the special i18n characters'{}with quotes.- Parameters:
msg- unescaped string- Returns:
- escaped string
- Since:
- 4477
-
getTranslationFile
private static java.net.URL getTranslationFile(java.lang.String lang)
-
getAvailableTranslations
public static java.util.stream.Stream<java.util.Locale> getAvailableTranslations()
Get a list of all available JOSM Translations.- Returns:
- an array of locale objects.
-
hasCode
public static boolean hasCode(java.lang.String code)
Determines if a language exists for the given code.- Parameters:
code- The language code- Returns:
trueif a language exists,falseotherwise
-
setupJavaLocaleProviders
static java.lang.String setupJavaLocaleProviders()
-
init
public static void init()
I18n initialization.
-
addTexts
public static void addTexts(java.io.File source)
I18n initialization for plugins.- Parameters:
source- file path/name of the JAR or Zip file containing translation strings- Since:
- 4159
-
load
private static boolean load(java.lang.String l)
-
load
private static boolean load(java.io.InputStream en, java.io.InputStream tr, boolean add)
-
set
public static void set(java.lang.String localeName)
Sets the default locale (seeLocale.setDefault(Locale)to the local given bylocalName. Ignored if localeName is null. If the locale with namelocalNameisn't found the default local is set toen(english).- Parameters:
localeName- the locale name. Ignored if null.
-
initializeNumberingFormat
public static void initializeNumberingFormat()
Updates the default locale: overrides the numbering system, if defined in internal boundaries.xml for the current language/country.- Since:
- 16109
-
pluralEval
private static int pluralEval(long n)
-
getSingularTranslations
public static java.util.Map<java.lang.String,java.lang.String> getSingularTranslations()
Returns the map of singular translations.- Returns:
- the map of singular translations.
- Since:
- 13761
-
getPluralTranslations
public static java.util.Map<java.lang.String,java.lang.String[]> getPluralTranslations()
Returns the map of plural translations.- Returns:
- the map of plural translations.
- Since:
- 13761
-
getOriginalLocale
public static java.util.Locale getOriginalLocale()
Returns the original default locale found when the JVM started. Used to guess real language/country of current user disregarding language chosen in JOSM preferences.- Returns:
- the original default locale found when the JVM started
- Since:
- 14013
-
getLocalizedScript
public static java.lang.String getLocalizedScript(java.lang.String script)
Returns the localized name of the given script. Only scripts used in the OSM database are known.- Parameters:
script- Writing system- Returns:
- the localized name of the given script, or null
- Since:
- 15501
-
getLocalizedLanguageName
public static Pair<java.lang.String,java.lang.Boolean> getLocalizedLanguageName(java.lang.String language)
Returns the localized name of the given language and optional script.- Parameters:
language- Language- Returns:
- the pair of localized name + known state of the given language, or null
- Since:
- 15501
-
-