@ -74,12 +74,7 @@ public class NLS {
* /
* /
public static final Locale ROOT_LOCALE = new Locale ( "" , "" , "" ) ; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
public static final Locale ROOT_LOCALE = new Locale ( "" , "" , "" ) ; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
private static final InheritableThreadLocal < NLS > local = new InheritableThreadLocal < NLS > ( ) {
private static final InheritableThreadLocal < NLS > local = new InheritableThreadLocal < > ( ) ;
@Override
protected NLS initialValue ( ) {
return new NLS ( Locale . getDefault ( ) ) ;
}
} ;
/ * *
/ * *
* Sets the locale for the calling thread .
* Sets the locale for the calling thread .
@ -99,10 +94,19 @@ public class NLS {
/ * *
/ * *
* Sets the JVM default locale as the locale for the calling thread .
* Sets the JVM default locale as the locale for the calling thread .
* < p >
* < p >
* Semantically this is equivalent to < code > NLS . setLocale ( Locale . getDefault ( ) ) < / code > .
* Semantically this is equivalent to
* < code > NLS . setLocale ( Locale . getDefault ( ) ) < / code > .
* /
* /
public static void useJVMDefaultLocale ( ) {
public static void useJVMDefaultLocale ( ) {
local . set ( new NLS ( Locale . getDefault ( ) ) ) ;
useJVMDefaultInternal ( ) ;
}
// TODO(ms): change signature of public useJVMDefaultLocale() in 5.0 to get
// rid of this internal method
private static NLS useJVMDefaultInternal ( ) {
NLS b = new NLS ( Locale . getDefault ( ) ) ;
local . set ( b ) ;
return b ;
}
}
/ * *
/ * *
@ -122,7 +126,11 @@ public class NLS {
* { @link org . eclipse . jgit . errors . TranslationStringMissingException }
* { @link org . eclipse . jgit . errors . TranslationStringMissingException }
* /
* /
public static < T extends TranslationBundle > T getBundleFor ( Class < T > type ) {
public static < T extends TranslationBundle > T getBundleFor ( Class < T > type ) {
return local . get ( ) . get ( type ) ;
NLS b = local . get ( ) ;
if ( b = = null ) {
b = useJVMDefaultInternal ( ) ;
}
return b . get ( type ) ;
}
}
final private Locale locale ;
final private Locale locale ;