Skip to content

Latest commit

 

History

History

locale-context

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Maven Version

Locale context module

This module allows an application to maintain a custom Locale in a context that is bound to the current thread, allowing a configured Locale to be propagated.

How to use this module

  1. Add it to your classpath.
<dependency>
    <groupId>nl.talsmasoftware.context</groupId>
    <artifactId>locale-context</artifactId>
    <version>[see Maven badge above]</version>
</dependency>
  1. Make sure to use the ContextAwareExecutorService as your threadpool.
  2. Set the current Locale for some block of code:
    private static LocaleContextManager localeContextManager = new LocaleContextManager();
    
    private void runWithLocale(Locale locale, Runnable someCode) {
        try (Context<Locale> ctx = localeContextManager.initializeNewContext(locale)) {
            someCode.run();
        }
    } 
  3. Use the LocaleContext anywhere in your application:
private void someMethod() {
    Locale locale = LocaleContextManager.getCurrentLocaleOrDefault();
}