Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

AEM as Cloud | Get all language copies of a page

Avatar

Level 6

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

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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()


Aanchal Sikka

View solution in original post

7 Replies

Avatar

Level 6

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/w...

 

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

Avatar

Level 6

Hi @pradeepdubey82 

Please check this java doc for LiveRelationshipManager interface which provides methods to get live copies of the given resource (in your case page resource).

https://developer.adobe.com/experience-manager/reference-materials/6-5/javadoc/com/day/cq/wcm/msm/ap...

 

 

Avatar

Correct answer by
Community Advisor

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()


Aanchal Sikka

Avatar

Level 4

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());
...
...
...
}

 

Avatar

Level 2

Hi @rkody 

In author it works however in publisher its not working. How we can achieve this from publisher. Kindly suggest me.

Map<Language, LanguageManager.Info> languagePages = languageManager.getAdjacentLanguageInfo(resolver, bluePrintPage.getPath());

 

Here languagePages getting null pointer exception.

Avatar

Level 4

Hi @upendarme1 ,

 

It's hard to say what the issue is without looking at the AEM instance. I have had some issues with null pointers because of permissions in the past so that might be a problem. Check the error logs for anything related.

 

Can you debug the publisher? If not, put some log statements on each part of your line of code and deploy.

i.e.

 

LOGGER.info("Page: {}", bluePrintPage);
LOGGER.info("Page path: {}", bluePrintPage.getPath());
LOGGER.info("Resolver: {}", resolver);
LOGGER.info("Language Manager: {}, languageManager");

 

 Then you can check to see if any of these variables are null and go from there.