Let’s say I have a Book
that has it’s title
and description
localized in any number of languages.
Localization only matters for e.g. administrators, because users chooses their localization and they need to see only their localization, not all of them. Administrators, however, needs to have full support for localization management.
I would have two entities for this: Book
– that is localized for the user. The repository would be aware of localization, so we don’t even need to pass current localization all the time.
Then, I will have another entity: Book2
(yeah, needs a better name) that will contain a Map<Locale, String>
instead of simple string for a title
. This entity would be use in ‘admin’ context.
I also do not see a way to make both Books to be of the same type.
Would this be a good approach? Any wisdom on this?
5
I have used a complex properties for this kind of situation, with the following structure:
TranslatedValue
Value
TranslationList
Translation1
Locale
Value
Translation2
Locale
Value
Translation3
Locale
Value
...
The Value
inside TranslatedValue is filled with value for the current user’s locale.
The TranslationList
contains all of the transaltions for the locales.
This way, you can easily control which values you want to load,
and simple access both current locale and other locales:
MyBook.Title.Value // Gives the value for the current locale
MyBook.Title.Translations["french"].Value // Gives the value for the french locale
Hope that this idea helps you.
3