Posts Tagged ‘east european characters’

Multi language reports using java

Friday, November 28th, 2008

I had to develop a multi language report. The report must support four languages: English, French, German and Slovenian. I decided to use Jasper reports. First I checked out the standard jasper example (“jasperreports-2.0.2\demo\samples\i18n). I have tested the example and I was very satisfied with the solution.
After that I developed my first multi language report. Below are the steps needed to achieve this functionality:
1.Create 4 properties files and use local language. In this example I will explain how to translate the word “OFFER”

i18n.properties
text.offer_number=OFFER No.:

i18n_de_DE.properties
text.offer_number=Anbieten:

i18n_fr_FR.properties
text.offer_number=Offre:

i18n_sl_SI.properties
text.offer_number=Ponudba Št:

2.Open Ireport and add a new text field
Add $R{text.ponudba_stevilka} into the expression editor

3.In the main menu select Edit->Report Properties
Select i18n tab
Put i18n into the Resource Bundle base name field

4.Put all four i18n*.properties files into the root directory!!! This MUST BE done when you try to call the report from application. In my case I have jasper reports in C:\development\MyApp\build\classes\reporti\reports and I have to put i18n file into C:\development\MyApp\build\classes.

Translation worked after that but I spend another two hours solving the problem described below.

I have a lot of problems with cp1250 fonts. Central european fonts were not displayed when i used i18n. I put a textField on the report. In the expression editor I defined the value as: $R{text.offer_number}+”Š”.
In the resource file I have defined text.offer_number=\u006F\u008A\u006E. Total expected length should be 4 characters (3characters are in i18n file and one character is concatenated).
I expected to get oŠnŠ but i get o?nŠ  (first three characters are unicode, so the problem is, that central european characters are lost during translation.

I found the solution after long hours. In http://unicode.coeurlumiere.com/ I found out that some characters are marked as “Invalid characters”. Character Š has two unicode numbers: 008A and 0160. The first one is invalid. I got the expected result when I replaced the text.offer_number=\u006F\u0160\u006E.

Do you find this post useful? Do not hesitate to leave a reply! Go to the bottom of this page.