Jump to content

I18N for Ireports


pnvswamy

Recommended Posts

Please tell me how to provide I18N for reports in IReport tool.

What i done is:

<jasperReport name="report3" pageWidth="595" pageHeight="842" columnWidth="535" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" resourceBundle="prop_en" whenResourceMissingType="Empty">

 

And in my text field is like this

<textField hyperlinkType="None">
    <reportElement x="277" y="0" width="100" height="20"/>
    <textElement/>
    <textFieldExpression class="java.lang.String"><![CDATA[$R{name2}]]></textFieldExpression>
   </textField>
----------------------------------------------------------------

And my prop_en.properties file is like this

name=code
name2=name


-------------------------------
Then i am getting the comiler error like:
Error filling print... Can't find bundle for base name prop_en, locale en_US
java.util.MissingResourceException: Can't find bundle for base name prop_en, locale en_US      at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1508)      at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1262)      at java.util.ResourceBundle.getBundle(ResourceBundle.java:964)      at net.sf.jasperreports.engine.util.JRResourcesUtil.loadResourceBundle(JRResourcesUtil.java:572)      at net.sf.jasperreports.engine.util.JRResourcesUtil.loadResourceBundle(JRResourcesUtil.java:510)      at net.sf.jasperreports.engine.fill.JRFillDataset.loadResourceBundle(JRFillDataset.java:527)      at net.sf.jasperreports.engine.fill.JRFillDataset.setParameterValues(JRFillDataset.java:555)      at net.sf.jasperreports.engine.fill.JRBaseFiller.setParameters(JRBaseFiller.java:1192)      at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:843)      at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:792)      at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:63)      at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:402)      at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:234)      at com.jaspersoft.ireport.designer.compiler.IReportCompiler.run(IReportCompiler.java:890)      at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:561)      at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:986) 


PLease give me help

Link to comment
Share on other sites

  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

Hi Lucian,

 

just a short question:

What is the better way for using i18n: Using the $R{SomeResourceName} or the str() function?

I just created a iReport-Plugin to transform a bunch of JRXML to the str() Function. So all static texts (or also phrases in textfieldexpressions/parameters or variables) are automatically transformed into textfields and all phrases get surrounded with str()

eg: StaticText with  "OrderNo.:"  will transformed to Textfield with expression str("OrderNo.") + ":"  

or TextField with expression "payable within " + $F{days} " after date of invoice ("+$F{paydate} + ")" will be transformed to str("payable within") + " " + $F{days} +" "+str("after date of invoice") + " ("+$F{paydate} + ")"

 

so that I can extract all phrases to our database-dictionary what is the base for my own ResourceBundle that is passed for fill process.

But I'm not sure if this is the best way, as there is the $R{} Syntax also!?!?!

Will the str() Function be included in future versions also?????

tia + regards from summer like Dresden / Germany

C-Box

Link to comment
Share on other sites

$R{} and str() are largely the same thing.  The functional difference is that $R{} can only be used with fixed/static keys, while str() can be used with dynamic message keys, e.g. str("message.prefix." + $P{message}).

So if you have static message keys you can use any of them, I can't recommend one over the other.  The fill time performance is the same, $R{} placeholders actually get translated at compile time to str() calls.

In the case you describe you might be interested in the msg() built-in method as well.  This method leverages java.text.MessageFormat functionality and is generally used when parametrized messages are in place.

For instance, you could have payable.within=payable within {0} after date of invoice ({1}) in the resource bundle, and use msg(str("payable.within"), $F{days}, $F{}) in the report.

This is generally considered a better way to localize messages than localizing message chunks.  The only problem might be to write a utility that processes text field expressions into such parametrized messages.

Regards,

Lucian

Link to comment
Share on other sites

Thx Lucian for your answer.

 

I think the str() Function is more readable within the design for "0815" Customers that want to see what they get in design mode.

If I change to msg() Function I would have just a key out of the resource bundle and not the full (human readable) text.

My "str() transformer" works pretty well so far with parsing all expression chunks and keeps the design more readable (IMHO).

The only bad thing when transforming static texts to textfields is, that there isn't a constructor for JRDesignTextField that gets an JRBaseElement (like JRDesignStaticText) for copying all the base attributes to the new textfield. So I have to use beanutils ...

 JRDesignTextField tf = new JRDesignTextField();
        BeanUtils.copyProperties(tf, staticText);

... for that purpose.

Perhaps you could add such a feature (or did I something wrong) ?

regards from again/still very sunny Germany

C-Box

Link to comment
Share on other sites

CBox
Wrote:

The only bad thing when transforming static texts to textfields is, that there isn't a constructor for JRDesignTextField that gets an JRBaseElement (like JRDesignStaticText) for copying all the base attributes to the new textfield. So I have to use beanutils ...

 JRDesignTextField tf = new JRDesignTextField();
        BeanUtils.copyProperties(tf, staticText);

... for that purpose.

Perhaps you could add such a feature (or did I something wrong) ?

Indeed, there is no built-in method for achieving this.  Please log this as a feature request so that we remember it.

Regards,

Lucian

Link to comment
Share on other sites

  • 4 years later...

Hello,

i have problem with passing the main report resource bundle ti the subreport !! in the main report the ressource work perfectly ! i made it as a subreport parameter and renamed to not bec confused with the subreport default ressource bundle .and even after that i'm still getting null as value . can someone help pls it's urgent 

Best regards

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...