Dynamic locale on a report

Options
system_migrated
edited February 11, 2022 in Analytics #1
<p>Hi,</p><p> </p><p>I'm working on a report displaying data from an Employee datasource. So it displays various data for each employee, and these data should be generated with the locale of that employee (to retrieve the static labels and for date formatting).</p><p> </p><p>So I wanted to set the locale by script, on the onRender of the row looping on each employee, but I don't find any method to set the locale by script.</p><p> </p><p>Is there a way to do that ?</p><p> </p><p>Thanks !</p>

Comments

  • <p>Thanks !</p><p>This works fine for date/number formatting (although I need to add a script on each item, which is a bit heavy :-/), but what about static labels that come from translation.properties resources ? How can I override the locale to have them appear in the right language ?</p><p> </p><p>Thanks !</p>
  • <p>Hi,</p><p> </p><p>The switch between locales happens at run time. When using the BIRT Viewer or the BIRT Viewer toolkit, you simply add the parameter __locale=<language>_<country>, as in __locale=fr_FR</p><p> </p><p>At design time, date and number fields that have been formatted will be automatically localized. For labels, you need to use .properties files to manage the translation. You will have one property file for each language you support, and each file will contain a list of key=value that you refer to in your design. You point to the base language property file by adding it to the report's Resources property. Then, for each label, you set the key value that contains the translation</p><p> </p><p>In the attached BIRT Project, I have create a simple listing report that is translated into French. You can test it in BIRT Designer by switching the locale to French (France) in Window --> Preferences --> Report Design --> Preview</p><p> </p><p>Hope this helps!</p><p> </p><p>P.</p>
    Warning No formatter is installed for the format ipb
  • <p>Yeap, I already have the properties file attached as resources and it works well having one locale at runtime for the whole report (and I can switch <em>before</em> running the report).</p><p> </p><p>But what I need is to set the Locale depending of the data - so in the same report, at runtime, I can have various locales (for instance, if I display in the same report data for 2 employees, one from France and the other one from USA, the static labels should be in French for the first one and in English for the second one).</p><p> </p><p>Is there means to do that ?</p><p> </p><p>Thanks !</p>
  • <p>I think the only way you can do this is by using the technique shown in the Devshare mentioned before.</p>
    Warning No formatter is installed for the format ipb
  • <p>The Devshare solutions works well for date/number formatting, but it does not explain how this could be done for static labels :-(</p>
  • <p>You can do something like this for labels</p><pre class="_prettyXprint">this.text = reportContext.getMessage("keyname", lc);</pre><p>where lc is a locale of type java.util.Locale. You can set it like this:</p><pre class="_prettyXprint">lc = new java.util.Locale("en","US");</pre>
  • <p>It works well, thanks ! :)</p>