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.

Translation of Pages, Experience Fragment and Content Fragment

Avatar

Level 7

I am trying to translate experience fragment and content fragment via code and 3rd Party API.

 

For Page it is working: we can pick page.getLanguage() return the jcr:language of the page

For experience Fragment: How to pick language similar to page

For content Fragment: Same how to get the language.

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

2 Replies

Avatar

Level 4

Hi @Ronnie09 

To get the language for Experience Fragments and Content Fragments, you can follow a similar approach as you did for pages. You can access the language information through the JCR properties of the fragment's node.

For Experience Fragment:

import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;

// ...

Resource experienceFragmentResource = ... // Get the experience fragment resource
ResourceResolver resourceResolver = experienceFragmentResource.getResourceResolver();
String language = resourceResolver.getLanguage(experienceFragmentResource.getPath());

For Content Fragment:

import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;

// ...

Resource contentFragmentResource = ... // Get the content fragment resource
ResourceResolver resourceResolver = contentFragmentResource.getResourceResolver();
String language = resourceResolver.getLanguage(contentFragmentResource.getPath());

 

These code snippets demonstrate how to get the language for Experience Fragments and Content Fragments by using the ResourceResolver to get the language based on the resource's path.




Avatar

Administrator

@Ronnie09 Did you find the suggestion helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.

 



Kautuk Sahni