Load a key from specific i18n Dictionary via sightly | Community
Skip to main content
Shashi_Mulugu
Community Advisor
Community Advisor
November 12, 2020
Solved

Load a key from specific i18n Dictionary via sightly

  • November 12, 2020
  • 4 replies
  • 3547 views

Hello Community Members,

 

A quick question, We have multi-tenant application, where we i18n dictionary for having same keys but different meanings, ex "welcome_message": "Welcome to My Site", in TenantA, where as for in TenantB, "welcome_message": "Welcome to My SiteB", So i dont have any Javabased logic and i am using simple sightly to display them.

${'welcome_message' @ i18n}

 So based on above, i am getting TenantB msg in TenantA.

 

Is there a way to load a specific dictionary values via sightly?

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 Shashi_Mulugu

Yes after doing a deep dive we can't simply do this from sightly, so I have used sling model to load a specific dictionary using sling:basename at dictionary level and using resourcebundle to load specific dictionary by passing locale and basename as params.

 

Thanks members for the insights.

4 replies

Jineet_Vora
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
November 12, 2020

Hi @shashi_mulugu,

Per Adobe documentation it is beyond the control of developer if there is more than one same key having different values. The reason is that the JSON for i18n is compiled altogether in a single file which includes all dictionaries under /apps and /libs.

So I believe there is no way to distinguish the key based on the project.

https://experienceleague.adobe.com/docs/experience-manager-65/developing/components/internationalization/i18n.html?lang=en#language-dictionaries

 

Note that you cannot predict which translation is used when strings are duplicated in dictionaries that are all located below the /apps node.

 

Image source: Adobe


 

prashantonkar
Level 4
November 12, 2020
Anudeep_Garnepudi
Community Advisor
Community Advisor
November 12, 2020

Yeah, as @jineet_vora said we cannot achieve this. Data Dictionary is just like Map, keys cannot be duplicated. If we duplicate the latest one will override the previous one. Similarly here the key which is down below the repository hierarchy will override the previous key.

/apps/project/a/i18n - KEY_ONE

/apps/project/b/i18n - KEY_ONE

KEY_ONE in b/i18n will override the KEY_ONE of a/i18n, as /project/b comes below in repo the hierarchy.

 

AG

Shashi_Mulugu
Community Advisor
Shashi_MuluguCommunity AdvisorAuthorAccepted solution
Community Advisor
November 13, 2020

Yes after doing a deep dive we can't simply do this from sightly, so I have used sling model to load a specific dictionary using sling:basename at dictionary level and using resourcebundle to load specific dictionary by passing locale and basename as params.

 

Thanks members for the insights.

Level 6
March 28, 2023

@shashi_mulugu Can you please share the sling model.