translation.js -> translations.js
kept confusing my why i can't find this file! this is in line with the rest of our code
This commit is contained in:
+2
-2
@@ -16,7 +16,7 @@ const assert = require('assert'),
|
||||
cron = require('./cron.js'),
|
||||
moment = require('moment-timezone'),
|
||||
settings = require('./settings.js'),
|
||||
translation = require('./translation.js');
|
||||
translations = require('./translations.js');
|
||||
|
||||
async function getStatus() {
|
||||
return {
|
||||
@@ -46,7 +46,7 @@ async function getLanguage() {
|
||||
async function setLanguage(language) {
|
||||
assert.strictEqual(typeof language, 'string');
|
||||
|
||||
const languages = await translation.listLanguages();
|
||||
const languages = await translations.listLanguages();
|
||||
if (languages.indexOf(language) === -1) throw new BoxError(BoxError.BAD_FIELD, 'Language not found');
|
||||
|
||||
await settings.set(settings.LANGUAGE_KEY, language);
|
||||
|
||||
+8
-8
@@ -26,7 +26,7 @@ const assert = require('assert'),
|
||||
nodemailer = require('nodemailer'),
|
||||
path = require('path'),
|
||||
safe = require('safetydance'),
|
||||
translation = require('./translation.js'),
|
||||
translations = require('./translations.js'),
|
||||
util = require('util');
|
||||
|
||||
const MAIL_TEMPLATES_DIR = path.join(__dirname, 'mail_templates');
|
||||
@@ -80,7 +80,7 @@ function render(templateFile, params, translationAssets) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (typeof translationAssets === 'object') raw = translation.translate(raw, translationAssets);
|
||||
if (typeof translationAssets === 'object') raw = translations.translate(raw, translationAssets);
|
||||
|
||||
try {
|
||||
content = ejs.render(raw, params);
|
||||
@@ -98,7 +98,7 @@ async function sendInvite(user, invitor, email, inviteLink) {
|
||||
assert.strictEqual(typeof inviteLink, 'string');
|
||||
|
||||
const mailConfig = await getMailConfig();
|
||||
const translationAssets = await translation.getTranslations();
|
||||
const translationAssets = await translations.getTranslations();
|
||||
const { fqdn:dashboardFqdn } = await dashboard.getLocation();
|
||||
|
||||
const templateData = {
|
||||
@@ -113,7 +113,7 @@ async function sendInvite(user, invitor, email, inviteLink) {
|
||||
const mailOptions = {
|
||||
from: mailConfig.notificationFrom,
|
||||
to: email,
|
||||
subject: ejs.render(translation.translate('{{ welcomeEmail.subject }}', translationAssets), { cloudron: mailConfig.cloudronName }),
|
||||
subject: ejs.render(translations.translate('{{ welcomeEmail.subject }}', translationAssets), { cloudron: mailConfig.cloudronName }),
|
||||
text: render('welcome_user-text.ejs', templateData, translationAssets),
|
||||
html: render('welcome_user-html.ejs', templateData, translationAssets)
|
||||
};
|
||||
@@ -133,7 +133,7 @@ async function sendNewLoginLocation(user, loginLocation) {
|
||||
assert.strictEqual(typeof city, 'string');
|
||||
|
||||
const mailConfig = await getMailConfig();
|
||||
const translationAssets = await translation.getTranslations();
|
||||
const translationAssets = await translations.getTranslations();
|
||||
const { fqdn:dashboardFqdn } = await dashboard.getLocation();
|
||||
|
||||
const templateData = {
|
||||
@@ -149,7 +149,7 @@ async function sendNewLoginLocation(user, loginLocation) {
|
||||
const mailOptions = {
|
||||
from: mailConfig.notificationFrom,
|
||||
to: user.email,
|
||||
subject: ejs.render(translation.translate('{{ newLoginEmail.subject }}', translationAssets), { cloudron: mailConfig.cloudronName }),
|
||||
subject: ejs.render(translations.translate('{{ newLoginEmail.subject }}', translationAssets), { cloudron: mailConfig.cloudronName }),
|
||||
text: render('new_login_location-text.ejs', templateData, translationAssets),
|
||||
html: render('new_login_location-html.ejs', templateData, translationAssets)
|
||||
};
|
||||
@@ -163,7 +163,7 @@ async function passwordReset(user, email, resetLink) {
|
||||
assert.strictEqual(typeof resetLink, 'string');
|
||||
|
||||
const mailConfig = await getMailConfig();
|
||||
const translationAssets = await translation.getTranslations();
|
||||
const translationAssets = await translations.getTranslations();
|
||||
const { fqdn:dashboardFqdn } = await dashboard.getLocation();
|
||||
|
||||
const templateData = {
|
||||
@@ -176,7 +176,7 @@ async function passwordReset(user, email, resetLink) {
|
||||
const mailOptions = {
|
||||
from: mailConfig.notificationFrom,
|
||||
to: email,
|
||||
subject: ejs.render(translation.translate('{{ passwordResetEmail.subject }}', translationAssets), { cloudron: mailConfig.cloudronName }),
|
||||
subject: ejs.render(translations.translate('{{ passwordResetEmail.subject }}', translationAssets), { cloudron: mailConfig.cloudronName }),
|
||||
text: render('password_reset-text.ejs', templateData, translationAssets),
|
||||
html: render('password_reset-html.ejs', templateData, translationAssets)
|
||||
};
|
||||
|
||||
+3
-3
@@ -41,7 +41,7 @@ const assert = require('assert'),
|
||||
safe = require('safetydance'),
|
||||
settings = require('./settings.js'),
|
||||
tokens = require('./tokens.js'),
|
||||
translation = require('./translation.js'),
|
||||
translations = require('./translations.js'),
|
||||
url = require('url'),
|
||||
users = require('./users.js'),
|
||||
util = require('util');
|
||||
@@ -463,7 +463,7 @@ function renderInteractionPage(provider) {
|
||||
assert.strictEqual(typeof provider, 'object');
|
||||
|
||||
return async function (req, res) {
|
||||
const translationAssets = await translation.getTranslations();
|
||||
const translationAssets = await translations.getTranslations();
|
||||
|
||||
try {
|
||||
const { uid, prompt, params, session } = await provider.interactionDetails(req, res);
|
||||
@@ -489,7 +489,7 @@ function renderInteractionPage(provider) {
|
||||
}
|
||||
|
||||
const template = fs.readFileSync(__dirname + '/oidc_templates/login.ejs', 'utf-8');
|
||||
const html = ejs.render(translation.translate(template, translationAssets), options);
|
||||
const html = ejs.render(translations.translate(template, translationAssets), options);
|
||||
|
||||
return res.send(html);
|
||||
}
|
||||
|
||||
+3
-3
@@ -27,7 +27,7 @@ const apps = require('./apps.js'),
|
||||
middleware = require('./middleware'),
|
||||
oidc = require('./oidc.js'),
|
||||
safe = require('safetydance'),
|
||||
translation = require('./translation.js'),
|
||||
translations = require('./translations.js'),
|
||||
users = require('./users.js'),
|
||||
util = require('util');
|
||||
|
||||
@@ -138,9 +138,9 @@ async function login(req, res, next) {
|
||||
});
|
||||
}
|
||||
|
||||
const translationAssets = await translation.getTranslations();
|
||||
const translationAssets = await translations.getTranslations();
|
||||
const template = fs.readFileSync(__dirname + '/oidc_templates/proxyauth_login.ejs', 'utf-8');
|
||||
const html = ejs.render(translation.translate(template, translationAssets), options);
|
||||
const html = ejs.render(translations.translate(template, translationAssets), options);
|
||||
|
||||
return res.send(html);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ const assert = require('assert'),
|
||||
HttpError = require('connect-lastmile').HttpError,
|
||||
HttpSuccess = require('connect-lastmile').HttpSuccess,
|
||||
safe = require('safetydance'),
|
||||
translation = require('../translation.js');
|
||||
translations = require('../translations.js');
|
||||
|
||||
async function getStatus(req, res, next) {
|
||||
const [error, status] = await safe(cloudron.getStatus());
|
||||
@@ -27,7 +27,7 @@ async function getStatus(req, res, next) {
|
||||
}
|
||||
|
||||
async function listLanguages(req, res, next) {
|
||||
const [error, languages] = await safe(translation.listLanguages());
|
||||
const [error, languages] = await safe(translations.listLanguages());
|
||||
if (error) return next(new BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, { languages }));
|
||||
|
||||
@@ -5,38 +5,38 @@
|
||||
'use strict';
|
||||
|
||||
const expect = require('expect.js'),
|
||||
translation = require('../translation.js');
|
||||
translations = require('../translations.js');
|
||||
|
||||
describe('translation', function () {
|
||||
|
||||
describe('translate', function () {
|
||||
it('nonexisting token', function () {
|
||||
const assets = { translations: {}, fallback: {} };
|
||||
const out = translation.translate('Foo {{ bar }}', assets);
|
||||
const out = translations.translate('Foo {{ bar }}', assets);
|
||||
expect(out).to.contain('{{ bar }}');
|
||||
});
|
||||
|
||||
it('existing token', function () {
|
||||
const assets = { translations: { bar: 'here' }, fallback: {} };
|
||||
const out = translation.translate('Foo {{ bar }}', assets);
|
||||
const out = translations.translate('Foo {{ bar }}', assets);
|
||||
expect(out).to.contain('here');
|
||||
});
|
||||
|
||||
it('existing token as fallback', function () {
|
||||
const assets = { translations: {}, fallback: { bar: 'here' } };
|
||||
const out = translation.translate('Foo {{ bar }}', assets);
|
||||
const out = translations.translate('Foo {{ bar }}', assets);
|
||||
expect(out).to.contain('here');
|
||||
});
|
||||
|
||||
it('existing token deep', function () {
|
||||
const assets = { translations: { bar: { baz: { foo: 'here' }}}, fallback: {} };
|
||||
const out = translation.translate('Foo {{ bar.baz.foo }}', assets);
|
||||
const out = translations.translate('Foo {{ bar.baz.foo }}', assets);
|
||||
expect(out).to.contain('here');
|
||||
});
|
||||
|
||||
it('existing token deep as fallback', function () {
|
||||
const assets = { translations: { bar: '' }, fallback: { bar: { baz: { foo: 'here' } } } };
|
||||
const out = translation.translate('Foo {{ bar.baz.foo }}', assets);
|
||||
const out = translations.translate('Foo {{ bar.baz.foo }}', assets);
|
||||
expect(out).to.contain('here');
|
||||
});
|
||||
|
||||
@@ -57,7 +57,7 @@ describe('translation', function () {
|
||||
};
|
||||
const input = 'Hello {{ something.missing.there}} and some more {{here}} and {{ there }} with odd spacing {{foo }} lots of{{ bar }}';
|
||||
|
||||
const out = translation.translate(input, assets);
|
||||
const out = translations.translate(input, assets);
|
||||
expect(out).to.contain('1');
|
||||
expect(out).to.contain('2');
|
||||
expect(out).to.contain('3');
|
||||
+2
-2
@@ -93,7 +93,7 @@ const appPasswords = require('./apppasswords.js'),
|
||||
settings = require('./settings.js'),
|
||||
speakeasy = require('speakeasy'),
|
||||
tokens = require('./tokens.js'),
|
||||
translation = require('./translation.js'),
|
||||
translations = require('./translations.js'),
|
||||
uaParser = require('ua-parser-js'),
|
||||
userDirectory = require('./user-directory.js'),
|
||||
uuid = require('uuid'),
|
||||
@@ -168,7 +168,7 @@ async function validateLanguage(language) {
|
||||
|
||||
if (language === '') return null; // reset to platform default
|
||||
|
||||
const languages = await translation.listLanguages();
|
||||
const languages = await translations.listLanguages();
|
||||
if (!languages.includes(language)) return new BoxError(BoxError.BAD_FIELD, 'Invalid language');
|
||||
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user