AEM as Cloud | Get all language copies of a page | Community
Skip to main content
Level 5
September 4, 2023
Solved

AEM as Cloud | Get all language copies of a page

  • September 4, 2023
  • 1 reply
  • 2351 views

Hi Folks,

 

I have a page (pagea), this page exist in en, fr, and de

 

Now this page has 3 language copies

 

I need to fetch all the existing language copies of page, how would I fetch it using some API.

Please do not suggest below 

http://localhost:4502/libs/wcm/core/content/pageinfo.json?path=/content/test/en/pagea

 

Any pointers is highly appreciated. 

 

Thanks,

Pradeep

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by aanchal-sikka

Hello @pradeepdubey82 

 

Please try following API:

 

  for (final Page page : languagemanager.getLanguageRoots(res,
            currentPagePath)) {
        languagePages.put(page.getLanguage(false), page);
    }

Here getLanguageRoots() should return all Language copies of current page. The relevant language details can then be retreived via page.getLanguage()

1 reply

aanchal-sikka
Community Advisor
Community Advisor
September 4, 2023
Level 5
September 4, 2023

I could not see any method in https://github.com/adobe/aem-core-wcm-components/blob/main/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/LocalizationUtils.java

 

Which is giving list of language copies of current page. 

My requirement is, let's say I am on pagea of en, then it should return list of language copies 

/content/test/fr/pagea

/content/test/de/pagea

rkody
Level 3
March 22, 2024

Hello @pradeepdubey82 

 

Please try following API:

 

  for (final Page page : languagemanager.getLanguageRoots(res,
            currentPagePath)) {
        languagePages.put(page.getLanguage(false), page);
    }

Here getLanguageRoots() should return all Language copies of current page. The relevant language details can then be retreived via page.getLanguage()


I just implemented LanguageManager for the same use case as @pradeepdubey82

getLanguageRoots() does not get the language copies, rather it gets the language roots in your site structure based on the provided page. 

 

For the original example getLanguageRoots() on /content/test/en/pagea would return:

/content/test/fr

/content/test/de

but what is needed is:

/content/test/fr/pagea

/content/test/de/pagea

 

You could technically use this and do some string manipulation to the paths but there is a simpler solution.

 

Instead you should use getAdjacentLanguageInfo(). I was able to process the return value with this:

Map<Language, LanguageManager.Info> languagePages = (languageManager.getAdjacentLanguageInfo(Resolver, path));
for
(Map.Entry<Language, LanguageManager.Info> entry : languagePages.entrySet()) {
String path = entry.getValue().getPath();
Page localePage = pageManager.getPage(entry.getValue().getPath());
...
...
...
}