Home » Archived » BIRT » how to control the language of date format (like month)
how to control the language of date format (like month) [message #688201] |
Fri, 24 June 2011 07:02 |
Missing name Mising name Messages: 81 Registered: April 2011 |
Member |
|
|
for a chart x-axis, it is datetime.
I set the format to short, date time.
when I run the report, it show as a expected, but when run in client machine, the date shown strange symbol, it seems it cannot shown the chinese character about month.
is there any method to force the output to english like
May/12/2011 1:00 pm
instead of chinese
5月/12/2011 晚上1:00
also, which setting control the display of date to chinese or english? in browser or in windows regional settings??
for e.g. MMM/dd/yy HH:mm, what setting control the display of MMM to english or chinese?
My birt designer version is 2.2.1
[Updated on: Fri, 24 June 2011 07:07] Report message to a moderator
|
|
|
Re: how to control the language of date format (like month) [message #688366 is a reply to message #688201] |
Fri, 24 June 2011 14:24 |
|
Have you seen these bugs?
https://bugs.eclipse.org/bugs/buglist.cgi?query_format=advanced;short_desc=chart%20chinese;short_desc_type=allwordssubstr;product=BIRT;classification=BIRT
You may also want to try and set in in beforeGeneration like:
function beforeGeneration(chart, icsc)
{
importPackage( Packages.org.eclipse.birt.chart.model.attribute.impl );
importPackage( Packages.org.eclipse.birt.chart.model.attribute );
//currently the chart model only supports one base axis
xAxis = chart.getBaseAxes()[0];
yAxis = chart.getOrthogonalAxes( xAxis, true)[0];
yAxisNumber2 = chart.getOrthogonalAxes( xAxis, true)[1];
if ( xAxis.getType() == AxisType.DATE_TIME_LITERAL)
{
xAxis.setFormatSpecifier( JavaDateFormatSpecifierImpl.create("MM-dd-yyyy") );
}
}
Jason
|
|
| |
Re: how to control the language of date format (like month) [message #688486 is a reply to message #688430] |
Fri, 24 June 2011 19:21 |
|
Try using this function instead:
function beforeDrawAxisLabel( axis, label, context )
{
importPackage(Packages.org.eclipse.birt.chart.model.attribute);
importPackage(Packages.java.text);
//LINEAR_LITERAL
//LOGARITHMIC_LITERAL
//TEXT_LITERAL
//DATE_TIME_LITERAL
if (axis.getType() == AxisType.DATE_TIME_LITERAL)
{
value = label.getCaption().getValue();
importPackage( Packages.java.util );
var lc = new Locale("en", "US");
var dtf2 = new SimpleDateFormat("MMM/dd/yy", lc);
//var dtf2 = new SimpleDateFormat("MM/dd", context.getExternalContext().getScriptable().getLocale());
var dt = new Date(value);
var fn1 = dtf2.format(dt);
label.getCaption().setValue(fn1);
}
}
Format it in the chart like MM/dd/yy and then let the script change it.
BTW The reason I posted the list of bugs is because several of them had directions on correcting a font path issue on your system so the error does not show up.
Jason
|
|
| |
Re: how to control the language of date format (like month) [message #689419 is a reply to message #689167] |
Mon, 27 June 2011 15:59 |
|
By default the report engine should be using the local machine locale,
but it can be set in the web.xml of the viewer or as a url parameter to
the viewer &__locale=en_US. You can also set locale in script or using
the property editor for a given report element.
If you want a test of the date localization put a data element in the
report set its type to date and enter new Date(); as the expression. In
the designer you can hard code the viewer locale using :
window->preferences->Report Design->Preview->Choose your locale.
Jason
On 6/26/2011 11:23 PM, forums-noreply@eclipse.org wrote:
> thanks for the reply, but I still want to know where to control the display format of date (chinese, english)? is it in client pc control panel?
> But I find that some report show date in chinese and some show in english, I have attached my pc control panel regional setting and one of the report which show english date caption for reference.
> for regional setting, my pc is set to show chinese date, but the report is show in english date caption...why would this happen?
>
> Thanks in advance.
|
|
| |
Re: how to control the language of date format (like month) [message #689481 is a reply to message #689450] |
Mon, 27 June 2011 17:45 |
|
No the __locale is a built in viewer parameter. If you set it to a
locale it will set it for all elements.
To set it in script put in a beforeFactory script like:
reportContext.getDesignHandle().setStringProperty("locale",
params["ReportLocale"].value);
Look at the attached example that shows how to do this.
Jason
On 6/27/2011 12:38 PM, forums-noreply@eclipse.org wrote:
> Quote:
>> as a url parameter to
>> the viewer &__locale=en_US. You can also set locale in script
>
>
> do u mean I can create a report parameter and set its name as 'locale'
> and default value = "en_US"?
> also, would you mind to tell me how to set locale in script for all
> element in a report (it is too tired if need set each element locale).
|
|
|
Re: how to control the language of date format (like month) [message #689644 is a reply to message #689481] |
Tue, 28 June 2011 04:03 |
Missing name Mising name Messages: 81 Registered: April 2011 |
Member |
|
|
My eclipse birt plugin version is
Eclipse BIRT Designer Version 2.2.1.r221_v20070924 Build <2.2.0.v20070924-1550
and so cannot run your attachment, but I copy
Quote:
reportContext.getDesignHandle().setStringProperty("locale", params["ReportLocale"].value);
in report beforeFactory method
and
Quote:
<scalar-parameter name="ReportLocale" id="23564029">
<property name="valueType">static</property>
<property name="dataType">string</property>
<property name="paramType">simple</property>
<property name="controlType">list-box</property>
<property name="mustMatch">true</property>
<property name="fixedOrder">true</property>
<property name="distinct">true</property>
<structure name="format">
<property name="category">Unformatted</property>
</structure>
<list-property name="selectionList">
<structure>
<property name="value">de_DE</property>
</structure>
<structure>
<property name="value">fr_FR</property>
</structure>
<structure>
<property name="value">zh_TW</property>
</structure>
<structure>
<property name="value">en_US</property>
</structure>
</list-property>
</scalar-parameter>
inside parameters attribute,
then when I run the report, the locale selection list come out, but whatever value I choose, the date display does not change (chinese, english, france...), why?
is the method not valid in birt version 2.2.1.r221_v20070924?
|
|
|
Re: how to control the language of date format (like month) [message #689878 is a reply to message #689644] |
Tue, 28 June 2011 14:23 |
|
In 2.2.1 you have to set it like
reportContext.getReportRunnable().designHandle.getDesignHandle().setStringProperty("locale",params["ReportLocale"]);
I believe.
Jason
On 6/28/2011 12:03 AM, forums-noreply@eclipse.org wrote:
> My eclipse birt plugin version is Eclipse BIRT Designer Version
> 2.2.1.r221_v20070924 Build <2.2.0.v20070924-1550
> and so cannot run your attachment, but I copy
> Quote:
>> reportContext.getDesignHandle().setStringProperty("locale",
>> params["ReportLocale"].value);
>
> in report beforeFactory method
> and Quote:
>> <scalar-parameter name="ReportLocale" id="23564029">
>> <property name="valueType">static</property>
>> <property name="dataType">string</property>
>> <property name="paramType">simple</property>
>> <property name="controlType">list-box</property>
>> <property name="mustMatch">true</property>
>> <property name="fixedOrder">true</property>
>> <property name="distinct">true</property>
>> <structure name="format">
>> <property name="category">Unformatted</property>
>> </structure>
>> <list-property name="selectionList">
>> <structure>
>> <property name="value">de_DE</property>
>> </structure>
>> <structure>
>> <property name="value">fr_FR</property>
>> </structure>
>> <structure>
>> <property name="value">zh_TW</property>
>> </structure>
>> <structure>
>> <property name="value">en_US</property>
>> </structure>
>> </list-property>
>> </scalar-parameter>
>
> inside parameters attribute, then when I run the report, the locale
> selection list come out, but whatever value I choose, the date display
> does not change (chinese, english, france...), why?
> is the method not valid in birt version 2.2.1.r221_v20070924?
|
|
| |
Re: how to control the language of date format (like month) [message #691043 is a reply to message #690689] |
Thu, 30 June 2011 15:09 |
|
I do not believe 2.2.1 had the locale report property.
Try this beforeFactory script:
importPackage(Packages.java.util);
var loc = new Locale("en_US");
_jsContext.setLocale(loc);
Jason
On 6/29/2011 10:40 PM, forums-noreply@eclipse.org wrote:
> in beforeFactory, I write
>
> try{
> reportContext.getReportRunnable().designHandle.getDesignHandle().setStringProperty("locale",params["ReportLocale"]);
>
> Packages.java.lang.System.out.println('params[\"ReportLocale\"] = ' +
> params["ReportLocale"]);
> }catch(ex){
> Packages.java.lang.System.out.println('Exception in beforeFactory');
> }
>
>
> and in eclipsec.exe, it show
> Quote:
>> Exception in beforeFactory
>
>
> any documentation to show how to set locale in script in birt designer
> 2.2.1?
|
|
| |
Re: how to control the language of date format (like month) [message #692030 is a reply to message #691886] |
Sun, 03 July 2011 08:17 |
Missing name Mising name Messages: 81 Registered: April 2011 |
Member |
|
|
I change something in beforeFactory and it is now like the following
Packages.java.lang.System.out.println ("--beforeFactory");
try{
importPackage(Packages.java.util);
Packages.java.lang.System.out.println("after importPackage");
Packages.java.lang.System.out.println("locale = " + reportContext.getLocale().toString());
var loc = new Locale("en_US");
_jsContext.setLocale(loc);
Packages.java.lang.System.out.println("locale = " + reportContext.getLocale().toString());
}catch(ex){
Packages.java.lang.System.out.println ("error in beforeFactory, locale");
}
the output see in eclipsec.exe prompt is
Quote:
--beforeFactory
after importPackage
locale = zh_TW
locale = en_us
this.queryText: select *
from contract_current_salary
where current_salary >= '20000'
order by current_salary;
text onCreate run
text onCreate finish
text onRender run
text onRender finish
it seems the locale is already change to en_us, but the report output is still in chinese format as attach (localeProblem2.jpg)!!
why?
My birt designer version is 2.2.1
[Updated on: Sun, 03 July 2011 08:21] Report message to a moderator
|
|
| | | | | |
Re: how to control the language of date format (like month) [message #693663 is a reply to message #693194] |
Thu, 07 July 2011 00:26 |
|
I currently do not have access to my 2.2.1 install, but the report only
contained a data item with an expression of new Date() field.
Jason
On 7/5/2011 9:57 PM, forums-noreply@eclipse.org wrote:
> could you post the rptdesign file for me?
> I think, will the database record has effect on the output?
>
> I try the method you mention in Sun, 03 July 2011 04:17 post and it
> seems the locale is already change to en_us, but the report output is
> still in chinese format as attach (localeProblem2.jpg)!!
|
|
| | | |
Goto Forum:
Current Time: Wed Sep 25 19:02:07 GMT 2024
Powered by FUDForum. Page generated in 0.05793 seconds
|