2

I have customers from many countries, and for each one I need to generate a page with data on it.

In my report I have a similar query: SELECT Name, Address, CodLanguage ... FROM Customers

For each record of this query, I want to generate a page in Jasper Reports with customer data in their respective language (I know its language through this flag CodLanguage). I want change report language for each customer page (each record). Can i do this using report parameter locale? Or changing some variable for each record? Has anyone had a similar situation? Have any idea what can be done?

Example

I need translate the labels: Name, Address, City, Phone Number and Country in 10 different languages, according to the customer's country language. enter image description here

This example is only a simplification. I will generate between 3 and 6 report pages for each customer, with many other data.

Thanks!

diegoqueres
  • 149
  • 1
  • 13
  • 1
    `I want change report language for each customer page (each record).` - What do you want? Do you want to replace text in fields (data from DB)? Your question is unclear - you should add some image to illustrate your task/problem – Alex K Oct 13 '16 at 19:15
  • Do you have all this names in different languages in DB? – Alex K Oct 14 '16 at 19:33
  • You can read about [internationalization](http://jasperreports.sourceforge.net/sample.reference/i18n/index.html#i18n), but this help you to show only labels on different languages. – Alex K Oct 14 '16 at 19:35
  • I need to internationalize the labels. Not in report level, but to each customer record. I don't have these labels names in DB. – diegoqueres Oct 14 '16 at 20:06
  • Looks like you question more about DB design. You should edit the question to make it clear. This post maybe help you: [MySQL Database Design with Internationalization](http://stackoverflow.com/q/4596385/876298) – Alex K Oct 14 '16 at 20:08
  • i will see this link: http://jasperreports.sourceforge.net/sample.reference/i18n/index.html#i18n – diegoqueres Oct 14 '16 at 20:09
  • I see that there is the parameter REPORT LOCALE. My question is if I could use a variable (rather than REPORT_LOCALE , it seems only work on reporting level) to say that the locale is different at each customer record. – diegoqueres Oct 14 '16 at 20:11
  • This link is more about of i18n support of const values that comes not from datasource (DB) – Alex K Oct 14 '16 at 20:12
  • The *REPORT_LOCALE* is a parameter for a whole report – Alex K Oct 14 '16 at 20:13

1 Answers1

1

As far as I can tell, this is not possible using any of the standard resource references:

  • $R{resource.bundle.property}
  • msg() function
  • str() function

For each record, supply the corresponding locale (or determine it based on other data, like the country and city -- chances are Quebec, Canada would be French [fr_CA] while Toronto, Canada would be English [en_CA]).

Once there's a map of locales to locations, use a ResourceBundle (or MessageFormat?) to translate the key for a particular label.

Create a number of resource bundle files with translations for the various labels. The file names must have a suffix that corresponds to the predetermined locale (e.g., Bundle_fr_CA.properties).

Change the label from static text to an expression. The expression instantiates a new resource bundle to look up the key (e.g., "city.name") for its translated value, such as:

ResourceBundle.getBundle("Bundle", new Locale("en", $F{country})).getString("city.name")

How the "en" is determined will be a bit of a chore, unless you can alter the database to get the user's language preferences. This means you'll also have to create a resource bundle for every language/country combination, which can be automated.

Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315