Hello everyone, I have a page in AEM under path /content/xyz/home.html. I have a language selector in this (custom implementation). On choosing any language, I have a requirement to translate the home.html page. I do not have language masters and language copies to take the MSM feature route in AEM. I have tried updating the html document lang property but it does not work. I cannot change the jcr:language in the jcr:content of the page as there will be concurrent users changing the language. What should be the right way to implement it ? Any suggestions ?
Views
Replies
Total Likes
Hi @ayush_aem ,
Could Follow this way as:
you could create a page for English at /content/xyz/home.html and a separate page for Spanish at /content/xyz/home-es.html. When a user selects Spanish from the language selector, you can redirect them to the /content/xyz/home-es.html page.
To implement this, you can create a custom component that includes the language selector and the logic to redirect users to the appropriate page. You can also use the Sling API to programmatically create the translated pages.
for example Sling API to create a translated page as:
ResourceResolver resolver = request.getResourceResolver();
PageManager pageManager = resolver.adaptTo(PageManager.class);
// Get the parent page
Page parentPage = pageManager.getPage("/content/xyz");
// Create the translated page
PageManager.create(parentPage, "home-es", "Home (Spanish)", "en");
// Get the translated page
Page translatedPage = pageManager.getPage("/content/xyz/home-es");
// Set the content of the translated page
ModifiableValueMap properties = translatedPage.getContentResource().adaptTo(ModifiableValueMap.class);
properties.put("sling:resourceType", "your/component/type");
properties.put("title", "Home (Spanish)");
properties.put("text", "Translated content goes here");
resolver.commit();
Note: This if for an example you have to modify as your requirement.
Thanks
Hi @HrishikeshKa . Creating different pages is not an option. If it was the case I could have created language masters page structure and created live copies. I dont have any dynamic data. I just have i18n labels in the current page which needs to be translated on choosing any language.
Views
Replies
Total Likes
If I understood this correctly, then you are facing issues with your i18n labels not reflecting properly. Is that understanding correct ?
If thats the case then could you provide a little more info on how your content hierarchy looks like ?
And how are you using the i18n labels in your components ?
@ayush_aem Did you find the suggestion helpful? Please let us know if you require more information. Otherwise, please mark the answer as correct for posterity. If you've discovered a solution yourself, we would appreciate it if you could share it with the community. Thank you!
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies