Class I18n


  • public final class I18n
    extends java.lang.Object
    Internationalisation support.
    • 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 java.lang.String BOPOMOFO  
      private static java.lang.String CORE_TRANS_DIRECTORY  
      private static java.lang.String HANI  
      private static java.lang.String HANS  
      private static java.lang.String HANT  
      private static java.lang.String HIRAGANA  
      private static java.lang.String KATAKANA  
      private static java.util.regex.Pattern LANGUAGE_NAMES  
      private static java.util.Map<java.lang.String,​I18n.PluralMode> languages  
      private static java.lang.String LATIN  
      private static java.lang.String LATINPINYIN  
      private static java.lang.String loadedCode  
      private static java.util.Locale originalLocale  
      private static java.lang.String PINYIN  
      private static java.lang.String PLUGIN_TRANS_DIRECTORY  
      private static I18n.PluralMode pluralMode  
      private static java.util.Map<java.lang.String,​java.lang.String[]> pstrings
      Map (english/locale) of plural strings
      private static java.lang.String ROMAJI  
      private static java.util.Map<java.lang.String,​java.lang.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​(java.io.File source)
      I18n initialization for plugins.
      static java.lang.String escape​(java.lang.String msg)
      Escapes the special i18n characters '{} with quotes.
      private static java.lang.String format​(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.String getLocalizedScript​(java.lang.String script)
      Returns the localized name of the given script.
      static java.util.Locale getOriginalLocale()
      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.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 gettextLazy​(java.lang.String text, java.lang.String ctx)  
      private static java.lang.String gettextn​(java.lang.String text, java.lang.String plural, java.lang.String ctx, long num)  
      private static java.net.URL getTranslationFile​(java.lang.String lang)  
      static boolean hasCode​(java.lang.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​(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.
      (package private) static java.lang.String setupJavaLocaleProviders()  
      static java.lang.String tr​(java.lang.String text, java.lang.Object... objects)
      Translates some text for the current locale.
      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 trcLazy​(java.lang.String context, java.lang.String text)  
      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
    • Constructor Detail

      • I18n

        private I18n()
    • Method Detail

      • format

        private static java.lang.String format​(java.lang.String text,
                                               java.lang.Object... objects)
      • 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:
        text unmodified.
      • 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 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 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 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:
        true if a language exists, false otherwise
      • 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 (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.
      • 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