Search code examples
aem

AEM checking lang version of a page


Hey I was hoping someone could point my to some documents or an example of checking the lang version of a page so for example if I'm on an english page and it is also in Spainsh I would like to capture the URL of the Spanish page.


Solution

  • You can get the Page's language.

    Locale getLanguage()

    Also, there is a Language Manager with several functions.

    The Spanish page should be the same but with a different language root. But if you are using aliases to also translate the URL path as well, then you should read that property.

    See:

    https://helpx.adobe.com/experience-manager/6-3/sites/developing/using/reference-materials/javadoc/com/day/cq/wcm/api/Page.html#getLanguage(boolean)

    https://helpx.adobe.com/experience-manager/6-2/sites/developing/using/reference-materials/javadoc/com/day/cq/wcm/api/LanguageManager.html#getCqLanguages(org.apache.sling.api.resource.ResourceResolver,%20java.lang.String)