Skip to content

Commit 7abcc43

Browse files
rfpekevinkucharczyk
authored andcommitted
Harvest server side strings
closes #5617 - Replace all hard-coded server-side strings with i18n translations
1 parent 52b76f2 commit 7abcc43

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+1090
-391
lines changed

core/server/api/authentication.js

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var _ = require('lodash'),
77
Promise = require('bluebird'),
88
errors = require('../errors'),
99
config = require('../config'),
10+
i18n = require('../i18n'),
1011
authentication;
1112

1213
function setupTasks(object) {
@@ -38,7 +39,7 @@ function setupTasks(object) {
3839
// Handles the additional values set by the setup screen.
3940
if (!_.isEmpty(setupUser.blogTitle)) {
4041
userSettings.push({key: 'title', value: setupUser.blogTitle});
41-
userSettings.push({key: 'description', value: 'Thoughts, stories and ideas.'});
42+
userSettings.push({key: 'description', value: i18n.t('common.api.authentication.sampleBlogDescription')});
4243
}
4344

4445
setupUser = user.toJSON(internal);
@@ -69,15 +70,15 @@ authentication = {
6970
var setup = result.setup[0].status;
7071

7172
if (!setup) {
72-
return Promise.reject(new errors.NoPermissionError('Setup must be completed before making this request.'));
73+
return Promise.reject(new errors.NoPermissionError(i18n.t('errors.api.authentication.setupMustBeCompleted')));
7374
}
7475

7576
return utils.checkObject(object, 'passwordreset');
7677
}).then(function (checkedPasswordReset) {
7778
if (checkedPasswordReset.passwordreset[0].email) {
7879
email = checkedPasswordReset.passwordreset[0].email;
7980
} else {
80-
return Promise.reject(new errors.BadRequestError('No email provided.'));
81+
return Promise.reject(new errors.BadRequestError(i18n.t('errors.api.authentication.noEmailProvided')));
8182
}
8283

8384
return settings.read({context: {internal: true}, key: 'dbHash'})
@@ -94,7 +95,7 @@ authentication = {
9495
mail: [{
9596
message: {
9697
to: email,
97-
subject: 'Reset Password',
98+
subject: i18n.t('common.api.authentication.mail.resetPassword'),
9899
html: emailContent.html,
99100
text: emailContent.text
100101
},
@@ -103,7 +104,7 @@ authentication = {
103104
};
104105
return mail.send(payload, {context: {internal: true}});
105106
}).then(function () {
106-
return Promise.resolve({passwordreset: [{message: 'Check your email for further instructions.'}]});
107+
return Promise.resolve({passwordreset: [{message: i18n.t('common.api.authentication.mail.checkEmailForInstructions')}]});
107108
}).catch(function (error) {
108109
return Promise.reject(error);
109110
});
@@ -125,7 +126,7 @@ authentication = {
125126
var setup = result.setup[0].status;
126127

127128
if (!setup) {
128-
return Promise.reject(new errors.NoPermissionError('Setup must be completed before making this request.'));
129+
return Promise.reject(new errors.NoPermissionError(i18n.t('errors.api.authentication.setupMustBeCompleted')));
129130
}
130131

131132
return utils.checkObject(object, 'passwordreset');
@@ -143,7 +144,7 @@ authentication = {
143144
dbHash: dbHash
144145
});
145146
}).then(function () {
146-
return Promise.resolve({passwordreset: [{message: 'Password changed successfully.'}]});
147+
return Promise.resolve({passwordreset: [{message: i18n.t('common.api.authentication.mail.passwordChanged')}]});
147148
}).catch(function (error) {
148149
return Promise.reject(new errors.UnauthorizedError(error.message));
149150
});
@@ -166,7 +167,7 @@ authentication = {
166167
var setup = result.setup[0].status;
167168

168169
if (!setup) {
169-
return Promise.reject(new errors.NoPermissionError('Setup must be completed before making this request.'));
170+
return Promise.reject(new errors.NoPermissionError(i18n.t('errors.api.authentication.setupMustBeCompleted')));
170171
}
171172

172173
return utils.checkObject(object, 'invitation');
@@ -189,7 +190,7 @@ authentication = {
189190
// Setting the slug to '' has the model regenerate the slug from the user's name
190191
return dataProvider.User.edit({name: name, email: email, slug: ''}, {id: user.id});
191192
}).then(function () {
192-
return Promise.resolve({invitation: [{message: 'Invitation accepted.'}]});
193+
return Promise.resolve({invitation: [{message: i18n.t('common.api.authentication.mail.invitationAccepted')}]});
193194
}).catch(function (error) {
194195
return Promise.reject(new errors.UnauthorizedError(error.message));
195196
});
@@ -207,7 +208,7 @@ authentication = {
207208
var setup = result.setup[0].status;
208209

209210
if (!setup) {
210-
return Promise.reject(new errors.NoPermissionError('Setup must be completed before making this request.'));
211+
return Promise.reject(new errors.NoPermissionError(i18n.t('errors.api.authentication.setupMustBeCompleted')));
211212
}
212213

213214
if (options.email) {
@@ -219,7 +220,7 @@ authentication = {
219220
}
220221
});
221222
} else {
222-
return Promise.reject(new errors.BadRequestError('The server did not receive a valid email'));
223+
return Promise.reject(new errors.BadRequestError(i18n.t('errors.api.authentication.invalidEmailReceived')));
223224
}
224225
});
225226
},
@@ -243,7 +244,7 @@ authentication = {
243244
var setup = result.setup[0].status;
244245

245246
if (setup) {
246-
return Promise.reject(new errors.NoPermissionError('Setup has already been completed.'));
247+
return Promise.reject(new errors.NoPermissionError(i18n.t('errors.api.authentication.setupAlreadyCompleted')));
247248
}
248249

249250
return setupTasks(object);
@@ -258,7 +259,7 @@ authentication = {
258259
}).then(function (emailContent) {
259260
var message = {
260261
to: setupUser.email,
261-
subject: 'Your New Ghost Blog',
262+
subject: i18n.t('common.api.authentication.mail.yourNewGhostBlog'),
262263
html: emailContent.html,
263264
text: emailContent.text
264265
},
@@ -272,8 +273,8 @@ authentication = {
272273
mail.send(payload, {context: {internal: true}}).catch(function (error) {
273274
errors.logError(
274275
error.message,
275-
'Unable to send welcome email, your blog will continue to function.',
276-
'Please see http://support.ghost.org/mail/ for instructions on configuring email.'
276+
i18n.t('errors.api.authentication.unableToSendWelcomeEmail', {url: 'http://support.ghost.org/mail/'}),
277+
i18n.t('errors.api.authentication.checkEmailConfigInstructions')
277278
);
278279
});
279280
}).then(function () {
@@ -283,14 +284,14 @@ authentication = {
283284

284285
updateSetup: function updateSetup(object, options) {
285286
if (!options.context || !options.context.user) {
286-
return Promise.reject(new errors.NoPermissionError('You are not logged in.'));
287+
return Promise.reject(new errors.NoPermissionError(i18n.t('errors.api.authentication.notLoggedIn')));
287288
}
288289

289290
return dataProvider.User.findOne({role: 'Owner', status: 'all'}).then(function (result) {
290291
var user = result.toJSON();
291292

292293
if (user.id !== options.context.user) {
293-
return Promise.reject(new errors.NoPermissionError('You are not the blog owner.'));
294+
return Promise.reject(new errors.NoPermissionError(i18n.t('errors.api.authentication.notTheBlogOwner')));
294295
}
295296

296297
return setupTasks(object);
@@ -307,14 +308,14 @@ authentication = {
307308
} else if (object.token_type_hint && object.token_type_hint === 'refresh_token') {
308309
token = dataProvider.Refreshtoken;
309310
} else {
310-
return errors.BadRequestError('Invalid token_type_hint given.');
311+
return errors.BadRequestError(i18n.t('errors.api.authentication.invalidTokenTypeHint'));
311312
}
312313

313314
return token.destroyByToken({token: object.token}).then(function () {
314315
return Promise.resolve({token: object.token});
315316
}, function () {
316317
// On error we still want a 200. See https://tools.ietf.org/html/rfc7009#page-5
317-
return Promise.resolve({token: object.token, error: 'Invalid token provided'});
318+
return Promise.resolve({token: object.token, error: i18n.t('errors.api.authentication.invalidTokenProvided')});
318319
});
319320
}
320321
};

core/server/api/clients.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var Promise = require('bluebird'),
66
errors = require('../errors'),
77
utils = require('./utils'),
88
pipeline = require('../utils/pipeline'),
9+
i18n = require('../i18n'),
910

1011
docName = 'clients',
1112
clients;
@@ -52,7 +53,7 @@ clients = {
5253
return {clients: [result.toJSON(options)]};
5354
}
5455

55-
return Promise.reject(new errors.NotFoundError('Client not found.'));
56+
return Promise.reject(new errors.NotFoundError(i18n.t('common.api.clients.clientNotFound')));
5657
});
5758
}
5859
};

core/server/api/configuration.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var _ = require('lodash'),
44
config = require('../config'),
55
errors = require('../errors'),
66
Promise = require('bluebird'),
7+
i18n = require('../i18n'),
78

89
configuration;
910

@@ -58,7 +59,7 @@ configuration = {
5859
value: data[options.key]
5960
}]});
6061
} else {
61-
return Promise.reject(new errors.NotFoundError('Invalid key'));
62+
return Promise.reject(new errors.NotFoundError(i18n.t('errors.api.configuration.invalidKey')));
6263
}
6364
}
6465
};

core/server/api/db.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var _ = require('lodash'),
88
errors = require('../errors'),
99
utils = require('./utils'),
1010
pipeline = require('../utils/pipeline'),
11+
i18n = require('../i18n'),
1112

1213
api = {},
1314
docName = 'db',
@@ -66,13 +67,13 @@ db = {
6667
function validate(options) {
6768
// Check if a file was provided
6869
if (!utils.checkFileExists(options, 'importfile')) {
69-
return Promise.reject(new errors.ValidationError('Please select a file to import.'));
70+
return Promise.reject(new errors.ValidationError(i18n.t('errors.api.db.selectFileToImport')));
7071
}
7172

7273
// Check if the file is valid
7374
if (!utils.checkFileIsValid(options.importfile, importer.getTypes(), importer.getExtensions())) {
7475
return Promise.reject(new errors.UnsupportedMediaTypeError(
75-
'Unsupported file. Please try any of the following formats: ' +
76+
i18n.t('errors.api.db.unsupportedFile') +
7677
_.reduce(importer.getExtensions(), function (memo, ext) {
7778
return memo ? memo + ', ' + ext : ext;
7879
})

core/server/api/mail.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ var _ = require('lodash').runInContext(),
1212
fs = require('fs'),
1313
templatesDir = path.resolve(__dirname, '..', 'mail', 'templates'),
1414
htmlToText = require('html-to-text'),
15-
1615
readFile = Promise.promisify(fs.readFile),
1716
docName = 'mail',
17+
i18n = require('../i18n'),
1818
mail;
1919

2020
_.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
@@ -112,7 +112,7 @@ mail = {
112112
mail: [{
113113
message: {
114114
to: result.get('email'),
115-
subject: 'Test Ghost Email',
115+
subject: i18n.t('common.api.mail.testGhostEmail'),
116116
html: content.html,
117117
text: content.text
118118
}

core/server/api/notifications.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var Promise = require('bluebird'),
77
utils = require('./utils'),
88
pipeline = require('../utils/pipeline'),
99
canThis = permissions.canThis,
10+
i18n = require('../i18n'),
1011

1112
// Holds the persistent notifications
1213
notificationsStore = [],
@@ -30,7 +31,7 @@ notifications = {
3031
return canThis(options.context).browse.notification().then(function () {
3132
return {notifications: notificationsStore};
3233
}, function () {
33-
return Promise.reject(new errors.NoPermissionError('You do not have permission to browse notifications.'));
34+
return Promise.reject(new errors.NoPermissionError(i18n.t('errors.api.notifications.noPermissionToBrowseNotif')));
3435
});
3536
},
3637

@@ -65,7 +66,7 @@ notifications = {
6566
return canThis(options.context).add.notification().then(function () {
6667
return options;
6768
}, function () {
68-
return Promise.reject(new errors.NoPermissionError('You do not have permission to add notifications.'));
69+
return Promise.reject(new errors.NoPermissionError(i18n.t('errors.api.notifications.noPermissionToAddNotif')));
6970
});
7071
}
7172

@@ -129,7 +130,7 @@ notifications = {
129130
return canThis(options.context).destroy.notification().then(function () {
130131
return options;
131132
}, function () {
132-
return Promise.reject(new errors.NoPermissionError('You do not have permission to destroy notifications.'));
133+
return Promise.reject(new errors.NoPermissionError(i18n.t('errors.api.notifications.noPermissionToDestroyNotif')));
133134
});
134135
}
135136

@@ -140,12 +141,12 @@ notifications = {
140141

141142
if (notification && !notification.dismissible) {
142143
return Promise.reject(
143-
new errors.NoPermissionError('You do not have permission to dismiss this notification.')
144+
new errors.NoPermissionError(i18n.t('errors.api.notifications.noPermissionToDismissNotif'))
144145
);
145146
}
146147

147148
if (!notification) {
148-
return Promise.reject(new errors.NotFoundError('Notification does not exist.'));
149+
return Promise.reject(new errors.NotFoundError(i18n.t('errors.api.notifications.notificationDoesNotExist')));
149150
}
150151

151152
notificationsStore = _.reject(notificationsStore, function (element) {
@@ -181,7 +182,7 @@ notifications = {
181182

182183
return notificationsStore;
183184
}, function () {
184-
return Promise.reject(new errors.NoPermissionError('You do not have permission to destroy notifications.'));
185+
return Promise.reject(new errors.NoPermissionError(i18n.t('errors.api.notifications.noPermissionToDestroyNotif')));
185186
});
186187
}
187188
};

core/server/api/posts.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var Promise = require('bluebird'),
66
errors = require('../errors'),
77
utils = require('./utils'),
88
pipeline = require('../utils/pipeline'),
9+
i18n = require('../i18n'),
910

1011
docName = 'posts',
1112
allowedIncludes = [
@@ -106,7 +107,7 @@ posts = {
106107
return {posts: [result.toJSON(options)]};
107108
}
108109

109-
return Promise.reject(new errors.NotFoundError('Post not found.'));
110+
return Promise.reject(new errors.NotFoundError(i18n.t('errors.api.posts.postNotFound')));
110111
});
111112
},
112113

@@ -153,7 +154,7 @@ posts = {
153154
return {posts: [post]};
154155
}
155156

156-
return Promise.reject(new errors.NotFoundError('Post not found.'));
157+
return Promise.reject(new errors.NotFoundError(i18n.t('errors.api.posts.postNotFound')));
157158
});
158159
},
159160

core/server/api/settings.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var _ = require('lodash'),
77
canThis = require('../permissions').canThis,
88
errors = require('../errors'),
99
utils = require('./utils'),
10+
i18n = require('../i18n'),
1011

1112
docName = 'settings',
1213
settings,
@@ -36,9 +37,9 @@ var _ = require('lodash'),
3637
*/
3738
updateConfigCache = function () {
3839
var errorMessages = [
39-
'Error: Invalid JSON in settings.labs',
40-
'The column with key "labs" could not be parsed as JSON',
41-
'Please try updating a setting on the labs page, or manually editing your DB'
40+
i18n.t('errors.api.settings.invalidJsonInLabs'),
41+
i18n.t('errors.api.settings.labsColumnCouldNotBeParsed'),
42+
i18n.t('errors.api.settings.tryUpdatingLabs')
4243
], labsValue = {};
4344

4445
if (settingsCache.labs && settingsCache.labs.value) {
@@ -245,7 +246,7 @@ populateDefaultSetting = function (key) {
245246
}
246247

247248
// TODO: Different kind of error?
248-
return Promise.reject(new errors.NotFoundError('Problem finding setting: ' + key));
249+
return Promise.reject(new errors.NotFoundError(i18n.t('errors.api.settings.problemFindingSetting', {key: key})));
249250
});
250251
};
251252

@@ -260,12 +261,12 @@ canEditAllSettings = function (settingsInfo, options) {
260261
var checkSettingPermissions = function (setting) {
261262
if (setting.type === 'core' && !(options.context && options.context.internal)) {
262263
return Promise.reject(
263-
new errors.NoPermissionError('Attempted to access core setting from external request')
264+
new errors.NoPermissionError(i18n.t('errors.api.settings.accessCoreSettingFromExtReq'))
264265
);
265266
}
266267

267268
return canThis(options.context).edit.setting(setting.key).catch(function () {
268-
return Promise.reject(new errors.NoPermissionError('You do not have permission to edit settings.'));
269+
return Promise.reject(new errors.NoPermissionError(i18n.t('errors.api.settings.noPermissionToEditSettings')));
269270
});
270271
},
271272
checks = _.map(settingsInfo, function (settingInfo) {
@@ -344,7 +345,7 @@ settings = {
344345

345346
if (setting.type === 'core' && !(options.context && options.context.internal)) {
346347
return Promise.reject(
347-
new errors.NoPermissionError('Attempted to access core setting from external request')
348+
new errors.NoPermissionError(i18n.t('errors.api.settings.accessCoreSettingFromExtReq'))
348349
);
349350
}
350351

@@ -355,7 +356,7 @@ settings = {
355356
return canThis(options.context).read.setting(options.key).then(function () {
356357
return settingsResult(result);
357358
}, function () {
358-
return Promise.reject(new errors.NoPermissionError('You do not have permission to read settings.'));
359+
return Promise.reject(new errors.NoPermissionError(i18n.t('errors.api.settings.noPermissionToReadSettings')));
359360
});
360361
};
361362

0 commit comments

Comments
 (0)