Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Plural words, FieldContainer and MenuItem #9

Merged
merged 2 commits into from

2 participants

@miguelocarvajal

Implemented plural words with Ext.util.Inflector. You just have to specify the "p:" prefix to get the plural form of a word.

So Ux.locale.Manager.get('cat') returns "cat".

And Ux.locale.Manager.get('p:cat') returns "cats".

I also added overrides for Ext JS Ext.form.FieldContainer and Ext.menu.Item.

Let me know your comments.

Omar

@mitchellsimoens

I like the plural, nice idea!

@mitchellsimoens mitchellsimoens merged commit ea25b9c into mitchellsimoens:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 19, 2012
  1. @miguelocarvajal

    Added support for plural words, using the 'p:' prefix.

    miguelocarvajal authored Omar Carvajal committed
  2. @miguelocarvajal
This page is out of date. Refresh to see the latest.
View
15 Ux/locale/Manager.js
@@ -115,9 +115,11 @@ Ext.define('Ux.locale.Manager', {
get : function(key, defaultText) {
var me = this,
locale = me._locale,
- keys = key.split('.'),
+ plural = key.indexOf('p:') == 0,
+ keys = (plural ? key.substr(2) : key).split('.'),
k = 0,
- kNum = keys.length;
+ kNum = keys.length,
+ res;
if (!me.isLoaded()) {
return defaultText;
@@ -131,7 +133,12 @@ Ext.define('Ux.locale.Manager', {
}
}
- return locale || defaultText;
+ res = locale || defaultText;
+
+ if (plural)
+ return Ext.util.Inflector.pluralize(res);
+ else
+ return res;
},
getAvailable : function(simple) {
@@ -156,4 +163,4 @@ Ext.define('Ux.locale.Manager', {
getLanguage : function(){
return this._language;
}
-});
+});
View
38 Ux/locale/override/extjs/FieldContainer.js
@@ -0,0 +1,38 @@
+Ext.define('Ux.locale.override.extjs.FieldContainer', {
+ override : 'Ext.form.FieldContainer',
+
+ requires : [
+ 'Ux.locale.override.extjs.Component'
+ ],
+
+ setLocale : function(locale) {
+ var me = this,
+ locales = me.locales,
+ text = locales.fieldLabel,
+ manager = me.locale,
+ defaultText = '';
+
+ if (text) {
+ if (Ext.isObject(text)) {
+ defaultText = text.defaultText;
+ text = text.key;
+ }
+
+ text = manager.get(text, defaultText);
+
+ if (Ext.isString(text)) {
+ me.setFieldLabel(text);
+ }
+ }
+
+ me.callOverridden(arguments);
+ },
+
+ setFieldLabel : function(text) {
+ this.labelEl.update(text);
+
+ this.fieldLabel = text;
+
+ return this;
+ }
+});
View
30 Ux/locale/override/extjs/MenuItem.js
@@ -0,0 +1,30 @@
+Ext.define('Ux.locale.override.extjs.MenuItem', {
+ override : 'Ext.menu.Item',
+
+ requires : [
+ 'Ux.locale.override.extjs.Component'
+ ],
+
+ setLocale : function(locale) {
+ var me = this,
+ locales = me.locales,
+ text = locales.text,
+ manager = me.locale,
+ defaultText = '';
+
+ if (text) {
+ if (Ext.isObject(text)) {
+ defaultText = text.defaultText;
+ text = text.key;
+ }
+
+ text = manager.get(text, defaultText);
+
+ if (Ext.isString(text)) {
+ me.setText(text);
+ }
+ }
+
+ me.callOverridden(arguments);
+ }
+});
Something went wrong with that request. Please try again.