Expand my Community achievements bar.

SOLVED

reading i18n from servlet

Avatar

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

Avatar

Employee Advisor

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

Avatar

Employee Advisor

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.

Avatar

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

Avatar

Employee Advisor

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).