org.openstreetmap.josm.tools
Class I18n

java.lang.Object
  extended by org.openstreetmap.josm.tools.I18n

public class I18n
extends java.lang.Object

Internationalisation support.


Nested Class Summary
private static class I18n.PluralMode
           
 
Field Summary
private static java.lang.String[] javaInternalMessageKeys
           
private static java.util.HashMap<java.lang.String,I18n.PluralMode> languages
           
private static java.lang.String loadedCode
           
private static I18n.PluralMode pluralMode
           
private static java.util.HashMap<java.lang.String,java.lang.String[]> pstrings
           
private static java.util.HashMap<java.lang.String,java.lang.String> strings
           
 
Constructor Summary
I18n()
           
 
Method Summary
static void addTexts(java.io.File source)
           
static java.lang.String escape(java.lang.String msg)
           
static java.util.Locale[] getAvailableTranslations()
          Get a list of all available JOSM Translations.
private static java.lang.String gettext_lazy(java.lang.String text, java.lang.String ctx)
           
private static java.lang.String gettext(java.lang.String text, java.lang.String ctx)
           
private static java.lang.String gettext(java.lang.String text, java.lang.String ctx, boolean lazy)
           
private static java.lang.String gettextn(java.lang.String text, java.lang.String plural, java.lang.String ctx, long num)
           
static FeatureAdapter.TranslationAdapter getTranslationAdapter()
           
private static java.net.URL getTranslationFile(java.lang.String lang)
           
static boolean hasCode(java.lang.String code)
           
static void init()
           
private static boolean load(java.io.InputStream en, java.io.InputStream tr, boolean add)
           
private static boolean load(java.lang.String l)
           
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).
static java.lang.String marktrc(java.lang.String context, java.lang.String text)
           
private static int pluralEval(long n)
           
static void set(java.lang.String localeName)
          Sets the default locale (see Locale.setDefault(Locale) to the local given by localName.
static java.lang.String tr(java.lang.String text, java.lang.Object... objects)
          Translates some text for the current locale.
static void translateJavaInternalMessages()
          Localizations for file chooser dialog.
static java.lang.String trc_lazy(java.lang.String context, java.lang.String text)
           
static java.lang.String trc(java.lang.String context, java.lang.String text)
          Translates some text in a context for the current locale.
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 between singularText and pluralText depending on n.
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 between singularText and pluralText depending on n.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pluralMode

private static I18n.PluralMode pluralMode

loadedCode

private static java.lang.String loadedCode

javaInternalMessageKeys

private static final java.lang.String[] javaInternalMessageKeys

strings

private static java.util.HashMap<java.lang.String,java.lang.String> strings

pstrings

private static java.util.HashMap<java.lang.String,java.lang.String[]> pstrings

languages

private static java.util.HashMap<java.lang.String,I18n.PluralMode> languages
Constructor Detail

I18n

public I18n()
Method Detail

tr

public static final 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).
Use trn(java.lang.String, java.lang.String, long, java.lang.Object...) for distinguishing singular from plural text, i.e., do not use tr(size == 1 ? "singular" : "plural") nor size == 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 in text 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 final 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 for text.
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...)

trc_lazy

public static final java.lang.String trc_lazy(java.lang.String context,
                                              java.lang.String text)

marktr

public static final 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:
text unmodified.

marktrc

public static final java.lang.String marktrc(java.lang.String context,
                                             java.lang.String text)

trn

public static final 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 between singularText and pluralText depending on n.
For instance, trn("There was an error!", "There were errors!", i) or trn("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 whether singularText or pluralText is used.
objects - the parameters for the string. Mark occurrences in singularText and pluralText 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 final 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 between singularText and pluralText depending on n. There can be different translations for the same text within different contexts.

Parameters:
context - string that helps translators to find an appropriate translation for text.
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 whether singularText or pluralText is used.
objects - the parameters for the string. Mark occurrences in singularText and pluralText 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...)

gettext

private static final java.lang.String gettext(java.lang.String text,
                                              java.lang.String ctx,
                                              boolean lazy)

gettext

private static final java.lang.String gettext(java.lang.String text,
                                              java.lang.String ctx)

gettext_lazy

private static final java.lang.String gettext_lazy(java.lang.String text,
                                                   java.lang.String ctx)

gettextn

private static final 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)

getTranslationFile

private static java.net.URL getTranslationFile(java.lang.String lang)

getAvailableTranslations

public static final 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)

init

public static void init()

addTexts

public static void addTexts(java.io.File source)

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 (see Locale.setDefault(Locale) to the local given by localName. Ignored if localeName is null. If the locale with name localName isn't found the default local is set to en (english).

Parameters:
localeName - the locale name. Ignored if null.

translateJavaInternalMessages

public static void translateJavaInternalMessages()
Localizations for file chooser dialog. For some locales (e.g. de, fr) translations are provided by Java, but not for others (e.g. ru, uk).


pluralEval

private static int pluralEval(long n)

getTranslationAdapter

public static FeatureAdapter.TranslationAdapter getTranslationAdapter()


JOSM