Of course I seen the Localization tutorial ^^
I answer to me :
To solve my problem, I create a new class TableViewChoiceCellRenderer
(see attach file) with the same model of TableViewNumberCellRenderer but
use java.text.ChoiceFormat intance of java.text.NumberFormat and in my
TableView.Column of wtkx file, I change the cellRender by my new class
TableViewChoiceCellRenderer :
<TableView.Column name="title" width="35" headerData="Titre">
<cellRenderer>
<content:TableViewChoiceCellRenderer pattern="%title"
xmlns:content="fr.pasteur.wtk.content"/>
</cellRenderer>
</TableView.Column>
and in my json localization files I define
title:"1#Mr|2#Madam|3#Miss" for English file
and
title:"1#M.|2#Mme|3#Mlle" for French file
Best regards
Duto
Le 30/07/2010 14:07, Greg Brown a écrit :
Hi,
Have you seen the Localization tutorial?
http://pivot.apache.org/tutorials/localization.html
Greg
On Jul 30, 2010, at 2:46 AM, Duto wrote:
Hello everybody,
With ResourceBundle you can create message with arguments :
title={0,choice,1#Mister|2#Madam|3#Miss} --> for English
title={0,choice,1#M.|2#Mme|3#Mlle} --> for French
Is there method to do the same think on Pivot with json or a other thinks
I need that for display a TableView where I have a column with the title of
person on numeric format.
Thanks in advance.
I am enthusiastic by Pivot, it's very a great great RIA framework!
Duto
--
View this message in context:
http://apache-pivot-users.399431.n3.nabble.com/Localization-like-ResourceBundle-with-argument-tp1008197p1008197.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.
--
Olivier Dutrieux
Études et Projets Informatiques (Tél : 31 62)
package fr.pasteur.wtk.content;
import org.apache.commons.lang.math.NumberUtils;
import org.apache.pivot.beans.BeanAdapter;
import org.apache.pivot.collections.Dictionary;
import org.apache.pivot.wtk.TableView;
import org.apache.pivot.wtk.content.TableViewCellRenderer;
import java.text.ChoiceFormat;
public class TableViewChoiceCellRenderer extends TableViewCellRenderer {
private String pattern = null;
public TableViewChoiceCellRenderer() {
}
@SuppressWarnings("unchecked")
public void render(Object row, int rowIndex, int columnIndex, TableView tableView, String columnName, boolean selected, boolean highlighted, boolean disabled) {
String formattedChoice = null;
if (this.pattern == null) {
System.err.println("pattern parameter is required for " + this.getClass().getSimpleName());
}
else {
ChoiceFormat choiceFormat = new ChoiceFormat(pattern);
if (row != null && columnName != null) {
// Get the row and cell data
Dictionary<String, Object> rowData;
if (row instanceof Dictionary<?, ?>) {
rowData = (Dictionary<String, Object>) row;
}
else {
rowData = new BeanAdapter(row);
}
Object cellData = rowData.get(columnName);
if (cellData != null) {
if (cellData instanceof Number) {
formattedChoice = choiceFormat.format(cellData);
}
else {
if (cellData instanceof String) {
try {
Number number = NumberUtils.createNumber((String) cellData);
formattedChoice = choiceFormat.format(number);
}
catch (NumberFormatException nfe) {
formattedChoice = (String) cellData;
}
}
else {
System.err.println("Data for \"" + columnName + "\" is a "
+ cellData.getClass().getName() + ", not a " + Number.class.getName() + "or a " + String.class.getName() + "representing a number.");
}
}
}
}
}
setText(formattedChoice);
}
public String getPattern() {
return pattern;
}
public void setPattern(String pattern) {
this.pattern = pattern;
}
}