Multi-Lingual Jasper
From iDempiere en
Automatic Language Printout
- From another amazing contribution by Carlos Ruiz, a JasperReport can detect what language locale you have chosen and transpose its field labels with the translated version.
- Sample image shown here looks like its done in English. It is because the login language is English.
- Now it looks like its done in Juan Valdez expresso. It is because I relogin with Colombian.
How it works
- The magic is double advantageous:
- The use of properties files with language suffix to denote which language it will use:
- <JasperReportName>_<suffix>.properties or base language if no suffix. For example:
- PruebaOSGi_es.properties
- PruebaOSGi.properties
- <JasperReportName>_<suffix>.properties or base language if no suffix. For example:
- External properties files allow self-setup of any other translation without touching the code, script or JasperReport format.
- The use of properties files with language suffix to denote which language it will use:
- This means minimal maintenance, cleaner install, easier end user freedom and user-friendliness.
- With [1], the use of properties file is now optional.
How to setup
- First use such Expression in your JasperReport:
- $P{RESOURCE}.getString("report.title")
- You can also use simpler syntax like str("report.title"), msg("report.title") or $R{"report.title"}
- Then create properties file with such entry:
- report.title=TÌtulo CafÈ
- report.subtitle=SubtÌtulo CafÈ
- Then attach them to a Report and Process for JasperProcess.
- Subreports need a parameter to be added. Refer: Finding resources in JasperReports
- Now login your chosen language and see the difference without further work.
- Or add a parameter with the name 'AD_Language' or 'CURRENT_LANG' to the process record and choose which language do you want to see in the report.
Sample Setup
- The sample attached here will automatically do all of the above.SourceForge
- Just Pack In the whole zip as it is without opening. (Login as SystemAdmin, go to Pack In, create a record and attach the zip. Then process it.)
- Do a Role Access Update
- Now go to main menu to see a new item created by it
- Click on it and it is working!
- Of course you can open a copy just to see what or how it works as a Pack In
Errata
- Note that was a mistake in the JRXML of not using the sub-title in the 2nd expression and I corrected it easily and then attach it back to the Report and Process as the new jrxml.
- There is also an option to specify 'attachment:<..>.jrxml instead of 'attachment:<..>.jasper so you just remove the attached jasper for the system to automatically generate one-time.
TO DO
- A properties generator to populate the properties file from the AD translation tab!