diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f72d28..85ea1ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,12 @@ +[Release 1.2.15-EPROC-20779-SNAPSHOT](https://github.com/OpusCapita/i18n/releases/tag/v1.2.15-EPROC-20779-SNAPSHOT) Thu Sep 30 2021 22:55:13 GMT+0300 (MSK) +======================================================= + +- Remove support of converting language specific translation bundles from json into properties file (Dmitriy Sanko dmitriy.sanko@opuscapita.com, 2021-09-30 22:44:53 +0300) +- (EPROC-20383) Used jdk zulu (GitHub ashestak-sc@users.noreply.github.com, 2021-04-06 16:50:55 +0300) +- (EPROC-20252) Added circleci builds jira integration (GitHub ashestak-sc@users.noreply.github.com, 2021-03-10 16:08:02 +0300) +- Update CI image to opuscapita/minsk-core-ci:grails-2.4.4-jdk-8u192-nodejs-8.17.0-maven-3.3.9 [ci skip] (Egor Stambakio egor.stambakio@opuscapita.com, 2020-05-07 16:13:08 +0300) + [Release 1.2.14](https://github.com/OpusCapita/i18n/releases/tag/v1.2.14) Thu Apr 09 2020 09:58:33 GMT+0300 (MSK) ======================================================= diff --git a/bin/i18n-js2properties.js b/bin/i18n-js2properties.js index f566d02..bfb198c 100644 --- a/bin/i18n-js2properties.js +++ b/bin/i18n-js2properties.js @@ -21,8 +21,6 @@ if (sourceObject.default) { sourceObject = sourceObject.default; } -const defaultLanguage = "en"; - function padWithLeadingZeros(string) { return new Array(5 - string.length).join("0") + string; } @@ -40,59 +38,41 @@ function unicodeEscape(string) { .join(""); } -if (!sourceObject[defaultLanguage]) { - console.error(`Default language [${defaultLanguage}] should be defined in translations [${source}]`); -} else { - const targetPath = path.resolve(process.cwd(), path.dirname(target)); - - if (!fs.existsSync(targetPath)) { - console.error(`Target path [${targetPath}] doesn't exists`); - } else { - const bundleName = path.basename(target); - - const languages = Object.keys(sourceObject); - - function flattenTranslationTexts(object, parentKey) { - let result = {}; - const keys = Object.keys(object); - - for (let i = 0, l = keys.length; i < l; i++) { - const key = keys[i]; - const propertiesKey = parentKey ? `${parentKey}.${key}` : key; - const value = object[key]; - - if (typeof value === "object") { - result = { - ...result, - ...flattenTranslationTexts(value, propertiesKey) - }; - } else { - result[propertiesKey] = value.toString(); - } - } - - return result; +function flattenTranslationTexts(object, parentKey) { + let result = {}; + const keys = Object.keys(object); + + for (let i = 0, l = keys.length; i < l; i++) { + const key = keys[i]; + const propertiesKey = parentKey ? `${parentKey}.${key}` : key; + const value = object[key]; + + if (typeof value === "object") { + result = { + ...result, + ...flattenTranslationTexts(value, propertiesKey) + }; + } else { + result[propertiesKey] = value.toString(); } + } - for (let i = 0; i < languages.length; i++) { - const language = languages[i]; - const objectTranslationTexts = sourceObject[language]; - const translationTexts = flattenTranslationTexts(objectTranslationTexts); - const propertiesText = properties.stringify(translationTexts); - const filePath = path.join(targetPath, `${bundleName}_${language}.properties`); + return result; +} - console.log(`Writing target file [${filePath}]`); - fs.writeFileSync(filePath, unicodeEscape(propertiesText)); - } +const targetPath = path.resolve(process.cwd(), path.dirname(target)); - const fromFilePath = path.join(targetPath, `${bundleName}_en.properties`); - const toFilePath = path.join(targetPath, `${bundleName}.properties`); - console.log(`Copy file [${fromFilePath}] to [${toFilePath}]`); - //save english properties as default - fs.createReadStream(fromFilePath).pipe( - fs.createWriteStream(toFilePath) - ); - } +if (!fs.existsSync(targetPath)) { + console.error(`Target path [${targetPath}] doesn't exists`); +} else { + const bundleName = path.basename(target); + + const translationTexts = flattenTranslationTexts(sourceObject); + const propertiesText = properties.stringify(translationTexts); + const filePath = path.join(targetPath, `${bundleName}.properties`); + + console.log(`Writing target file [${filePath}]`); + fs.writeFileSync(filePath, unicodeEscape(propertiesText)); } diff --git a/package.json b/package.json index 81062e9..bad386e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@opuscapita/i18n", - "version": "1.2.15-SNAPSHOT", + "version": "1.2.16-EPROC-20779-2-SNAPSHOT", "description": "OpusCapita simple i18n mechanism", "main": "lib/index.js", "files": [ diff --git a/src/cli/i18n-js2properties.spec.js b/src/cli/i18n-js2properties.spec.js index a8ca5be..3630548 100644 --- a/src/cli/i18n-js2properties.spec.js +++ b/src/cli/i18n-js2properties.spec.js @@ -40,15 +40,6 @@ describe("i18n-js to properties CLI", () => { fs.mkdirSync("tmp/grails-app"); fs.mkdirSync("tmp/grails-app/i18n"); fs.writeFileSync("tmp/i18n/index.js", ` -import en from './en'; -import de from './de'; - -export default { - en, - de -}; - `); - fs.writeFileSync("tmp/i18n/en.js", ` const header = { title: "test title" }; @@ -58,18 +49,6 @@ const form = { "a.b.c": "test a b c" }; -export default { messages: {header, form} } - `); - fs.writeFileSync("tmp/i18n/de.js", ` -const header = { - title: "de test title" -}; - -const form = { - "a.b": "de test a b", - "a.b.c": "de test a b c ΓΌ" -}; - export default { messages: {header, form} } `); }); @@ -87,31 +66,18 @@ export default { messages: {header, form} } expect( fs.existsSync("tmp/grails-app/i18n/messages_en.properties") - ).to.be.equal(true); + ).to.be.equal(false); expect( fs.existsSync("tmp/grails-app/i18n/messages_de.properties") - ).to.be.equal(true); + ).to.be.equal(false); - const englishProperties = properties.parse( - fs.readFileSync("tmp/grails-app/i18n/messages_en.properties").toString() + const defaultProperties = properties.parse( + fs.readFileSync("tmp/grails-app/i18n/messages.properties").toString() ); - expect(englishProperties).to.deep.include( + expect(defaultProperties).to.deep.include( { "messages.header.title": "test title", "messages.form.a.b": "test a b", "messages.form.a.b.c": "test a b c" } ); - - const germanProperties = properties.parse(fs.readFileSync("tmp/grails-app/i18n/messages_de.properties").toString()); - - expect(germanProperties).to.deep.include( - { - "messages.header.title": "de test title", - "messages.form.a.b": "de test a b", - "messages.form.a.b.c": "de test a b c \u00fc" - } - ); - - const defaultProperties = properties.parse(fs.readFileSync("tmp/grails-app/i18n/messages.properties").toString()); - expect(defaultProperties).to.deep.include(englishProperties); }); });