rodionmoiseev / c10n

A Java library, focused on making internationalisation more modular, easier to evolve and maintain, robust-to-change and IDE-friendly without excess of external tools.
Apache License 2.0
67 stars 10 forks source link

Support specifying locale at c10n interface proxy creation time #13

Closed rodionmoiseev closed 11 years ago

rodionmoiseev commented 11 years ago

Currenly one can explicitly change locale at configuration time, using C10NConfigBase#setLocale() or setLocaleProvider() methods. In order to dynamically change locale at runtime, one has to provide a custom locale provider, and make sure it provides the desired locale before invoking C10N.get(Class) method.

Even though this approach works, it is somewhat cumbersome. Also, in certain multi-user environments where user's locale cannot be statically determined from the current thread (e.g. Play 2 scala project) and has to be passed around with the request, simultaneously using multiple locales with one configuration is impossible.

Two possible solutions;

  1. Pass locale directly to C10N.get(Class) method, i.e. C10N.get(Class, Locale)
  2. Make it possible to create a light-weight clone of the current configuration with a different locale setting, i.e. implement a method C10NConfiguredModule.setLocale(Locale): C10NConfiguredModule that will create a new instance of the configured module, reusing all immutable internals, including string translations, but with the different locale setting.