Foros de discusión

FreeMarker - Request local language

Mar Kus, modificado hace 6 años.

FreeMarker - Request local language

New Member Mensajes: 5 Fecha de incorporación: 14/03/16 Mensajes recientes
Does anyone know how to request the current language local the user is using like "en_US"?

I want to use this variable in a template.

Thanks in advance.

Best,
Markus
thumbnail
Nikolai Reisch, modificado hace 6 años.

RE: FreeMarker - Request local language

New Member Mensajes: 14 Fecha de incorporación: 25/02/09 Mensajes recientes
${w3c_language_id}
Mar Kus, modificado hace 6 años.

RE: FreeMarker - Request local language

New Member Mensajes: 5 Fecha de incorporación: 14/03/16 Mensajes recientes
Many thanks for your reply.

But this doesn't work for me: <a>${w3c_language_id}</a>

Do I have to assign it in a special way?
thumbnail
Nikolai Reisch, modificado hace 6 años.

RE: FreeMarker - Request local language

New Member Mensajes: 14 Fecha de incorporación: 25/02/09 Mensajes recientes
it comes from init.ftl:

<#assign language = locale.getLanguage() />
<#assign language_id = user.getLanguageId() />
<#assign w3c_language_id = localeUtil.toW3cLanguageId(theme_display.getLanguageId()) />
<#assign time_zone = user.getTimeZoneId() />
Aitor Ibañez, modificado hace 6 años.

RE: FreeMarker - Request local language

New Member Mensajes: 15 Fecha de incorporación: 5/06/17 Mensajes recientes
Hi Markus,
I have used that variable like this:

&lt;#assign langId = themeDisplay.getLanguageId() /&gt; 
&lt;#if langId == "es_ES" &gt;
		${langId}
<!--#if-->
Mar Kus, modificado hace 6 años.

RE: FreeMarker - Request local language

New Member Mensajes: 5 Fecha de incorporación: 14/03/16 Mensajes recientes
Many thanks for your replies!

Finally, that solution worked for me:
<#assign langId = request['theme-display']['language-id'] />
André Biegel, modificado hace 6 años.

RE: FreeMarker - Request local language

Junior Member Mensajes: 31 Fecha de incorporación: 11/11/13 Mensajes recientes
<#assign langId = request['theme-display']['language-id'] /> worked !
bunix nic, modificado hace 4 años.

RE: FreeMarker - Request local language

New Member Mensaje: 1 Fecha de incorporación: 28/02/20 Mensajes recientes
Special variables are variables defined by the FreeMarker engine itself. To access them, you use the .variable_name syntax.locale: Returns the current value of the locale setting. This is a string, for example en_US. For more information about locale strings see the setting directive.
So to access the current local within a Freemarker template you would use
[code]The current locale is: ${.locale}
To use it in a conditional statement as per your requirements, you would do:
[code]&lt;#if .locale == "DE"&gt;
   ...
&lt;#else&gt;
   ...
<!--#if-->
​​​​​​​[u][color=#2b4259][font="Source Sans Pro", sans-serif][size=4][b][/b][/size][/font][/color][/u]
Upsers