Problem localising column headers on grid

7 views
Skip to first unread message

murrayh...@gmail.com

unread,
Jul 9, 2015, 6:42:00 AM7/9/15
to gl...@googlegroups.com
I have a problem localising the headers on my grid.

The abbreviated version of the grid view looks like this:
glu.defView('App.glu.UserGrid', {

name : 'UserGrid',
xtype : 'grid',
columns:[
{
header : '~~verified~~',
dataIndex : 'verified'
},
{
header : '~~firstName~~',
dataIndex: 'firstname'
},
// etc
],
// etc

}

Now, following the glu assets example my viewmodel definition includes:
glu.defModel('App.glu.UserGrid',{
UserGrid : {
mtype : 'glustore',
model : 'App.glu.models.Users',
remoteSort : true,
remoteFilter: true,
pageSize : 15,
sorters : [{property:'username'}]
},
// etc
}

The stripped down locale file looks like this:

glu.namespace('App.glu').locale = {

// Application-wide locale keys.
firstName : 'First name',

// UserGrid viewmodel keys
UserGrid : {
verified : 'Verified'
}
}

Now, the firstName key (the global one) DOES substitute in the grid column header correctly. However, the verified key (the User one) does not.

When I look at the glu source code in /adapters_extjs4/grid.js (at about line 126) I see this where the viewmodel parameter is set as the store.
col.header = glu.localize({ns:viewmodel.ns, viewmodel:config.store, key:col.header});

Then later, in glu.js localizer() function, this line sets viewSpecific to an empty object because the glustore viewmodel does not have a viewmodelName or recType property.
var viewSpecific = config.viewmodel ? (nsGlobal[config.viewmodel.viewmodelName] || nsGlobal[config.viewmodel.recType] || {}) : {};

And that is why the 'firstName' key works (since it is set in locale to be NOT viewmodel-specific (ie global)), but the 'verified' key fails because it IS viewmodel-specific.

All of that begs the question as to whether I am correctly defining the viewmodel, view and glustore for a grid setup, or is there a bug, or some other reason this is happening?

Thanks,
Murray


Ryan Smith

unread,
Jul 9, 2015, 12:39:02 PM7/9/15
to gl...@googlegroups.com
Hey Murray,

You are right, its a slightly inconsistent behavior on the grid columns.  If you are using a glustore with a model, then I believe the translation will work with the specific locale like you are looking for.  Since I haven't ever personally used either, I just declare my locale translations in the "global" namespace like you figured out and everything works great.  If it were me, I'd just move the translations up a level and call it a day :).

-Ryan

--
You received this message because you are subscribed to the Google Groups "GluJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to glujs+un...@googlegroups.com.
To post to this group, send email to gl...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/glujs/f48be365-0bd8-4a27-b94f-71a7ae0c9d34%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

murrayh...@gmail.com

unread,
Jul 10, 2015, 12:36:20 AM7/10/15
to gl...@googlegroups.com

> You are right, its a slightly inconsistent behavior on the grid columns.  If you are using a glustore with a model, then I believe the translation will work with the specific locale like you are looking for.  Since I haven't ever personally used either, I just declare my locale translations in the "global" namespace like you figured out and everything works great.  If it were me, I'd just move the translations up a level and call it a day :).

I had my glustore configured with a model all along, so maybe I needed to something else. Anyway, since my app might have many grids I did want to "namespace" the local file by viewModel names. So, I changed the code in /adapters_extjs4/grid.js as follows. This seems to fix it without breaking anything. Maybe there is a reason not to do this that I haven't hit yet!

if( glu.isArray( config.columns ) ){
for( var i = 0, len=config.columns.length; i < len; i++ ){
var col = config.columns[i];
if( col.header && col.header.indexOf(glu.conventions.localizeStart) == 0 && glu.symbol(col.header).endsWith(glu.conventions.localizeEnd)){
// v1.2.2 For store viewmodels for localisation we actually want the viewmodel that is the parent
// of the store so we have the correct viewmodelName to use in the localizer.
// Was this:
// col.header = glu.localize({ns:viewmodel.ns, viewmodel:config.store, key:col.header});
// Now this:
col.header = glu.localize({ns:viewmodel.ns, viewmodel:config.store.parentVM, key:col.header});
}
if( col.text && col.text.indexOf(glu.conventions.localizeStart) == 0 && glu.symbol(col.text).endsWith(glu.conventions.localizeEnd)){
// v1.2.2 see above
//col.text = glu.localize({ns:viewmodel.ns, viewmodel:config.store, key:col.text});
col.text = glu.localize({ns:viewmodel.ns, viewmodel:config.store.parentVM, key:col.text});
}
if( col.editor && typeof(col.editor) == 'object' && col.editor.store && typeof(col.editor.store) == 'string' && col.editor.store.indexOf(glu.conventions.bindingSymbol) == 0){
var bindings = glu.provider.binder.collectBindings(col.editor, viewmodel);
glu.provider.binder.applyBindingsList(bindings);
}
}
}

At some stage I will do a pull request on the changes I have made. :-)

Cheers,
Murray

murrayh...@gmail.com

unread,
Jul 10, 2015, 12:46:54 AM7/10/15
to gl...@googlegroups.com, murrayh...@gmail.com
PS. While I was at it I fixed this too:

// v1.2.2 Add localisation for xtype:'booleancolumn' for the trueText and falseText properties
if( col.xtype && col.xtype === 'booleancolumn' ){
if (col.trueText && col.trueText.indexOf(glu.conventions.localizeStart) == 0 && glu.symbol(col.trueText).endsWith(glu.conventions.localizeEnd)) {
col.trueText = glu.localize({ns:viewmodel.ns, viewmodel:config.store.parentVM, key:col.trueText});
}
if (col.falseText && col.falseText.indexOf(glu.conventions.localizeStart) == 0 && glu.symbol(col.falseText).endsWith(glu.conventions.localizeEnd)) {
col.falseText = glu.localize({ns:viewmodel.ns, viewmodel:config.store.parentVM, key:col.falseText});
}
}

;-)

Reply all
Reply to author
Forward
0 new messages