generated from eea/volto-addon-template
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from eea/develop
Add infrastructure support for i18n and locales folder (#23)
- Loading branch information
Showing
6 changed files
with
329 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('@plone/volto/babel'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Plone\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2017-04-27T19:30:59.079Z\n" | ||
"PO-Revision-Date: 2016-10-22 16:41-0500\n" | ||
"Last-Translator: German <[email protected]>\n" | ||
"Language: de\n" | ||
"Language-Team: German <[email protected]>\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: 8bit\n" | ||
"Plural-Forms: nplurals=1; plural=0;\n" | ||
"MIME-Version: 1.0\n" | ||
"Language-Code: de\n" | ||
"Language-Name: Deutsch\n" | ||
"Preferred-Encodings: utf-8 latin1\n" | ||
"X-Is-Fallback-For: de-at de-li de-lu de-ch de-de\n" | ||
|
||
#: components/manage/Blocks/Accordion/Schema | ||
msgid "Accordion" | ||
msgstr "Akkordeon" | ||
|
||
#: components/manage/Blocks/Accordion/Schema | ||
msgid "Accordion Title size" | ||
msgstr "Akkordeon Schriftgröße Titel" | ||
|
||
#: components/manage/Blocks/Accordion/Schema | ||
msgid "Allow multiple panels open at a time" | ||
msgstr "Erlaube mehrere Panele zur gleichen Zeit geöffnet zu haben" | ||
|
||
#: components/manage/Blocks/Accordion/Schema | ||
msgid "Collapsed by default" | ||
msgstr "Eingeklappt ist der Standard" | ||
|
||
#: components/manage/Blocks/Accordion/Schema | ||
msgid "Friendly name" | ||
msgstr "Kurzname" | ||
|
||
#: components/manage/Blocks/Accordion/Schema | ||
msgid "Non exclusive" | ||
msgstr "Nicht ausschließend" | ||
|
||
#: components/manage/Blocks/Accordion/Schema | ||
msgid "Style" | ||
msgstr "Aussehen" | ||
|
||
#: components/manage/Blocks/Accordion/Schema | ||
msgid "Title" | ||
msgstr "Titel" | ||
|
||
#: components/manage/Blocks/Accordion/Schema | ||
msgid "Title Icon on the right" | ||
msgstr "Titel-Icon auf der rechten Seite anzeigen" | ||
|
||
#: components/manage/Blocks/Accordion/Schema | ||
msgid "Title size" | ||
msgstr "Schriftgröße Titel" | ||
|
||
#: components/manage/Blocks/Accordion/EditBlockWrapper | ||
msgid "Unknown Block" | ||
msgstr "Unbekannter Block" | ||
|
||
#: components/manage/Blocks/Accordion/EditBlockWrapper | ||
msgid "delete" | ||
msgstr "löschen" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Plone\n" | ||
"POT-Creation-Date: 2021-09-16T09:40:55.321Z\n" | ||
"Last-Translator: Plone i18n <[email protected]>\n" | ||
"Language-Team: Plone i18n <[email protected]>\n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=utf-8\n" | ||
"Content-Transfer-Encoding: 8bit\n" | ||
"Plural-Forms: nplurals=1; plural=0;\n" | ||
"Language-Code: en\n" | ||
"Language-Name: English\n" | ||
"Preferred-Encodings: utf-8\n" | ||
"Domain: volto\n" | ||
|
||
#: components/manage/Blocks/Accordion/Schema | ||
# defaultMessage: Accordion | ||
msgid "Accordion" | ||
msgstr "" | ||
|
||
#: components/manage/Blocks/Accordion/Schema | ||
# defaultMessage: Accordion Title size | ||
msgid "Accordion Title size" | ||
msgstr "" | ||
|
||
#: components/manage/Blocks/Accordion/Schema | ||
# defaultMessage: Allow multiple panels open at a time | ||
msgid "Allow multiple panels open at a time" | ||
msgstr "" | ||
|
||
#: components/manage/Blocks/Accordion/Schema | ||
# defaultMessage: Collapsed by default | ||
msgid "Collapsed by default" | ||
msgstr "" | ||
|
||
#: components/manage/Blocks/Accordion/Schema | ||
# defaultMessage: Friendly name | ||
msgid "Friendly name" | ||
msgstr "" | ||
|
||
#: components/manage/Blocks/Accordion/Schema | ||
# defaultMessage: Non exclusive | ||
msgid "Non exclusive" | ||
msgstr "" | ||
|
||
#: components/manage/Blocks/Accordion/Schema | ||
# defaultMessage: Style | ||
msgid "Style" | ||
msgstr "" | ||
|
||
#: components/manage/Blocks/Accordion/Schema | ||
# defaultMessage: Title | ||
msgid "Title" | ||
msgstr "" | ||
|
||
#: components/manage/Blocks/Accordion/Schema | ||
# defaultMessage: Title Icon on the right | ||
msgid "Title Icon on the right" | ||
msgstr "" | ||
|
||
#: components/manage/Blocks/Accordion/Schema | ||
# defaultMessage: Title size | ||
msgid "Title size" | ||
msgstr "" | ||
|
||
#: components/manage/Blocks/Accordion/EditBlockWrapper | ||
# defaultMessage: Unknown Block {block} | ||
msgid "Unknown Block" | ||
msgstr "" | ||
|
||
#: components/manage/Blocks/Accordion/EditBlockWrapper | ||
# defaultMessage: delete | ||
msgid "delete" | ||
msgstr "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
/* eslint no-console: 0 */ | ||
/** | ||
* i18n script. | ||
* @module scripts/i18n | ||
*/ | ||
|
||
const { find, keys, map, concat, reduce } = require('lodash'); | ||
const glob = require('glob').sync; | ||
const fs = require('fs'); | ||
const Pofile = require('pofile'); | ||
const babel = require('@babel/core'); | ||
|
||
/** | ||
* Extract messages into separate JSON files | ||
* @function extractMessages | ||
* @return {undefined} | ||
*/ | ||
function extractMessages() { | ||
map(glob('src/**/*.js?(x)'), (filename) => { | ||
babel.transformFileSync(filename, {}, (err) => { | ||
if (err) { | ||
console.log(err); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
/** | ||
* Get messages from separate JSON files | ||
* @function getMessages | ||
* @return {Object} Object with messages | ||
*/ | ||
function getMessages() { | ||
return reduce( | ||
concat( | ||
{}, | ||
...map( | ||
// We ignore the existing customized shadowed components ones, since most | ||
// probably we won't be overriding them | ||
// If so, we should do it in the config object or somewhere else | ||
glob('build/messages/src/**/*.json', { | ||
ignore: 'build/messages/src/customizations/**', | ||
}), | ||
(filename) => | ||
map(JSON.parse(fs.readFileSync(filename, 'utf8')), (message) => ({ | ||
...message, | ||
filename: filename.match(/build\/messages\/src\/(.*).json$/)[1], | ||
})), | ||
), | ||
), | ||
(current, value) => { | ||
let result = current; | ||
if (current.id) { | ||
result = { | ||
[current.id]: { | ||
defaultMessage: current.defaultMessage, | ||
filenames: [current.filename], | ||
}, | ||
}; | ||
} | ||
|
||
if (result[value.id]) { | ||
result[value.id].filenames.push(value.filename); | ||
} else { | ||
result[value.id] = { | ||
defaultMessage: value.defaultMessage, | ||
filenames: [value.filename], | ||
}; | ||
} | ||
return result; | ||
}, | ||
); | ||
} | ||
|
||
/** | ||
* Convert messages to pot format | ||
* @function messagesToPot | ||
* @param {Object} messages Messages | ||
* @return {string} Formatted pot string | ||
*/ | ||
function messagesToPot(messages) { | ||
return map(keys(messages).sort(), (key) => | ||
[ | ||
...map(messages[key].filenames, (filename) => `#: ${filename}`), | ||
`# defaultMessage: ${messages[key].defaultMessage}`, | ||
`msgid "${key}"`, | ||
'msgstr ""', | ||
].join('\n'), | ||
).join('\n\n'); | ||
} | ||
|
||
/** | ||
* Pot header | ||
* @function potHeader | ||
* @return {string} Formatted pot header | ||
*/ | ||
function potHeader() { | ||
return `msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Plone\\n" | ||
"POT-Creation-Date: ${new Date().toISOString()}\\n" | ||
"Last-Translator: Plone i18n <[email protected]>\\n" | ||
"Language-Team: Plone i18n <[email protected]>\\n" | ||
"MIME-Version: 1.0\\n" | ||
"Content-Type: text/plain; charset=utf-8\\n" | ||
"Content-Transfer-Encoding: 8bit\\n" | ||
"Plural-Forms: nplurals=1; plural=0;\\n" | ||
"Language-Code: en\\n" | ||
"Language-Name: English\\n" | ||
"Preferred-Encodings: utf-8\\n" | ||
"Domain: volto\\n" | ||
`; | ||
} | ||
|
||
/** | ||
* Format header | ||
* @function formatHeader | ||
* @param {Array} comments Array of comments | ||
* @param {Object} headers Object of header items | ||
* @return {string} Formatted header | ||
*/ | ||
function formatHeader(comments, headers) { | ||
return [ | ||
...map(comments, (comment) => `# ${comment}`), | ||
'msgid ""', | ||
'msgstr ""', | ||
...map(keys(headers), (key) => `"${key}: ${headers[key]}\\n"`), | ||
'', | ||
].join('\n'); | ||
} | ||
|
||
/** | ||
* Sync po by the pot file | ||
* @function syncPoByPot | ||
* @return {undefined} | ||
*/ | ||
function syncPoByPot() { | ||
const pot = Pofile.parse(fs.readFileSync('locales/volto.pot', 'utf8')); | ||
|
||
map(glob('locales/**/*.po'), (filename) => { | ||
const po = Pofile.parse(fs.readFileSync(filename, 'utf8')); | ||
|
||
fs.writeFileSync( | ||
filename, | ||
`${formatHeader(po.comments, po.headers)} | ||
${map(pot.items, (item) => { | ||
const poItem = find(po.items, { msgid: item.msgid }); | ||
return [ | ||
`${map(item.references, (ref) => `#: ${ref}`).join('\n')}`, | ||
`msgid "${item.msgid}"`, | ||
`msgstr "${poItem ? poItem.msgstr : ''}"`, | ||
].join('\n'); | ||
}).join('\n\n')}\n`, | ||
); | ||
}); | ||
} | ||
|
||
// Main tasks | ||
console.log('Extracting messages from source files...'); | ||
extractMessages(); | ||
console.log('Synchronizing messages to pot file...'); | ||
// We only write the pot file if it's really different | ||
const newPot = `${potHeader()}${messagesToPot(getMessages())}\n`.replace( | ||
/"POT-Creation-Date:(.*)\\n"/, | ||
'', | ||
); | ||
const oldPot = fs | ||
.readFileSync('locales/volto.pot', 'utf8') | ||
.replace(/"POT-Creation-Date:(.*)\\n"/, ''); | ||
|
||
if (newPot !== oldPot) { | ||
fs.writeFileSync( | ||
'locales/volto.pot', | ||
`${potHeader()}${messagesToPot(getMessages())}\n`, | ||
); | ||
} | ||
console.log('Synchronizing messages to po files...'); | ||
syncPoByPot(); | ||
console.log('done!'); |