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
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

reading i18n from servlet

gargsahil099
Level 4
Level 4

Hi All,

We have use case where we are reading the i18n (sling:message and sling:key) from servlet. For chinese and ru-ru languages we are not able to read values properly like below

Servlet Returning Value :-

"Banner Abstract": "???????",

Actual Value :-

"Banner Abstract": "横幅摘要",

using the value map to read the JCR properties.

vm.get("sling:message", String.class);

Can someone please help on this.

1 Accepted Solution
Jörg_Hoh
Employee
Employee

can you show the code you are using? If you use a valueMap to read it (I assume that becaus of the "vm.get(...)", you basically implemented what the system can already do:

SlingHttpServletRequest request = ...

String bannerAbstractLabel = request.getResourceBundle(null).get("Banner Abstract");

(this uses the locale from the request, but you can override and ask for any locale.)

Towards your problem: For me it seems that some part of the system is not using UTF-8 (maybe your browser or the declared charset/locale in the website, maybe something else); an additional problem could be the font you use for display.

4 Replies
Jörg_Hoh
Employee
Employee

can you show the code you are using? If you use a valueMap to read it (I assume that becaus of the "vm.get(...)", you basically implemented what the system can already do:

SlingHttpServletRequest request = ...

String bannerAbstractLabel = request.getResourceBundle(null).get("Banner Abstract");

(this uses the locale from the request, but you can override and ask for any locale.)

Towards your problem: For me it seems that some part of the system is not using UTF-8 (maybe your browser or the declared charset/locale in the website, maybe something else); an additional problem could be the font you use for display.

gargsahil099
Level 4
Level 4

Hi joerg,

Is there any way that i can fetch particular locale fir eg "ar-ae" from 1 specific project for eg /apps/project/i18n.

By default in AEM it creates the dict.en_us.json file for all the dictionaries not the project specific.

Thanks

Jörg_Hoh
Employee
Employee

In that case you should proceed a bit different.

you should provide a basename to your i18n library and then use

request.getResourceBundle("my-basename",new Locale ("ar-ae")).get("Banner Abstract");

(see Apache Sling :: Internationalization Support (i18n)  for the details).