Highlighted

reading i18n from servlet

Avatar

Avatar

gargsahil099

Avatar

gargsahil099

gargsahil099

03-05-2019

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.

Replies

Highlighted

Avatar

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Answer

2.3K

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Answer

2.3K
smacdonald2008

03-05-2019

Highlighted

Avatar

Avatar

Jörg_Hoh

Employee

Total Posts

3.0K

Likes

910

Correct Answer

1.0K

Avatar

Jörg_Hoh

Employee

Total Posts

3.0K

Likes

910

Correct Answer

1.0K
Jörg_Hoh
Employee

04-05-2019

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.

Highlighted

Avatar

Avatar

gargsahil099

Avatar

gargsahil099

gargsahil099

04-05-2019

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

Highlighted

Avatar

Avatar

Jörg_Hoh

Employee

Total Posts

3.0K

Likes

910

Correct Answer

1.0K

Avatar

Jörg_Hoh

Employee

Total Posts

3.0K

Likes

910

Correct Answer

1.0K
Jörg_Hoh
Employee

05-05-2019

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