Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events
SOLVED

Setting Granite.I18n.get message

Avatar

Level 3

Hi All,

 

I'm trying to compare 2 number fields in content fragment through custom js. So based on that validation I'll have to display an error message. So for that I'm making use of Granite.I18n.get.

Can anyone help me in setting up the Granite.I18n.get message to a specific field in content fragment ?

 

Thanks in Advance!

1 Accepted Solution

Avatar

Correct answer by
Employee

The granite.utils client library folder provides the JavaScript API. To use the API, include this client library dependency in your custom clientlibs.

 

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
    jcr:primaryType="cq:ClientLibraryFolder"
    categories="custom.clientlibs"
    dependencies="[granite.utils]"/>

 

Localization functions use the Granite.I18n namespace.

Before you present localized strings, you need to set the locale using the Granite.I18n.setLocale function. The function requires the language code of the locale as an argument:

 

 

Granite.I18n.setLocale("fr");

 

 

To present a localized string, use the Granite.I18n.get function:

 

 

Granite.I18n.get("string to localize");

 

 

View solution in original post

3 Replies

Avatar

Level 3

Hi @Saravanan_Dharmaraj Thanks for the reference but I have already checked that post, In my case I'll have to compare 2 number fields and validate.

For the first approach:

I was able to write custom JS for the same but I'm facing issues while increasing/decreasing value through scroller(mousepad) since it is number field.

For the second approach:

I was trying to implement error message through this Granite.I18n.get(since same is being used for OOTB validations in content fragment) but I'm unable to set that error to a specific field.

 

Any help would be appreciated.

Avatar

Correct answer by
Employee

The granite.utils client library folder provides the JavaScript API. To use the API, include this client library dependency in your custom clientlibs.

 

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
    jcr:primaryType="cq:ClientLibraryFolder"
    categories="custom.clientlibs"
    dependencies="[granite.utils]"/>

 

Localization functions use the Granite.I18n namespace.

Before you present localized strings, you need to set the locale using the Granite.I18n.setLocale function. The function requires the language code of the locale as an argument:

 

 

Granite.I18n.setLocale("fr");

 

 

To present a localized string, use the Granite.I18n.get function:

 

 

Granite.I18n.get("string to localize");