Package org.openstreetmap.josm.tools
Class I18n
- java.lang.Object
-
- org.openstreetmap.josm.tools.I18n
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
I18n.PluralMode
Enumeration of possible plural modes.static interface
I18n.QuirkyPluralString
This annotates strings which do not permit a clean i18n.
-
Field Summary
Fields Modifier and Type Field Description private static String
CORE_TRANS_DIRECTORY
private static String
HIRAGANA
private static String
KATAKANA
private static Pattern
LANGUAGE_NAMES
private static Map<String,I18n.PluralMode>
languages
private static String
LATIN
private static String
loadedCode
private static Locale
originalLocale
private static String
PINYIN
private static String
PLUGIN_TRANS_DIRECTORY
private static I18n.PluralMode
pluralMode
private static Map<String,String[]>
pstrings
Map (english/locale) of plural stringsprivate static String
ROMAJI
private static Map<String,String>
strings
Map (english/locale) of singular strings
-
Constructor Summary
Constructors Modifier Constructor Description private
I18n()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
addTexts(File source)
I18n initialization for plugins.static String
escape(String msg)
Escapes the special i18n characters'{}
with quotes.private static String
format(String text, Object... objects)
static Stream<Locale>
getAvailableTranslations()
Get a list of all available JOSM Translations.static Pair<String,Boolean>
getLocalizedLanguageName(String language)
Returns the localized name of the given language and optional script.static String
getLocalizedScript(String script)
Returns the localized name of the given script.static Locale
getOriginalLocale()
Returns the original default locale found when the JVM started.static Map<String,String[]>
getPluralTranslations()
Returns the map of plural translations.static Map<String,String>
getSingularTranslations()
Returns the map of singular translations.private static String
gettext(String text, String ctx)
private static String
gettext(String text, String ctx, boolean lazy)
private static String
gettextLazy(String text, String ctx)
private static String
gettextn(String text, String plural, String ctx, long num)
private static URL
getTranslationFile(String lang)
static boolean
hasCode(String code)
Determines if a language exists for the given code.static void
init()
I18n initialization.static void
initializeNumberingFormat()
Updates the default locale: overrides the numbering system, if defined in internal boundaries.xml for the current language/country.private static boolean
load(InputStream en, InputStream tr, boolean add)
private static boolean
load(String l)
static String
marktr(String text)
Marks a string for translation (such that a script can harvest the translatable strings from the source files).static String
marktrc(String context, String text)
private static int
pluralEval(long n)
static void
set(String localeName)
Sets the default locale (seeLocale.setDefault(Locale)
to the local given bylocalName
.(package private) static String
setupJavaLocaleProviders()
static String
tr(String text, Object... objects)
Translates some text for the current locale.static String
trc(String context, String text)
Translates some text in a context for the current locale.static String
trcLazy(String context, String text)
static String
trn(String singularText, String pluralText, long n, Object... objects)
Translates some text for the current locale and distinguishes betweensingularText
andpluralText
depending onn
.static String
trnc(String context, String singularText, String pluralText, long n, Object... objects)
Translates some text in a context for the current locale and distinguishes betweensingularText
andpluralText
depending onn
.
-
-
-
Field Detail
-
CORE_TRANS_DIRECTORY
private static final String CORE_TRANS_DIRECTORY
- See Also:
- Constant Field Values
-
PLUGIN_TRANS_DIRECTORY
private static final String PLUGIN_TRANS_DIRECTORY
- See Also:
- Constant Field Values
-
pluralMode
private static volatile I18n.PluralMode pluralMode
-
loadedCode
private static volatile String loadedCode
-
strings
private static volatile Map<String,String> strings
Map (english/locale) of singular strings
-
pstrings
private static volatile Map<String,String[]> pstrings
Map (english/locale) of plural strings
-
originalLocale
private static final Locale originalLocale
-
languages
private static final Map<String,I18n.PluralMode> languages
-
HIRAGANA
private static final String HIRAGANA
- See Also:
- Constant Field Values
-
KATAKANA
private static final String KATAKANA
- See Also:
- Constant Field Values
-
LATIN
private static final String LATIN
- See Also:
- Constant Field Values
-
PINYIN
private static final String PINYIN
- See Also:
- Constant Field Values
-
ROMAJI
private static final String ROMAJI
- See Also:
- Constant Field Values
-
LANGUAGE_NAMES
private static final Pattern LANGUAGE_NAMES
-
-
Constructor Detail
-
I18n
private I18n()
-
-
Method Detail
-
tr
public static String tr(String text, 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 intext
with{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 String trc(String context, 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...)
-
marktr
public static String marktr(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:
text
unmodified.
-
trn
public static String trn(String singularText, String pluralText, long n, Object... objects)
Translates some text for the current locale and distinguishes betweensingularText
andpluralText
depending 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 whethersingularText
orpluralText
is used.objects
- the parameters for the string. Mark occurrences insingularText
andpluralText
with{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 String trnc(String context, String singularText, String pluralText, long n, Object... objects)
Translates some text in a context for the current locale and distinguishes betweensingularText
andpluralText
depending 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 whethersingularText
orpluralText
is used.objects
- the parameters for the string. Mark occurrences insingularText
andpluralText
with{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...)
-
gettextLazy
private static String gettextLazy(String text, String ctx)
-
escape
public static String escape(String msg)
Escapes the special i18n characters'{}
with quotes.- Parameters:
msg
- unescaped string- Returns:
- escaped string
- Since:
- 4477
-
getTranslationFile
private static URL getTranslationFile(String lang)
-
getAvailableTranslations
public static Stream<Locale> getAvailableTranslations()
Get a list of all available JOSM Translations.- Returns:
- an array of locale objects.
-
hasCode
public static boolean hasCode(String code)
Determines if a language exists for the given code.- Parameters:
code
- The language code- Returns:
true
if a language exists,false
otherwise
-
setupJavaLocaleProviders
static String setupJavaLocaleProviders()
-
init
public static void init()
I18n initialization.
-
addTexts
public static void addTexts(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(InputStream en, InputStream tr, boolean add)
-
set
public static void set(String localeName)
Sets the default locale (seeLocale.setDefault(Locale)
to the local given bylocalName
. Ignored if localeName is null. If the locale with namelocalName
isn'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 Map<String,String> getSingularTranslations()
Returns the map of singular translations.- Returns:
- the map of singular translations.
- Since:
- 13761
-
getPluralTranslations
public static Map<String,String[]> getPluralTranslations()
Returns the map of plural translations.- Returns:
- the map of plural translations.
- Since:
- 13761
-
getOriginalLocale
public static 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 String getLocalizedScript(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<String,Boolean> getLocalizedLanguageName(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
-
-