Skip to content

Commit 5cb0c61

Browse files
committed
fix(translations): Moved all field validation error translations into a separate project (joi-messages)
1 parent 4bc743a commit 5cb0c61

17 files changed

+1787
-1058
lines changed

data/google-crawlers.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"creationTime": "2024-01-09T23:00:41.000000",
2+
"creationTime": "2024-01-23T23:00:42.000000",
33
"prefixes": [
44
{
55
"ipv6Prefix": "2001:4860:4801:2008::/64"

lib/translations.js

+5-35
Original file line numberDiff line numberDiff line change
@@ -4,52 +4,22 @@ const fs = require('fs').promises;
44
const Path = require('path');
55
const Gettext = require('node-gettext');
66
const { mo } = require('gettext-parser');
7-
const logger = require('./logger');
87
const locales = require('../translations/locales.json');
8+
const joiMessages = require('@postalsys/joi-messages');
99

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

1313
const joiLocales = {};
1414

15-
const joiLocaleKeys = ['de_DE', 'en_US', 'es_ES', 'fr_FR', 'pt_BR', 'ru_RU', 'tr_TR', 'et_EE'];
16-
17-
function unwrapLocale(localeObj) {
18-
let res = {};
19-
for (let key of Object.keys(localeObj)) {
20-
if (!localeObj[key] || typeof localeObj[key] !== 'object') {
21-
continue;
22-
}
23-
for (let subKey of Object.keys(localeObj[key])) {
24-
if (!localeObj[key][subKey] || typeof localeObj[key][subKey] !== 'string') {
25-
continue;
26-
}
27-
res[`${key}.${subKey}`] = localeObj[key][subKey].replace(/^./, c => c.toUpperCase());
28-
}
29-
}
30-
return res;
31-
}
32-
3315
const gt = new Gettext();
3416

3517
async function loadTranslations() {
3618
// Joi translations
37-
for (let joiLocale of joiLocaleKeys) {
38-
let localeObj;
39-
40-
try {
41-
let fContent = await fs.readFile(Path.join(translationsDir, 'joi', `${joiLocale}.json`));
42-
localeObj = JSON.parse(fContent);
43-
} catch (err) {
44-
logger.error({ msg: 'Failed to load Joi locale', joiLocale, err });
45-
continue;
46-
}
47-
48-
joiLocales[joiLocale] = unwrapLocale(localeObj);
49-
let language = joiLocale.split('_').shift();
50-
if (!joiLocales[language]) {
51-
joiLocales[language] = unwrapLocale(localeObj);
52-
}
19+
20+
let joiMessageLocales = await joiMessages.messages();
21+
for (let joiLocale of Object.keys(joiMessageLocales)) {
22+
joiLocales[joiLocale] = joiMessageLocales[joiLocale];
5323
}
5424

5525
// Gettext translations

package.json

+9-7
Original file line numberDiff line numberDiff line change
@@ -46,29 +46,30 @@
4646
"@hapi/boom": "10.0.1",
4747
"@hapi/cookie": "12.0.1",
4848
"@hapi/crumb": "9.0.1",
49-
"@hapi/hapi": "21.3.2",
49+
"@hapi/hapi": "21.3.3",
5050
"@hapi/inert": "7.1.0",
5151
"@hapi/vision": "7.0.3",
5252
"@phc/pbkdf2": "1.1.14",
5353
"@postalsys/certs": "1.0.7",
5454
"@postalsys/email-ai-tools": "1.8.0",
5555
"@postalsys/email-text-tools": "2.1.3",
5656
"@postalsys/hecks": "3.0.0-fork.3",
57+
"@postalsys/joi-messages": "1.0.1",
5758
"@postalsys/templates": "1.0.7",
58-
"ace-builds": "1.32.3",
59+
"ace-builds": "1.32.5",
5960
"base32.js": "0.1.0",
6061
"bull-arena": "4.1.0",
61-
"bullmq": "5.1.2",
62+
"bullmq": "5.1.5",
6263
"compare-versions": "6.1.0",
63-
"dotenv": "16.3.1",
64+
"dotenv": "16.4.1",
6465
"encoding-japanese": "2.0.0",
6566
"exponential-backoff": "3.1.1",
6667
"express": "4.18.2",
6768
"gettext-parser": "7.0.1",
6869
"handlebars": "4.7.8",
6970
"hapi-auth-bearer-token": "8.0.0",
7071
"hapi-pino": "12.1.0",
71-
"hapi-swagger": "17.2.0",
72+
"hapi-swagger": "17.2.1",
7273
"he": "1.2.0",
7374
"html-to-text": "9.0.5",
7475
"humanize": "0.0.9",
@@ -78,7 +79,7 @@
7879
"ioredfour": "1.3.0-ioredis-07",
7980
"ioredis": "5.3.2",
8081
"ipaddr.js": "2.1.0",
81-
"joi": "17.11.1",
82+
"joi": "17.12.1",
8283
"jquery": "3.7.1",
8384
"js-beautify": "1.14.11",
8485
"libbase64": "1.2.1",
@@ -111,7 +112,7 @@
111112
"xml2js": "0.6.2"
112113
},
113114
"devDependencies": {
114-
"chai": "5.0.0",
115+
"chai": "5.0.3",
115116
"eerawlog": "1.5.1",
116117
"eslint": "8.56.0",
117118
"eslint-config-nodemailer": "1.2.0",
@@ -120,6 +121,7 @@
120121
"grunt-cli": "1.4.3",
121122
"grunt-eslint": "24.3.0",
122123
"jsxgettext": "0.11.0",
124+
"npm-check-updates": "16.14.14",
123125
"pino-pretty": "10.3.1",
124126
"pkg": "5.8.1",
125127
"resedit": "2.0.0",

sbom.json

+1-1
Large diffs are not rendered by default.

static/js/ace/ace.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

static/js/ace/ext-language_tools.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)