Resources location with variable and set

20 views
Skip to first unread message

Felipo Antonoff

unread,
Feb 21, 2014, 10:08:45 AM2/21/14
to tot...@googlegroups.com
Hi Peter and colleagues, I would like to know if you have to use http://docs.totaljs.com/how-does-it-work/resources/  with variable and if you have to set the language.

Example:
key1: text test wih {title}

In view:
@ {resource (' key1 ', ' my title ')}

And the set something like:
@ {resource.set (' en ')}
or
controller.resource.set (' en ')
Turning now the default.

Also if it's not too much trouble, working with plural.

Peter Širka

unread,
Feb 21, 2014, 10:38:33 AM2/21/14
to tot...@googlegroups.com
Hello Felipo,
resource doesn't support set, but you can create a custom helper or component:

framework.helpers.res = function(key, value) {
   
// this === controller
   
var self = this;
   
   
// text test with {0} - {0} will be replaced with the value
   
return (self.resource(self.repository.resource || 'default', key) || '').format(value);
};

framework
.helpers.resSet = function(key) {
   
this.repository.resource = key || 'default';

   
// IMPORTANT:
   
return '';
};

Using in VIEWS or TEMPLATES:

<h1>TEST</h1>
@{resSet('en')}
<div>
    @{res('key1', 'my title')}
    @{res('key1', 'my title').pluralize('zero', 'one', 'few', 'other')}
</div>


Using in CONTROLLERS:

var self = this;
framework
.helpers.resSet.call(self, 'en');
console
.log(framework.helpers.res.call(self, 'key1', 'my title'));

I must create a helper for helpers in controllers :-)
I hope that I understand you.
Thanks.
Reply all
Reply to author
Forward
0 new messages