留言板

FreeMarker - Request local language

Mar Kus,修改在6 年前。

FreeMarker - Request local language

New Member 帖子: 5 加入日期: 16-3-14 最近的帖子
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,修改在6 年前。

RE: FreeMarker - Request local language

New Member 帖子: 14 加入日期: 09-2-25 最近的帖子
${w3c_language_id}
Mar Kus,修改在6 年前。

RE: FreeMarker - Request local language

New Member 帖子: 5 加入日期: 16-3-14 最近的帖子
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,修改在6 年前。

RE: FreeMarker - Request local language

New Member 帖子: 14 加入日期: 09-2-25 最近的帖子
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,修改在6 年前。

RE: FreeMarker - Request local language

New Member 帖子: 15 加入日期: 17-6-5 最近的帖子
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,修改在6 年前。

RE: FreeMarker - Request local language

New Member 帖子: 5 加入日期: 16-3-14 最近的帖子
Many thanks for your replies!

Finally, that solution worked for me:
<#assign langId = request['theme-display']['language-id'] />
André Biegel,修改在6 年前。

RE: FreeMarker - Request local language

Junior Member 帖子: 31 加入日期: 13-11-11 最近的帖子
<#assign langId = request['theme-display']['language-id'] /> worked !
bunix nic,修改在4 年前。

RE: FreeMarker - Request local language

New Member 发布: 1 加入日期: 20-2-28 最近的帖子
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