Skip to content

Commit 2e2bc60

Browse files
Move translation into separate file
Signed-off-by: Raimund Schlüßler <raimund.schluessler@mailbox.org>
1 parent 70d6dce commit 2e2bc60

File tree

2 files changed

+41
-38
lines changed

2 files changed

+41
-38
lines changed

translations.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const fs = require('fs')
2+
const gettextParser = require('gettext-parser')
3+
4+
// https://github.com/alexanderwallin/node-gettext#usage
5+
// https://github.com/alexanderwallin/node-gettext#load-and-add-translations-from-mo-or-po-files
6+
const translations = fs
7+
.readdirSync('./l10n')
8+
.filter(name => name !== 'messages.pot' && name.endsWith('.pot'))
9+
.map(file => {
10+
const path = './l10n/' + file
11+
const locale = file.substr(0, file.length - '.pot'.length)
12+
13+
const po = fs.readFileSync(path)
14+
const json = gettextParser.po.parse(po)
15+
16+
// Compress translations Content
17+
const translations = {}
18+
for (const key in json.translations['']) {
19+
if (key !== '') {
20+
// Plural
21+
if ('msgid_plural'in json.translations[''][key]) {
22+
translations[json.translations[''][key].msgid] = {
23+
pluralId: json.translations[''][key].msgid_plural,
24+
msgstr: json.translations[''][key].msgstr,
25+
}
26+
continue
27+
}
28+
29+
// Singular
30+
translations[json.translations[''][key].msgid] = json.translations[''][key].msgstr[0]
31+
}
32+
}
33+
34+
return {
35+
locale,
36+
translations,
37+
}
38+
})
39+
40+
module.exports = translations

webpack.js

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
const webpackConfig = require('@nextcloud/webpack-vue-config')
22
const webpackRules = require('@nextcloud/webpack-vue-config/rules')
33

4-
const fs = require('fs')
5-
const gettextParser = require('gettext-parser')
64
const glob = require('glob')
75
const md5 = require('md5')
86
const path = require('path')
7+
const translations = require('./translations')
98

109
const { DefinePlugin } = require('webpack')
1110
const nodeExternals = require('webpack-node-externals')
@@ -18,42 +17,6 @@ const SCOPE_VERSION = JSON.stringify(versionHash)
1817

1918
console.info('This build version hash is', versionHash, '\n')
2019

21-
// https://github.com/alexanderwallin/node-gettext#usage
22-
// https://github.com/alexanderwallin/node-gettext#load-and-add-translations-from-mo-or-po-files
23-
const translations = fs
24-
.readdirSync('./l10n')
25-
.filter(name => name !== 'messages.pot' && name.endsWith('.pot'))
26-
.map(file => {
27-
const path = './l10n/' + file
28-
const locale = file.substr(0, file.length - '.pot'.length)
29-
30-
const po = fs.readFileSync(path)
31-
const json = gettextParser.po.parse(po)
32-
33-
// Compress translations Content
34-
const translations = {}
35-
for (const key in json.translations['']) {
36-
if (key !== '') {
37-
// Plural
38-
if ('msgid_plural'in json.translations[''][key]) {
39-
translations[json.translations[''][key].msgid] = {
40-
pluralId: json.translations[''][key].msgid_plural,
41-
msgstr: json.translations[''][key].msgstr,
42-
}
43-
continue
44-
}
45-
46-
// Singular
47-
translations[json.translations[''][key].msgid] = json.translations[''][key].msgstr[0]
48-
}
49-
}
50-
51-
return {
52-
locale,
53-
translations,
54-
}
55-
})
56-
5720
webpackConfig.entry = {
5821
ncvuecomponents: path.join(__dirname, 'src', 'index.js'),
5922
...glob.sync('src/components/*/index.js').reduce((acc, item) => {

0 commit comments

Comments
 (0)