Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

Approach to implement same components but with different styles specific to locale

Veenu
Level 1
Level 1

Hello Everyone,

 

I have a use case to implement same components but with different styles(UI) for 21 different locales. What should be the best approach for this. I don't want to extend components or add conditions for locale in the generic components.

@Arun_Patidar  @Veena_Vikram @Theo_Pendle @ArpitVarshney 

1 Accepted Solution
Singaiah_Chintalapudi
Correct answer by
Community Advisor
Community Advisor

There are few different ways. In general, below approaches are popular.

 

1. Use Style System: Use this approach, If you want to provide a authoring capability for authors to select the style system: https://docs.adobe.com/content/help/en/experience-manager-65/developing/components/style-system.html

 

2. Use HTML Attributes/CSS Selectors: Sometimes, we want to roll some styles globally on specific languages. This is most common use can you can use HTML attributes to define the styles specific to a language/locale.

 

Ex: 

html:lang(ja) {
 font-family: "Arial",Helvetica;
}

 
 
All the languages pages would have either the lang attribute or some other attributes to tell the search engines that the page belongs to a specific language. So, you can use that along with the CSS selectors to define the styles.
 
Thanks,
Singaiah 

View solution in original post

6 Replies
Nikhil-Kumar
Community Advisor
Community Advisor

@Veenu  Use the Style System , where you can create your custom policies and apply it to a component.
It's pretty cool!!

Thanks,
Nikhil

Singaiah_Chintalapudi
Correct answer by
Community Advisor
Community Advisor

There are few different ways. In general, below approaches are popular.

 

1. Use Style System: Use this approach, If you want to provide a authoring capability for authors to select the style system: https://docs.adobe.com/content/help/en/experience-manager-65/developing/components/style-system.html

 

2. Use HTML Attributes/CSS Selectors: Sometimes, we want to roll some styles globally on specific languages. This is most common use can you can use HTML attributes to define the styles specific to a language/locale.

 

Ex: 

html:lang(ja) {
 font-family: "Arial",Helvetica;
}

 
 
All the languages pages would have either the lang attribute or some other attributes to tell the search engines that the page belongs to a specific language. So, you can use that along with the CSS selectors to define the styles.
 
Thanks,
Singaiah 

View solution in original post

BrianKasingli
Community Advisor
Community Advisor

My 2 cents is that the style system can be used, but it may negatively impact authors the need to be very accurate with content configuration. Instead, I would change colors or icons in the code, and use the CSS selector: :lang() to tackle this situation (supported on most browsers); https://caniuse.com/#search=%3Alang

HTML:

 

<html lang="en">
...
</html>

<html lang="fr">
...
</html>

 

CSS / SCSS: 

 

// CSS 
.button:lang(en) {
  background: yellow;
}

.button:lang(fr) {
  background: red;
}

// SCSS
.button {
   &:lang(en) {
      background: yellow;
   }
   &:lang(fr) {
      background: red;
   }
}

 

 

chaudharynick
Level 1
Level 1

Hi,

 

What can you use is locale-dependent clientlibs for components/templates. For example - you have a text component and locales en-us and en-ca. Create a clientlib with name project.text.en-us and project.text.ca-us (PROJECT.COMPONENT_NAME.LOCALE) and fetch the component name and locale in HTL and create this clientlib name and call the clientlib in this way you don't have to add any manual efforts for the author and this will be generic for multiple locales and u can add more in future.

Arun_Patidar
Community Advisor
Community Advisor

you can inject a locale class in your component's wrapper div and write style for that

 

e.g. Model

Resource resource = resourceResolver.getResource(path);
if (resource != null) {
    Page targetPage = resource.adaptTo(Page.class);
    if (targetPage != null) {
        Locale pageLocale = targetPage.getLanguage(true);
        String countryLocale = "cmp_mycmp__local_"+pageLocale.getCountry();
    }
}

 

HTL

 

<div  data-sly-use.obj="com.proj.core.models.CompModel" class="Some_class more_classes ${obj.countryLocaleClass ? obj.countryLocaleClass : ''}">