Jump to content
Changes to the Jaspersoft community edition download ×

About Multi Language in Report


2004 IR Help

Recommended Posts

By: Jacky - jacky11287

About Multi Language in Report

2005-02-15 01:12

Hi, everyone, I would like to create a multi-language report.

 

I tried i18n resource bundle approach, I found very very inconvenience. Since resorce bundle can help a lot only under the same pdf encoding, or it doesn't make a great improvement. What I have tried, is to dynamically change the pdf ecnoding before generate the report, I need to predefine each fonts I will use as report fonts, and match them one by one and change to the suitable one according to the locale. But once I remember I need to change the style of the text either, than the work become terrible, I could hardly continue to write those code since I have coded a lot....>.<

 

So, can anyone suggest another more convenience method to do multi language report by JasperReport library. I took a look on Unicode approach, but sounds more or less the same as in i18n approach...

 

Looking forwards to your kindly reply...

 

Thanks you very much...

 

Jacky

 

 

 

 

By: Jacky - jacky11287

RE: About Multi Language in Report

2005-02-15 22:48

Hi, any update?

 

 

 

 

By: Teodor Danciu - teodord

RE: About Multi Language in Report

2005-02-16 09:58

 

Hi,

 

I agree that there is this shortcoming in the i18n

functionality.

The multilanguage support does not handle changing

the font properties related to the PDF export.

 

For the moment the solution is to change these

properties like you tried using the API.

I don't quite understand the problem with the style

that you mentioned. Are you using styled text also

in your reports.

 

What do you think the best solution will be in this case.

Feedback is welcomed.

 

Thank you,

Teodor

 

 

 

 

 

By: Jacky - jacky11287

RE: About Multi Language in Report

2005-02-16 23:27

Hi, Teodor

 

Glad to hear from you, about the solution, I posted here for your reference.

 

Here is the method to replace the fonts according to the locale, "jasperReport" is the object of desired report, and the "fontMap" is the fonts predefined in the program (Refer to the end of the post). Find the report font that matches the predefined font, and change the report font properties.

 

private void replaceReportFonts(JasperReport jasperReport, Map fontMap)

{

JRReportFont reportFonts[] = jasperReport.getFonts();

 

if (reportFonts == null)

throw new NullPointerException("No report Fonts");

 

for (int i = 0; i < reportFonts.length; i++)

{

JRReportFont reportFont = reportFonts;

if (fontMap.containsKey(reportFont.getName()))

{

JRFont mappedFont = (JRFont)fontMap.get(reportFont.getName());

reportFont.setFontName(mappedFont.getFontName());

reportFont.setSize(mappedFont.getSize());

reportFont.setPdfFontName(mappedFont.getPdfFontName());

reportFont.setPdfEncoding(mappedFont.getPdfEncoding());

reportFont.setBold(mappedFont.isBold());

reportFont.setItalic(mappedFont.isItalic());

reportFont.setUnderline(mappedFont.isUnderline());

reportFont.setStrikeThrough(mappedFont.isStrikeThrough());

}

}

}

 

I need to code those properites here,

 

private final String TW = "TW";

private final String TWPDFFONT = "MHei-Medium";

private final String TWPDFENCODING = "UniCNS-UCS2-H";

 

private final String CN = "CN";

private final String CNPDFFONT = "STSong-Light";

private final String CNPDFENCODING = "UniGB-UCS2-H";

 

private final String US = "US";

private final String USPDFFONT = "Helvetica";

private final String USPDFENCODING = "CP1252";

 

private final String PT = "PT";

private final String PTPDFFONT = "Helvetica";

private final String PTPDFENCODING = "CP1252";

 

And create the predefined fonts by,

 

ReportFont[] fonts =

{

new ReportFont("Heading", 20, false, false),

new ReportFont("Title", 18, true, false),

new ReportFont("Date", 12, true, true)

};

 

But you can notice from the code above, is can hardly change the style of the text, I mean "Bold" and "Italic". I need to code more for them. That's all my solution.

 

I think at that monent, I don't know whether it is the best solution or not, but at least, it can work with more coding. I think maybe the shortcoming of iText in different encoding and different styles in the pdf document both.

 

Thank you for your reply,

Jacky

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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...