Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "BIRT/FAQ/Internationalization"

< BIRT‎ | FAQ
(Q: How can I localize strings in Javascript?)
(message parameters howto)
Line 29: Line 29:
  
 
Use <code>reportContext.getMessage("companyNameKey", reportContext.getLocale())</code>, where companyNameKey is a key from the resource bundle associated with the report. See [http://help.eclipse.org/help31/topic/org.eclipse.birt.doc/enginescript/api/org/eclipse/birt/report/engine/api/script/IReportContext.html javadoc] for more information.
 
Use <code>reportContext.getMessage("companyNameKey", reportContext.getLocale())</code>, where companyNameKey is a key from the resource bundle associated with the report. See [http://help.eclipse.org/help31/topic/org.eclipse.birt.doc/enginescript/api/org/eclipse/birt/report/engine/api/script/IReportContext.html javadoc] for more information.
 +
 +
=== Q: Can I localize messages with dynamic content? ===
 +
 +
Yes, you can. But you should use javascript, as BIRT Designer does not support this feature. Imagine that you need to localize message: "There are <VALUE-OF>orders</VALUE-OF> orders." First define the key messageOrdersKey with this content: "There are {0} orders." Then edit your report item and type following:
 +
<pre><VALUE-OF>l10nParams = new Array(1); l10nParams[0] = orders;
 +
reportContext.getMessage("messageOrdersKey", reportContext.getLocale(), l10nParams);</VALUE-OF></pre>
 +
Read Sun Java documentation for [http://java.sun.com/j2se/1.4.2/docs/api/java/text/MessageFormat.html message format details].

Revision as of 11:27, 20 December 2006

Back to BIRT FAQ Index

Internationalization

Q: Do BIRT reports support localization (L10N) and internationalization (I18N)?

Yes. Do the following:

  • Create a standard Java properties file within your report project.
  • Create properties for each resource you want to localize.
  • Set the Resources property of your report. Select the white space in the layout editor. Open the Property Editor. Switch to the General tab. Enter your property file name in the Resources field.
  • For each label, go the "Localization" tab in the Property Editor and choose the appropriate resource from the list for the Content key property.

When you run your report, BIRT will use the standard Java system for locating a property file that matches the user's locale. The resources for that file will appear in your labels. (If BIRT cannot find a resource file, or cannot find the requested key, then the default text for the label will appear. The default text is what you entered in BIRT's layout editor.)

Q: How to create translation for my language?

If your default property file is named "myreport.properties", copy it to file named "myreport_lang.properties" or "myreport_lang_country.properties", where lang and country are two letter ISO codes. For example for german translation use "myreport_de.properties", for US english use "myreport_en_US.properties". Then translate all texts behind equal signs (property file consists of couples key=text).

Q: Can different bits of a report appear in different locales?

For example, suppose BIRT is used in an ERP application. Invoices are printed in the locale of the customer. The user wants to see the invoice in the same locale as the customer. For example, if the user's locale is German, but customer's local is American, then the user would see the invoice in American format with English strings, decimal point "." instead of German "," etc.

This feature is not available in Release 1.0. It is something to consider for a future release.

Q: Can the user specify the report locale when running the report?

Reports are viewed using the BIRT web application. This application takes a __locale parameter within the URL for running a report. Simply set this parameter to the desired locale.

Q: How can I localize strings in Javascript?

Use reportContext.getMessage("companyNameKey", reportContext.getLocale()), where companyNameKey is a key from the resource bundle associated with the report. See javadoc for more information.

Q: Can I localize messages with dynamic content?

Yes, you can. But you should use javascript, as BIRT Designer does not support this feature. Imagine that you need to localize message: "There are <VALUE-OF>orders</VALUE-OF> orders." First define the key messageOrdersKey with this content: "There are {0} orders." Then edit your report item and type following:

<VALUE-OF>l10nParams = new Array(1); l10nParams[0] = orders;
reportContext.getMessage("messageOrdersKey", reportContext.getLocale(), l10nParams);</VALUE-OF>

Read Sun Java documentation for message format details.

Back to the top