Skip to content

Commit

Permalink
fix(translations): Moved all field validation error translations into…
Browse files Browse the repository at this point in the history
… a separate project (joi-messages)
  • Loading branch information
andris9 committed Jan 30, 2024
1 parent 4bc743a commit 5cb0c61
Show file tree
Hide file tree
Showing 17 changed files with 1,787 additions and 1,058 deletions.
2 changes: 1 addition & 1 deletion data/google-crawlers.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"creationTime": "2024-01-09T23:00:41.000000",
"creationTime": "2024-01-23T23:00:42.000000",
"prefixes": [
{
"ipv6Prefix": "2001:4860:4801:2008::/64"
Expand Down
40 changes: 5 additions & 35 deletions lib/translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,22 @@ const fs = require('fs').promises;
const Path = require('path');
const Gettext = require('node-gettext');
const { mo } = require('gettext-parser');
const logger = require('./logger');
const locales = require('../translations/locales.json');
const joiMessages = require('@postalsys/joi-messages');

const translationsDir = Path.join(__dirname, '..', 'translations');
const domain = 'messages';

const joiLocales = {};

const joiLocaleKeys = ['de_DE', 'en_US', 'es_ES', 'fr_FR', 'pt_BR', 'ru_RU', 'tr_TR', 'et_EE'];

function unwrapLocale(localeObj) {
let res = {};
for (let key of Object.keys(localeObj)) {
if (!localeObj[key] || typeof localeObj[key] !== 'object') {
continue;
}
for (let subKey of Object.keys(localeObj[key])) {
if (!localeObj[key][subKey] || typeof localeObj[key][subKey] !== 'string') {
continue;
}
res[`${key}.${subKey}`] = localeObj[key][subKey].replace(/^./, c => c.toUpperCase());
}
}
return res;
}

const gt = new Gettext();

async function loadTranslations() {
// Joi translations
for (let joiLocale of joiLocaleKeys) {
let localeObj;

try {
let fContent = await fs.readFile(Path.join(translationsDir, 'joi', `${joiLocale}.json`));
localeObj = JSON.parse(fContent);
} catch (err) {
logger.error({ msg: 'Failed to load Joi locale', joiLocale, err });
continue;
}

joiLocales[joiLocale] = unwrapLocale(localeObj);
let language = joiLocale.split('_').shift();
if (!joiLocales[language]) {
joiLocales[language] = unwrapLocale(localeObj);
}

let joiMessageLocales = await joiMessages.messages();
for (let joiLocale of Object.keys(joiMessageLocales)) {
joiLocales[joiLocale] = joiMessageLocales[joiLocale];
}

// Gettext translations
Expand Down
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,30 @@
"@hapi/boom": "10.0.1",
"@hapi/cookie": "12.0.1",
"@hapi/crumb": "9.0.1",
"@hapi/hapi": "21.3.2",
"@hapi/hapi": "21.3.3",
"@hapi/inert": "7.1.0",
"@hapi/vision": "7.0.3",
"@phc/pbkdf2": "1.1.14",
"@postalsys/certs": "1.0.7",
"@postalsys/email-ai-tools": "1.8.0",
"@postalsys/email-text-tools": "2.1.3",
"@postalsys/hecks": "3.0.0-fork.3",
"@postalsys/joi-messages": "1.0.1",
"@postalsys/templates": "1.0.7",
"ace-builds": "1.32.3",
"ace-builds": "1.32.5",
"base32.js": "0.1.0",
"bull-arena": "4.1.0",
"bullmq": "5.1.2",
"bullmq": "5.1.5",
"compare-versions": "6.1.0",
"dotenv": "16.3.1",
"dotenv": "16.4.1",
"encoding-japanese": "2.0.0",
"exponential-backoff": "3.1.1",
"express": "4.18.2",
"gettext-parser": "7.0.1",
"handlebars": "4.7.8",
"hapi-auth-bearer-token": "8.0.0",
"hapi-pino": "12.1.0",
"hapi-swagger": "17.2.0",
"hapi-swagger": "17.2.1",
"he": "1.2.0",
"html-to-text": "9.0.5",
"humanize": "0.0.9",
Expand All @@ -78,7 +79,7 @@
"ioredfour": "1.3.0-ioredis-07",
"ioredis": "5.3.2",
"ipaddr.js": "2.1.0",
"joi": "17.11.1",
"joi": "17.12.1",
"jquery": "3.7.1",
"js-beautify": "1.14.11",
"libbase64": "1.2.1",
Expand Down Expand Up @@ -111,7 +112,7 @@
"xml2js": "0.6.2"
},
"devDependencies": {
"chai": "5.0.0",
"chai": "5.0.3",
"eerawlog": "1.5.1",
"eslint": "8.56.0",
"eslint-config-nodemailer": "1.2.0",
Expand All @@ -120,6 +121,7 @@
"grunt-cli": "1.4.3",
"grunt-eslint": "24.3.0",
"jsxgettext": "0.11.0",
"npm-check-updates": "16.14.14",
"pino-pretty": "10.3.1",
"pkg": "5.8.1",
"resedit": "2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion sbom.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion static/js/ace/ace.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion static/js/ace/ext-language_tools.js

Large diffs are not rendered by default.

Loading

0 comments on commit 5cb0c61

Please sign in to comment.