Setting Granite.I18n.get message | Community
Skip to main content
Level 3
July 18, 2023
Solved

Setting Granite.I18n.get message

  • July 18, 2023
  • 2 replies
  • 1760 views

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!

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 Nishant-Singh

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");

 

 

2 replies

Saravanan_Dharmaraj
Community Advisor
Community Advisor
July 18, 2023
priyak-1Author
Level 3
July 18, 2023

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.

Nishant-Singh
Adobe Employee
Nishant-SinghAdobe EmployeeAccepted solution
Adobe Employee
July 18, 2023

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");