Custom jrxml templates: pass REPORT_LOCALE and REPORT_RESOURCE_BUNDLE so $R{key} captions and number/date formats follow the user's locale

Open
#1,880 0 comments 0 reactions 1 assignee View on GitHub

@danchanka is already working on this.

Since Oct 16, 2026.

Assessment

This issue has not been assessed yet.

Description

Summary

A custom jrxml template has no way to get localized captions from the platform. The standard JasperReports mechanism for this - $R{key} text fields resolved through a resource bundle - does work today with the application's own bundle on the classpath (verified on 7.0-SNAPSHOT with resourceBundle="MyCompanyResourceBundle" on the report: $R{Opening_balance} prints «Начальный остаток» / "Opening balance" / „Saldo otwarcia”, msg($R{...}, args) works too), but the bundle is resolved by the default locale of the JVM that fills the report, not by the locale of the user, because the platform passes neither REPORT_LOCALE nor REPORT_RESOURCE_BUNDLE to JasperFillManager.fillReport. The number and date patterns of the template (#,##0.00, yyyy-MM-dd etc.) follow the JVM locale for the same reason.

So an application whose users pick their own language (Authentication.language) cannot have one localized template: today the only way is to pass every caption from the form as a value (PROPERTIES captionDebit = 'Debit', ... and $F{captionDebit} in the template), which is a lot of noise in the form and makes the template depend on the names of helper fields.

Where

api/src/main/java/lsfusion/interop/form/print/ReportGenerator.java: JasperFillManager.fillReport(report, childParams, source) - the parameters hold only the <id>_report / <id>_source / <id>_params entries of the subreports and REPORT_VIRTUALIZER.

Proposed solution

  1. When the server builds ReportGenerationData (FormReportManager), take the locale of the current user from the context, collect the $R{key} references of the report designs (a regular expression over the expression texts is enough), localize every key with the platform localizer across all bundles (DefaultLocalizer.localizeKey(key, locale), i.e. the project bundles and the platform ones alike), and put the resulting Map<String, String> and the locale into the generation data.
  2. In ReportGenerator, before filling, put JRParameter.REPORT_LOCALE = that locale and JRParameter.REPORT_RESOURCE_BUNDLE = a ListResourceBundle over that map into the parameters (for the top report and the subreports).

Then a template needs no resourceBundle attribute at all: $R{Debit} is localized exactly like a form caption '{Debit}', the desktop client does not need the application bundles (it receives the map), number and date patterns are formatted in the user's locale, and sentences with substitutions can be ordinary MessageFormat patterns in the bundle (According to the records of {0} as of {1,date,yyyy-MM-dd} the balance in favour of {2}:) used through msg().

Example

<jasperReport ... name="Invoicing_printReconciliationStatement">
  ...
  <textField><reportElement .../>
    <textFieldExpression><![CDATA[$R{Opening_balance}]]></textFieldExpression>
  </textField>
  <textField><reportElement .../>
    <textFieldExpression><![CDATA[msg($R{Balance_in_favour_of}, $F{fullName(c)}, $F{dateTo}, $F{fullName(p)})]]></textFieldExpression>
  </textField>

With the keys in MyCompanyResourceBundle[_ru|_pl].properties this prints in the language of the server today and would print in the language of the user with the change above.

Dominant language
Java
Stars
214
Forks
46
PR merge metrics
No merged PRs in 30d

Getting set up

  • Ships a Dockerfile or Docker Compose file
  • No pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from lsfusion/platform

All issues in lsfusion/platform

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.