Use structured jsons instead of POT file

This commit is contained in:
dominik-zeglen 2020-02-13 12:14:47 +01:00
parent c4c0f22cec
commit dc396f9830
7 changed files with 5057 additions and 10223 deletions

View file

@ -1,10 +1,10 @@
[main] [main]
host = https://www.transifex.com host = https://www.transifex.com
[saleor-1.dashboard-20] [saleor-1.dashboard-20-json]
file_filter = locale/<lang>.po file_filter = locale/<lang>.po
minimum_perc = 1 minimum_perc = 1
source_file = locale/messages.pot source_file = locale/defaultMessages.json
source_lang = en source_lang = en
type = PO type = STRUCTURED_JSON

View file

@ -47,8 +47,8 @@ module.exports = api => {
plugins.push("macros"); plugins.push("macros");
return { return {
presets, ignore,
plugins, plugins,
ignore presets,
}; };
}; };

4896
locale/defaultMessages.json Normal file

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

111
package-lock.json generated
View file

@ -762,6 +762,54 @@
"js-tokens": "^4.0.0" "js-tokens": "^4.0.0"
} }
}, },
"@babel/node": {
"version": "7.8.4",
"resolved": "https://registry.npmjs.org/@babel/node/-/node-7.8.4.tgz",
"integrity": "sha512-MlczXI/VYRnoaWHjicqrzq2z4DhRPaWQIC+C3ISEQs5z+mEccBsn7IAI5Q97ZDTnFYw6ts5IUTzqArilC/g7nw==",
"dev": true,
"requires": {
"@babel/register": "^7.8.3",
"commander": "^4.0.1",
"core-js": "^3.2.1",
"lodash": "^4.17.13",
"node-environment-flags": "^1.0.5",
"regenerator-runtime": "^0.13.3",
"resolve": "^1.13.1",
"v8flags": "^3.1.1"
},
"dependencies": {
"commander": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/commander/-/commander-4.1.1.tgz",
"integrity": "sha512-NOKm8xhkzAjzFx8B2v5OAHT+u5pRQc2UCa2Vq9jYL/31o2wi9mxBA7LIFs3sV5VSC49z6pEhfbMULvShKj26WA==",
"dev": true
},
"regenerator-runtime": {
"version": "0.13.3",
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.3.tgz",
"integrity": "sha512-naKIZz2GQ8JWh///G7L3X6LaQUAMp2lvb1rvwwsURe/VXwD6VMfr+/1NuNw3ag8v2kY1aQ/go5SNn79O9JU7yw==",
"dev": true
},
"resolve": {
"version": "1.15.1",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.15.1.tgz",
"integrity": "sha512-84oo6ZTtoTUpjgNEr5SJyzQhzL72gaRodsSfyxC/AXRvwu0Yse9H8eF9IpGo7b8YetZhlI6v7ZQ6bKBFV/6S7w==",
"dev": true,
"requires": {
"path-parse": "^1.0.6"
}
},
"v8flags": {
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/v8flags/-/v8flags-3.1.3.tgz",
"integrity": "sha512-amh9CCg3ZxkzQ48Mhcb8iX7xpAfYJgePHxWMQCBWECpOSqJUXgY26ncA61UTV0BkPqfhcy6mzwCIoP4ygxpW8w==",
"dev": true,
"requires": {
"homedir-polyfill": "^1.0.1"
}
}
}
},
"@babel/parser": { "@babel/parser": {
"version": "7.7.2", "version": "7.7.2",
"resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.7.2.tgz", "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.7.2.tgz",
@ -1676,6 +1724,32 @@
} }
} }
}, },
"@babel/register": {
"version": "7.8.3",
"resolved": "https://registry.npmjs.org/@babel/register/-/register-7.8.3.tgz",
"integrity": "sha512-t7UqebaWwo9nXWClIPLPloa5pN33A2leVs8Hf0e9g9YwUP8/H9NeR7DJU+4CXo23QtjChQv5a3DjEtT83ih1rg==",
"dev": true,
"requires": {
"find-cache-dir": "^2.0.0",
"lodash": "^4.17.13",
"make-dir": "^2.1.0",
"pirates": "^4.0.0",
"source-map-support": "^0.5.16"
},
"dependencies": {
"find-cache-dir": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/find-cache-dir/-/find-cache-dir-2.1.0.tgz",
"integrity": "sha512-Tq6PixE0w/VMFfCgbONnkiQIVol/JJL7nRMi20fqzA4NRs9AfeqMGeRdPi3wIhYkxjeBaWh2rxwapn5Tu3IqOQ==",
"dev": true,
"requires": {
"commondir": "^1.0.1",
"make-dir": "^2.0.0",
"pkg-dir": "^3.0.0"
}
}
}
},
"@babel/runtime": { "@babel/runtime": {
"version": "7.7.6", "version": "7.7.6",
"resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.7.6.tgz", "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.7.6.tgz",
@ -14721,6 +14795,15 @@
"resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz",
"integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==" "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg=="
}, },
"json-stable-stringify": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/json-stable-stringify/-/json-stable-stringify-1.0.1.tgz",
"integrity": "sha1-mnWdOcXy/1A/1TAGRu1EX4jE+a8=",
"dev": true,
"requires": {
"jsonify": "~0.0.0"
}
},
"json-stable-stringify-without-jsonify": { "json-stable-stringify-without-jsonify": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz", "resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz",
@ -14756,6 +14839,12 @@
"graceful-fs": "^4.1.6" "graceful-fs": "^4.1.6"
} }
}, },
"jsonify": {
"version": "0.0.0",
"resolved": "https://registry.npmjs.org/jsonify/-/jsonify-0.0.0.tgz",
"integrity": "sha1-LHS27kHZPKUbe1qu6PUDYx0lKnM=",
"dev": true
},
"jsprim": { "jsprim": {
"version": "1.4.1", "version": "1.4.1",
"resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz", "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz",
@ -16436,6 +16525,16 @@
"minimatch": "^3.0.2" "minimatch": "^3.0.2"
} }
}, },
"node-environment-flags": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/node-environment-flags/-/node-environment-flags-1.0.6.tgz",
"integrity": "sha512-5Evy2epuL+6TM0lCQGpFIj6KwiEsGh1SrHUhTbNX+sLbBtjidPZFAnVK9y5yU1+h//RitLbRHTIMyxQPtxMdHw==",
"dev": true,
"requires": {
"object.getownpropertydescriptors": "^2.0.3",
"semver": "^5.7.0"
}
},
"node-fetch": { "node-fetch": {
"version": "2.6.0", "version": "2.6.0",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz",
@ -18752,6 +18851,18 @@
} }
} }
}, },
"react-intl-translations-manager": {
"version": "5.0.3",
"resolved": "https://registry.npmjs.org/react-intl-translations-manager/-/react-intl-translations-manager-5.0.3.tgz",
"integrity": "sha512-EfBeugnOGFcdUbQyY9TqBMbuauQ8wm73ZqFr0UqCljhbXl7YDHQcVzclWFRkVmlUffzxitLQFhAZEVVeRNQSwA==",
"dev": true,
"requires": {
"chalk": "^2.3.2",
"glob": "^7.1.2",
"json-stable-stringify": "^1.0.1",
"mkdirp": "^0.5.1"
}
},
"react-is": { "react-is": {
"version": "16.11.0", "version": "16.11.0",
"resolved": "https://registry.npmjs.org/react-is/-/react-is-16.11.0.tgz", "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.11.0.tgz",

View file

@ -131,6 +131,7 @@
"plop": "^2.4.0", "plop": "^2.4.0",
"prettier": "^1.19.1", "prettier": "^1.19.1",
"react-intl-po": "^2.2.2", "react-intl-po": "^2.2.2",
"react-intl-translations-manager": "^5.0.3",
"react-test-renderer": "^16.12.0", "react-test-renderer": "^16.12.0",
"regenerator-runtime": "^0.11.1", "regenerator-runtime": "^0.11.1",
"require-context.macro": "^1.1.1", "require-context.macro": "^1.1.1",
@ -184,8 +185,8 @@
"scripts": { "scripts": {
"build": "webpack -p", "build": "webpack -p",
"extract-json-messages": "rimraf build/locale && cross-env NODE_ENV=extract babel src 'src/**/*.{ts,tsx}' -o build/dashboard.bundle.js", "extract-json-messages": "rimraf build/locale && cross-env NODE_ENV=extract babel src 'src/**/*.{ts,tsx}' -o build/dashboard.bundle.js",
"extract-pot-messages": "rip json2pot \"build/locale/**/*.json\" -c description -o locale/messages.pot", "transpile-messages": "node scripts/transpile-tx.js",
"extract-messages": "npm run extract-json-messages && npm run extract-pot-messages", "extract-messages": "npm run extract-json-messages && npm run transpile-messages",
"build-messages": "rip po2json 'locale/**/*.po' -m 'build/locale/**/*.json' -o 'locale' -c 'description'", "build-messages": "rip po2json 'locale/**/*.po' -m 'build/locale/**/*.json' -o 'locale' -c 'description'",
"build-types": "apollo client:codegen --target=typescript types --globalTypesFile=src/types/globalTypes.ts", "build-types": "apollo client:codegen --target=typescript types --globalTypesFile=src/types/globalTypes.ts",
"check-types": "tsc --noEmit", "check-types": "tsc --noEmit",

42
scripts/transpile-tx.js Normal file
View file

@ -0,0 +1,42 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const {
createSingleMessagesFile,
default: manageTranslations
} = require("react-intl-translations-manager");
const sortKeys = true;
const translationsDirectory = "locale";
manageTranslations({
messagesDirectory: "build/locale/src",
overrideCoreMethods: {
outputSingleFile: combinedFiles => {
const msgDescriptors = combinedFiles.reduce(
(acc, messages) => [...acc, ...messages.descriptors],
[]
);
const structuredJsonFormat = msgDescriptors.reduce((msgs, msg) => {
const key = msg.id.replace(/\./g, "_dot_");
if (msgs[key] && msgs[key].context === undefined) {
msgs[key].context = msg.description;
} else {
msgs[key] = {
context: msg.description,
string: msg.defaultMessage
};
}
return msgs;
}, {});
createSingleMessagesFile({
directory: translationsDirectory,
messages: structuredJsonFormat,
sortKeys
});
}
},
singleMessagesFile: true,
sortKeys,
translationsDirectory
});