Expand my Community achievements bar.

SOLVED

How to get website page locale code?

Avatar

Former Community Member

Hi there,

There is a difficulty case to me:  i wonder if there is a API to get locale code. E.g., when i get node "/content/geometrixx/fr/products/square",  the API could return the "fr"(french); and when i get node "/content/geometrixx/en/services/banking", the api could return the "en" (English). 

Anyone could help that? Thanks a lot.

 

Br,

Brian

1 Accepted Solution

Avatar

Correct answer by
Level 4
3 Replies

Avatar

Correct answer by
Level 4

Avatar

Former Community Member

It works, thank you so much.

But i wonder the principle that get the page locale information, and where do it find the language and counrtry of page exactly? I guess maybe one property saved that page locale information? Could you comment details? Thanks a lot.

Avatar

Employee Advisor

Hi,

The API documentation says:

Returns the content language of the page. The language is usually defined on the page content via a jcr:language property containing the iso codes for language and country. if the property is not defined on this page all ancestors are search for such an property. If no language is defined at all, the path is examined if it contains a iso label. If no language can be found at all, the systems default locale is returned. If ignoreConent is true, only the names of the path is used to determine the language. Note that this has nothing to do with i18n of the cq5 itself.

The "jcr:language" property is supposed to be on the "jcr:content" node on a page. And the methods checks if the page contains this property on its jcr:content node. If it isn't there, all ancestor pages are checked as well. And then some other assumptions kick in (like trying to interprete the parts of the paths as ISO codes).

Jörg