Localization of GeoServer Freemarker Templates

167 views
Skip to first unread message

Michael Steigemann

unread,
Mar 5, 2022, 1:16:05 AM3/5/22
to mapstore-developers
Good morning!

I am trying to localize my output of the GeoServer FeatureInfo Freemarker Templates. In https://mapstore.readthedocs.io/en/latest/user-guide/catalog/#wms/wmtscatalog the following is written:
  • Produce a localized output for GetFeatureInfo requests (the freemarker template need to be properly configured to retrieve the locale from the request)

The page https://docs.geoserver.org/stable/en/user/tutorials/freemarker.html does not contain any hint about the locale or language. I then tried out the following: https://stackoverflow.com/questions/19765706/get-locale-in-freemarker-template#19766008 " The current locale is: ${.locale}". Unfortunately I get de_DE all the time. Is there an extra documentation or an example anywhere that could be linked? 

Thanks for your feedback and all the best,
Michael

Michael Steigemann

unread,
Mar 15, 2022, 4:58:24 PM3/15/22
to mapstore-developers
Hello!

I just wanted to ask again if anybody could give me a hint for my question above? If somebody has an example I will try it out and help improve the documentation https://docs.geoserver.org/stable/en/user/tutorials/freemarker.html .

Thanks again and all the best,
Michael

Michael Steigemann

unread,
Apr 9, 2022, 10:10:49 AM4/9/22
to mapstore-developers
Hello!
It is me once again. Today I have tried once again to get my content.ftl-Files localized dependening on the mapstore_language. The ENV Parameter is already added to my WMS-Requests:

In my content.ftl I am using the ${request.LAYERS} Parameter. This works as expected and the layer name is printed. Unfortunately i get the following error when I use  ${request.ENV.PROPERTY} (see https://docs.geoserver.org/maintain/en/user/tutorials/freemarker.html).

{"version":"1.1.1","exceptions":[{"code":"noApplicableCode","locator":"noLocator","text":"java.io.IOException: Error occurred processing content template content.ftl for mist:myposition\nError occurred processing content template content.ftl for mist:myposition\nThe following has evaluated to null or missing:\n==> request.ENV.PROPERTY [in template \"content.ftl\" at line 33, column 33]\n\n----\nTip: It's the step after the last dot that caused this error, not those before it.\n----\nTip: If the failing expression is known to legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing<\/#if>. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??\n----\n\n----\nFTL stack trace (\"~\" means nesting-related):\n\t- Failed at: ${request.ENV.PROPERTY} [in template \"content.ftl\" at line 33, column 31]\n----"}]}

Is anyone able to help me out? In the issue https://github.com/geosolutions-it/MapStore2-C028/issues/119 there are some descriptions available but unfortunately they do not cover the Freemarker templates.

Thanks for your answer and all the best,
Michael

Michael Steigemann

unread,
Apr 9, 2022, 11:29:27 AM4/9/22
to mapstore-developers
Hello again!

Last but not least I have found the solution. The description in https://docs.geoserver.org/maintain/en/user/tutorials/freemarker.html is right but a bit short ;-)
For accessing the mapstore_language in the request you have to write MAPSTORE_LANGUAGE in UPPERCASE letters: ${request.ENV. MAPSTORE_LANGUAGE }. With lowercase letters like in the request you get the error message above.

As I plan to have English (default) and German as second language I have now added the following part to my content.ftl-Files:

      <#assign mapstore_language = "en">
      <#attempt>
        <#if request.ENV.MAPSTORE_LANGUAGE == "de"  >
           <#assign mapstore_language = "de">
        </#if>
      <#recover>
      </#attempt> 


So only if the mapstore_language parameter is available in the request and equals de I use the german translations

Perhaps that hint helps someone in the future ;-)

All the best,
Michael

Lorenzo Natali

unread,
Apr 14, 2022, 9:50:34 AM4/14/22
to mapstore-developers
Good to know. 
Thank you very much for this information. For sure it will be useful
Reply all
Reply to author
Forward
0 new messages