PDA

View Full Version : Issues working with german locale



hschaefer123
20 Apr 2012, 5:33 AM
Currently i miss locoale support from Ext!

Please can you add number support to

Ext.util.Format.number


/* START ADDON UOPS */
number: function(v, format) {
if (!format) {
return v;
}
v = Ext.num(v, NaN);
if (isNaN(v)) {
return '';
}
var comma = ',',
dec = '.',
i18n = false,
neg = v < 0;

v = Math.abs(v);
if (format.substr(format.length - 2) == '/i') {
format = format.substr(0, format.length - 2);
i18n = true;
comma = '.';
dec = ',';
}

var hasComma = format.indexOf(comma) != -1,
psplit = (i18n ? format.replace(/[^\d\,]/g, '') : format.replace(/[^\d\.]/g, '')).split(dec);

if (1 < psplit.length) {
v = v.toFixed(psplit[1].length);
} else if(2 < psplit.length) {
throw ('NumberFormatException: invalid format, formats should have no more than 1 period: ' + format);
} else {
v = v.toFixed(0);
}

var fnum = v.toString();

psplit = fnum.split('.');

if (hasComma) {
var cnum = psplit[0],
parr = [],
j = cnum.length,
m = Math.floor(j / 3),
n = cnum.length % 3 || 3,
i;

for (i = 0; i < j; i += n) {
if (i != 0) {
n = 3;
}

parr[parr.length] = cnum.substr(i, n);
m -= 1;
}
fnum = parr.join(comma);
if (psplit[1]) {
fnum += dec + psplit[1];
}
} else {
if (psplit[1]) {
fnum = psplit[0] + dec + psplit[1];
}
}

return (neg ? '-' : '') + format.replace(/[\d,?\.?]+/, fnum);
}
/* END ADDON UOPS */



this would be a timesaver...

German numbers are always formatted this way 0.000.000,12
Using convert function
return Ext.util.Format.number(rec.get('turnover_total'), '0.000,00/i');
you are able to use german numbers as a workaround.

In general i hope that this will be done in future releases more generic.

Currently i am also not able to get src/local/... files working via prototyping.
It is inside srv dir but also the EN version is not working!

Any help?

mitchellsimoens
23 Apr 2012, 6:48 AM
We don't include everything that Ext JS has as we need to keep the framework small but if you need to add functionality then you are more than free to.

The locale directory I would assume to be not working looking at the code.

hschaefer123
23 Apr 2012, 7:44 AM
But what is the prefered way to use Sencha Touch in a non english environment?

Currently other languages does not seems to be supported.
The problem with additional prototyped locales is the loading order of microloader!

Beside localized labels i18n always needs localized output of Dates, Numbers, etc
supported in Ext JS but not in Touch.

I think you wrote the ux.Locale component! How are you handling different locales?
Maybe you do not have such needs or Sencha does not care the rest of the world because the US market is large enough ;-)

Cheers Holger

mitchellsimoens
23 Apr 2012, 7:45 AM
I load it via Ajax. When I have time I will add in support to load <script> elements.

TDroenner
4 Feb 2013, 8:26 AM
Any news on i18n and ST 2.1.x ?

Thorsten

wm003
30 Dec 2013, 2:06 AM
Here is a working locale for german. Indeed the deployed english locale is not working and needs some adjustments aswell (Date. -> Ext.Date.)

Anyway: Ext.picker.Picker needs to be fixed, because there are still hardcoded words ('Done', 'Cancel' here..)



Ext.override(Ext.picker.Picker,{
applyDoneButton: function(config) {
if (config) {
if (Ext.isBoolean(config)) {
config = {};
}


if (typeof config == "string") {
config = {
text: config
};
}


Ext.applyIf(config, {
ui: 'action',
align: 'right',
text: this.doneText
});
}


return Ext.factory(config, 'Ext.Button', this.getDoneButton());
},
applyCancelButton: function(config) {

if (config) {
if (Ext.isBoolean(config)) {
config = {};
}


if (typeof config == "string") {
config = {
text: config
};
}


Ext.applyIf(config, {
align: 'left',
text: this.cancelText
});
}


return Ext.factory(config, 'Ext.Button', this.getCancelButton());
}
});




Ext.Date.dayNames = [
'Sonntag',
'Montag',
'Dienstag',
'Mittwoch',
'Donnerstag',
'Freitag',
'Samstag'
];


Ext.Date.monthNames = [
'Januar',
'Februar',
'März',
'April',
'Mai',
'Juni',
'Juli',
'August',
'September',
'Oktober',
'November',
'Dezember'
];


Ext.Date.monthNumbers = {
'Jan': 0,
'Feb': 1,
'Mar': 2,
'Apr': 3,
'Mai': 4,
'Jun': 5,
'Jul': 6,
'Aug': 7,
'Sep': 8,
'Oct': 9,
'Nov': 10,
'Dez': 11
};


Ext.Date.getShortMonthName = function(month) {
return Ext.Date.monthNames[month].substring(0, 3);
};


Ext.Date.getShortDayName = function(day) {
return Ext.Date.dayNames[day].substring(0, 3);
};


Ext.Date.getMonthNumber = function(name) {
return Ext.Date.monthNumbers[name.substring(0, 1).toUpperCase() + name.substring(1, 3).toLowerCase()];
};


Ext.Date.parseCodes.S.s = '(?:st|nd|rd|th)';


if (Ext.picker.Picker){
Ext.override(Ext.picker.Picker, {
doneText: 'OK',
cancelText: 'Abbruch'
});
}


if (Ext.picker.Date) {
Ext.override(Ext.picker.Date, {
'dayText': 'Tag',
'monthText': 'Monat',
'yearText': 'Jahr',
'slotOrder': ['day', 'month', 'year']
});
}


if(Ext.IndexBar){
Ext.override(Ext.IndexBar, {
'letters': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
});
}


if(Ext.NestedList){
Ext.override(Ext.NestedList, {
'backText': 'Zurück',
'loadingText': 'Lade Daten...',
'emptyText': 'Keine Werte verfügbar.'
});
}


if(Ext.util.Format){
Ext.util.Format.defaultDateFormat = 'd/m/Y';
}


if(Ext.MessageBox){
Ext.MessageBox.OK.text = 'OK';
Ext.MessageBox.CANCEL.text = 'Abbruch';
Ext.MessageBox.YES.text = 'Ja';
Ext.MessageBox.NO.text = 'Nein';
Ext.MessageBox.OKCANCEL[0].text = 'Abbruch';
Ext.MessageBox.OKCANCEL[1].text = 'OK';
Ext.MessageBox.YESNOCANCEL[0].text = 'Abbruch';
Ext.MessageBox.YESNOCANCEL[1].text = 'Nein';
Ext.MessageBox.YESNOCANCEL[2].text = 'Ja';
Ext.MessageBox.YESNO[0].text = 'Nein';
Ext.MessageBox.YESNO[1].text = 'Ja';


}


if(Ext.ProgressIndicator) {
Ext.ProgressIndicator.prototype.config.loadingText = {
any: 'Lade Daten: {percent}%',
upload: 'Hochladen: {percent}%',
download: 'Herunterladen: {percent}%'
};
Ext.ProgressIndicator.prototype.config.fallbackText = {
any: 'Lade Daten',
upload: 'Hochladen',
download: 'Herunterladen'
};
}