mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-05 18:34:39 +03:00
Merge pull request #3802 from ErisDS/i18n
Removing prototypal i18n code
This commit is contained in:
commit
e6bb7c4443
@ -1,7 +1,6 @@
|
||||
var downsize = require('downsize'),
|
||||
hbs = require('express-hbs'),
|
||||
moment = require('moment'),
|
||||
polyglot = require('node-polyglot').instance,
|
||||
_ = require('lodash'),
|
||||
when = require('when'),
|
||||
|
||||
@ -569,32 +568,6 @@ coreHelpers.meta_description = function (options) {
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Localised string helpers
|
||||
*
|
||||
* @param {String} key
|
||||
* @param {String} default translation
|
||||
* @param {Object} options
|
||||
* @return {String} A correctly internationalised string
|
||||
*/
|
||||
coreHelpers.e = function (key, defaultString, options) {
|
||||
var output;
|
||||
return when.all([
|
||||
api.settings.read('defaultLang'),
|
||||
api.settings.read('forceI18n')
|
||||
]).then(function (values) {
|
||||
if (values[0].settings[0] === 'en_US' &&
|
||||
_.isEmpty(options.hash) &&
|
||||
values[1].settings[0] !== 'true') {
|
||||
output = defaultString;
|
||||
} else {
|
||||
output = polyglot.t(key, options.hash);
|
||||
}
|
||||
|
||||
return output;
|
||||
});
|
||||
};
|
||||
|
||||
coreHelpers.foreach = function (context, options) {
|
||||
var fn = options.fn,
|
||||
inverse = options.inverse,
|
||||
|
@ -1,25 +0,0 @@
|
||||
{
|
||||
"__SECTION__": "admin core",
|
||||
"admin.navbar.blog": "Blog",
|
||||
"admin.navbar.settings": "Settings",
|
||||
|
||||
"__SECTION__": "icons",
|
||||
"icon.tag.label": "Tag",
|
||||
"icon.faq.label": "?",
|
||||
"icon.faq.markdown.title": "What is Markdown?",
|
||||
"icon.full_screen.label": "Full Screen",
|
||||
"icon.full_screen.title": "Enter full screen mode",
|
||||
"icon.settings.label": "Settings",
|
||||
|
||||
"__SECTION__": "editor",
|
||||
"editor.entry_title.placeholder": "Your Post Title",
|
||||
"editor.entry_permalink.label": "Permalink:",
|
||||
"editor.entry_permalink.example_url": "http://yoursite.com/",
|
||||
"editor.entry_permalink.example_slug": "the-post-title-goes-here",
|
||||
"editor.headers.markdown.label": "Markdown",
|
||||
"editor.headers.preview.label": "Preview",
|
||||
"editor.word_count": "%{count} words",
|
||||
"editor.actions.save_draft": "Save Draft",
|
||||
"editor.actions.publish": "Publish"
|
||||
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
var fs = require('fs'),
|
||||
config = require('../../server/config'),
|
||||
/**
|
||||
* Create new Polyglot object
|
||||
* @type {Polyglot}
|
||||
*/
|
||||
I18n;
|
||||
|
||||
I18n = function (ghost) {
|
||||
|
||||
// TODO: validate
|
||||
var lang = ghost.settings('defaultLang'),
|
||||
path = config.paths.lang,
|
||||
langFilePath = path + lang + '.json';
|
||||
|
||||
return function (req, res, next) {
|
||||
|
||||
if (lang === 'en_US') {
|
||||
// TODO: do stuff here to optimise for en
|
||||
|
||||
// Make jslint empty block error go away
|
||||
lang = 'en_US';
|
||||
}
|
||||
|
||||
/** TODO: potentially use req.acceptedLanguages rather than the default
|
||||
* TODO: handle loading language file for frontend on frontend request etc
|
||||
* TODO: switch this mess to be promise driven */
|
||||
fs.stat(langFilePath, function (error) {
|
||||
if (error) {
|
||||
console.log('No language file found for language ' + lang + '. Defaulting to en_US');
|
||||
lang = 'en_US';
|
||||
}
|
||||
|
||||
fs.readFile(langFilePath, function (error, data) {
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
try {
|
||||
data = JSON.parse(data);
|
||||
} catch (e) {
|
||||
throw e; // TODO: do something better with the error here
|
||||
}
|
||||
|
||||
ghost.polyglot().extend(data);
|
||||
|
||||
next();
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
module.exports.load = I18n;
|
@ -1368,43 +1368,6 @@ describe('Core Helpers', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('e helper', function () {
|
||||
|
||||
it('is loaded', function () {
|
||||
should.exist(handlebars.helpers.e);
|
||||
});
|
||||
|
||||
it('should return the correct default string', function (done) {
|
||||
apiStub.restore();
|
||||
apiStub = sandbox.stub(api.settings, 'read', function () {
|
||||
return when({ settings: ['en_US'] });
|
||||
});
|
||||
|
||||
helpers.e('testKey', 'default', { hash: {} }).then(function (result) {
|
||||
result.should.equal('default');
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
it('should return the correct string', function (done) {
|
||||
apiStub.restore();
|
||||
apiStub = sandbox.stub(api.settings, 'read', function () {
|
||||
return when({ settings: ['fr'] });
|
||||
});
|
||||
|
||||
var polyglot = new Polyglot();
|
||||
|
||||
polyglot.extend({ testKey: 'test value' });
|
||||
|
||||
helpers.__set__('polyglot', polyglot);
|
||||
|
||||
helpers.e('testKey', 'default', { hash: {} }).then(function (result) {
|
||||
result.should.equal('test value');
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
});
|
||||
|
||||
describe('foreach helper', function () {
|
||||
|
||||
// passed into the foreach helper. takes the input string along with the metadata about
|
||||
|
@ -50,7 +50,6 @@
|
||||
"lodash": "2.4.1",
|
||||
"moment": "2.4.0",
|
||||
"morgan": "1.0.0",
|
||||
"node-polyglot": "0.3.0",
|
||||
"node-uuid": "1.4.1",
|
||||
"nodemailer": "0.5.13",
|
||||
"oauth2orize": "1.0.1",
|
||||
|
Loading…
Reference in New Issue
Block a user