Package com.oorian.i18n
Class LanguageSwitcher
java.lang.Object
com.oorian.i18n.LanguageSwitcher
Utility for dynamically switching the user's locale at runtime.
LanguageSwitcher coordinates three actions when changing the locale:
- Updates the thread-local locale via
OorianLocale.set(Locale) - Persists the locale to the session via
SessionLocaleResolver.setLocale(Locale) - Fires a
LocaleChangeEventto notify registered listeners
Pages implementing LocaleChangeListener
can register for locale change events and re-render their content accordingly.
Usage:
// Switch to German
LanguageSwitcher.switchLocale(Locale.GERMANY);
// Switch to Arabic (triggers RTL layout update)
LanguageSwitcher.switchLocale(new Locale("ar"));
// Clear override (revert to browser Accept-Language detection)
LanguageSwitcher.clearLocale();
- Since:
- 2.1
- Version:
- 1.0
- Author:
- Marvin P. Warble Jr.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidClears the locale override and reverts to the default resolution strategy.static voidswitchLocale(Locale newLocale) Switches the current user's locale and notifies all registered listeners.
-
Method Details
-
switchLocale
Switches the current user's locale and notifies all registered listeners.This method updates the thread-local locale, persists the preference to the session, and fires a
LocaleChangeEvent. All pages implementingLocaleChangeListenerthat are registered on the current session will be notified.- Parameters:
newLocale- the locale to switch to
-
clearLocale
public static void clearLocale()Clears the locale override and reverts to the default resolution strategy.After clearing, subsequent requests will resolve the locale from the Accept-Language header or other configured resolvers. A
LocaleChangeEventis fired with the reverted locale.
-