Skip to content

Commit

Permalink
remove i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
shaunlee committed May 8, 2011
1 parent 50e8439 commit 46781de
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 49 deletions.
7 changes: 0 additions & 7 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ via npm:
* Unbuffered code for embed codes etc `{% code %}` or `{{ variable }}`
* Enforcing coding standard, for example `{{ variable }}` is correct, but `{{variable}}` is wrong
* Customizable filters
* Internationalization

## Example

Expand Down Expand Up @@ -57,12 +56,6 @@ via npm:
jst.addFilter('filterName', function(arg1, arg2, arg3) { return function(src) { ... }});
jst.render('{{ it.value|filterName(1, 2, 3) }}', {value: 123});

// i18n
jst.configure({
locales: {lang: 'zh_CN', locales: __dirname + '/locales'}
});
jst.render('{{ _("Hello {it.name}")|e }}', {name: '<strong>jst</strong>'});

// Client side
<script src="jst.js"></script>
<script>
Expand Down
35 changes: 2 additions & 33 deletions jst.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,37 +39,6 @@ exports.add = function(value) {

})(filters);

// i18n

var i18n = {};

;(function(exports) {

/**
* gettext('Hello {name}', {name: 'jst'})
*/
exports.gettext = function(ctx, args) {
// TODO:

for (var name in args) {
var re = RegExp('\\{' + name + '\\}', 'g');
ctx = ctx.replace(re, args[name]);
}
return ctx;
}

/**
* ngettext('There is a template', 'There are {n} templates', n)
*/
exports.ngettext = function(singular, plural, n) {
var ctx = n === 1 ? singular : plural;

// TODO:

return ctx.replace(/\{n\}/g, n);
}
})(i18n);

// compiler

var jst = {};
Expand Down Expand Up @@ -142,10 +111,10 @@ var compile = exports.compile = function(ctx) {
code += 'return out;';
//console.log(code);

var fn = new Function('it, _, _n, filters', code);
var fn = new Function('it, filters', code);

return function(args) {
return fn.call(this, args, i18n.gettext, i18n.ngettext, filters);
return fn.call(this, args, filters);
}
}

Expand Down
11 changes: 3 additions & 8 deletions lib/jst.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@
*/

var fs = require('fs'),
locales = require('locales');
filters = require('./filters'),
hash = require('./hash');

exports.version = '0.0.11';

exports.detector = locales.detector;
exports.version = '0.0.13';

var _cache = {},
_files = {},
Expand All @@ -22,8 +19,6 @@ var _cache = {},
exports.configure = function(options) {
for (var prop in options) {
_options[prop] = options[prop];
if (prop === 'locales')
locales.configure(options[prop]);
}
}

Expand Down Expand Up @@ -90,10 +85,10 @@ var compile = exports.compile = function(ctx) {
code += 'return out;';
//console.log(code);

var fn = new Function('it, _, _n, filters', code);
var fn = new Function('it, filters', code);

return function(args) {
return fn.call(this, args, locales.gettext, locales.ngettext, filters.filters);
return fn.call(this, args, filters.filters);
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "jst",
"description": "Node JavaScript Template, A pretty high performance template engine",
"version": "0.0.12",
"version": "0.0.13",
"author": "Shaun Li <shonhen@gmail.com>",
"keywords": ["template", "engine", "jst"],
"main": "./lib/jst.js",
Expand Down

0 comments on commit 46781de

Please sign in to comment.