Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a multi language report?

I want to create a document, which prints in more than one language, based on the Locale.

I have created 2 resource bundles, one in English and one in Chinese, but I am not sure how to use them.

like image 538
Abcde Avatar asked Dec 14 '10 10:12

Abcde


People also ask

How do I add multi language to my website?

Google Translate is a no-cost service provided by Google. It is by far the easiest and more common way to add multiple language support to your website. To add Google Translate to your site, you simply sign up for an account and then paste a small bit of code to the HTML.


1 Answers

Here is the sample of how to implement internationalization support for JasperReports.

The main idea is to use special expression $R{} for localizing text and images.

The sample for images:

<image scaleImage="Clip"> 
    <reportElement positionType="Float" x="20" y="20" width="100" height="50"/> 
    <imageExpression class="java.lang.String"><![CDATA[$R{image.flag}]]></imageExpression> 
</image>

The samples for text (the $R{} syntax):

<textField isBlankWhenNull="true"> 
 <reportElement x="20" y="100" width="530" height="20"/> 
 <textElement/> 
 <textFieldExpression class="java.lang.String"><![CDATA[$R{sampleString}]]></textFieldExpression> 
</textField> 

or (the msg() method):

text.message=The program picked up {0} as a random number.
<textField isStretchWithOverflow="true" isBlankWhenNull="true"> 
 <reportElement x="20" y="210" width="530" height="20"/> 
 <textElement/> 
 <textFieldExpression class="java.lang.String"><![CDATA[msg($R{text.message}, $P{number})]]></textFieldExpression> 
</textField>
like image 151
Alex K Avatar answered Oct 11 '22 16:10

Alex K