Depending on the page, my client needed to customize the labels depending on some variable. I wanted to use the i18n mechanism provided by JSF, so it can fallback to a default label and use a custom one when available.
The difficult part was actually to set the locale, depending on a parameter. A solution would have been to extend the ViewHandler
and override the calculateLocale()
method, but it wasn't a good fit (I didn't manage to access the conversation context, also the locale depends on various values depending on the page you're on). Defining a var in child pages and setting the locale in the root f:view
worked like a charm (even though it's ugly).
<f:view locale="#{locale_variant eq null?'fr':'fr_FR_'}#{locale_variant}" />
<ui:param name="locale_variant" value="#{myBean.parameter.name()}" />
<supported-locale>fr_FR_MYVARIANT</supported-locale>