Servoy, i18n, ResourceBundle and Jasper *Server*

Hello,

Currently I use resources ($R{i18n…}) for many of the labels in my Jasper report units. I typically run my reports through servoy, in which case the i18n keys work great. However, I am moving many of my report units to Jasper Server so that they can also be run outside of Servoy (not against record obj’s of course, but with direct JDBC connections to the same datasources my Servoy solution uses), however I would still like to be able to benefit from Servoy’s i18n (I don’t want to manage i18n in two places). Meaning I want my reports to render the i18n value for $R{} tags regardless of whether or not they are run through Servoy or through Jasper server. How can this be done? Do I need to export all of my Servoy i18n keys/values to a props file and make the server aware of it or is there a better way?

Thanks in advance,

Jeff

Hi Jeff,

your i18n values are pulled from a table in a DB aren’t they? In that case I don’t see any advantage of extracting them as properties, at least not that I can imagine…

If there is a way to add a secondary source to your report, or maybe to pull the values from the same dataSource if a secondary source is not possible, you should be able to do it.

Now the problem might be that you will need to parse the i18n expressions for every label. There must be a way to do this, maybe with scriptlets, and maybe in Jasper Server your habe more options (I never used it but I was under the impression you would), anyway it’s not going to be easy, I fear!

Hey Patrick!

Thanks for the reply.

I agree that there is no advantage to extracting/exporting into a static .properties file, but there may not be another way? It would be a pain to keep resources in sync, but wouldn’t be the end of the world. My i18N values don’t change much (although I do have localizations for three languages, so I have a fair amount of values). I’m not sure if I would need to parse or not b/c I would write out the pros file sans “i18n:”

Does Servoy provide an 18n export utility of any kind (apart from a manual export from the DB itself)?

BTW (Still working through your newest post on the Java Blog…what an effort!)

Also, I believe that Servoy adds the resourceBundle property to the report at runtime, when the report is executed/called from within Servoy. So with that in mind, I wonder what would happen if I statically defined my resourceBundle property in my JRXML to look at my Jasper Server properties file, then ran the report through Servoy? Would the Servoy plugin overwrite/replace the statically defined resourceBundle? Would it add a new resourceBundle property etc.? Hmmm

To have these kind of answers you will probably have to look at the sources of the jasper plugin…
I don’t remember exactly how it’s done, but maybe Rob or Andrei, or even Tom Parry will be able to tell you what to look for?

I really need to find some time to go back to that plugin, because there are some enhancements to be made, for sure!
And we are still in alpha stage for the foundset implementation, while there is still need to provide for backward compatibility with the sql use (the one you use in your case).

I would get the sources and start digging if I were you… the more, the merrier! :)

Had a look at JasperReportsI18NHandler…

1). Gets Locale from passed in locale string e.g. EN_US etc.
2). Gets Servoy application’s resourceBundle application.getResourceBundle(Locale)
3). Puts resourceBundle obj in report params map as “REPORT_RESOURCE_BUNDLE”
4). Returns new params map for report to provider

This means that when called from Servoy a report unit has the resource bundle property dynamically added to it. So what I am unclear of now is what would happen if I already had a report resource bundle property defined? Which would take precedent?

Assuming you can’t have multiple resource bundles for a given report, my feeling would be that the appendI18N method should replace any existing resource bundle it finds in the properties map. This would make the plugin play a little nicer with Jasper Server/server-based resource bundles.

This calls for a test!

I just had a look at the Jasper Report documentation and any given report unit can only support one resourceBundle. So with that in mind - and assuming that the custom java.util.ResourceBundle instance via the REPORT_RESOURCE_BUNDLE does not already overwrite any existing resourceBundle property - I think the current appendI18N method should be patched to ensure that any existing resourceBundle is replaced with the Servoy-created resource bundle (when running a report from Servoy). Yes/No??

I will do a test to see what happens when an exiting resourceBundle property is present in a report unit being run from Servoy.

From the Servoy plugin, you will not know if any resourceBundle already exists/is declared in the jrxml unless your parse the jasper source (and what happens if you use a compiled .jasper file?), so let’s just hope that the parameters Map sent to the report takes precedence (I would guess it does).