Class NLS


  • public class NLS
    extends java.lang.Object
    The purpose of this class is to provide NLS (National Language Support) configurable per thread.

    The setLocale(Locale) method is used to configure locale for the calling thread. The locale setting is thread inheritable. This means that a child thread will have the same locale setting as its creator thread until it changes it explicitly.

    Example of usage:

     NLS.setLocale(Locale.GERMAN);
     TransportText t = NLS.getBundleFor(TransportText.class);
     
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.InheritableThreadLocal<NLS> local  
      private java.util.Locale locale  
      private java.util.concurrent.ConcurrentHashMap<java.lang.Class,​TranslationBundle> map  
      static java.util.Locale ROOT_LOCALE
      The root locale constant.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private NLS​(java.util.Locale locale)  
    • Field Detail

      • ROOT_LOCALE

        public static final java.util.Locale ROOT_LOCALE
        The root locale constant. It is defined here because the Locale.ROOT is not defined in Java 5
      • local

        private static final java.lang.InheritableThreadLocal<NLS> local
      • locale

        private final java.util.Locale locale
      • map

        private final java.util.concurrent.ConcurrentHashMap<java.lang.Class,​TranslationBundle> map
    • Constructor Detail

      • NLS

        private NLS​(java.util.Locale locale)
    • Method Detail

      • setLocale

        public static void setLocale​(java.util.Locale locale)
        Sets the locale for the calling thread.

        The getBundleFor(Class) method will honor this setting if it is supported by the provided resource bundle property files. Otherwise, it will use a fall back locale as described in the TranslationBundle

        Parameters:
        locale - the preferred locale
      • useJVMDefaultLocale

        public static void useJVMDefaultLocale()
        Sets the JVM default locale as the locale for the calling thread.

        Semantically this is equivalent to NLS.setLocale(Locale.getDefault()).

      • useJVMDefaultInternal

        private static NLS useJVMDefaultInternal()
      • clear

        public static void clear()
        Release resources held by NLS
        Since:
        5.8