i18n feedback refactorings (#2597)

*  Create endpoint for node credential translation

*  Add API helper method in FE

* 🔨 Add creds JSON files to tsconfig

*  Refactor credentials loading

*  Refactor calls in CredentialConfig

* ✏️ Add dummy translations

*  Split translations per node

* 🔥 Remove deprecated method

*  Refactor nesting in collections

* 🚚 Rename topParameter methods for accuracy

* ✏️ Fill out GitHub dummy cred

* 🚚 Clarify naming for collection utils

* ✏️ Fill out dummy translation

* 🔥 Remove surplus colons

* 🔥 Remove logging

*  Restore missing space

* 🔥 Remove lingering colon

*  Add path to InputLabel calls

* ✏️ Fill out dummy translations

* 🐛 Fix multipleValuesButtonText logic

*  Add sample properties to be deleted

*  Render deeply nested params

* 📦 Update package-lock.json

* 🔥 remove logging

* ✏️ Add dummy value to Slack translation

* ✏️ Add placeholder to dummy translation

*  Fix placeholder rendering for button text

* 👕 Fix lint

* 🔥 Remove outdated comment

* 🐛 Pass in missing arg for placeholder

* ✏️ Fill out Slack translation

*  Add explanatory comment

* ✏️ Fill out dummy translation

* ✏️ Update documentation

* 🔥 Remove broken link

* ✏️ Add pending functionality

* ✏️ Fix indentation

* 🐛 Fix method call in CredentialEdit

*  Implement eventTriggerDescription

* 🐛 Fix table-json-binary radio buttons

* ✏️ Clarify usage of eventTriggerDescription

* 🔥 Remove unneeded arg

* 🐛 Fix display in CodeEdit and TextEdit

* 🔥 Remove logging

* ✏️ Add translation for test cred options

* ✏️ Add test for separate file in same dir

* ✏️ Add test for versioned node

* ✏️ Add test for node in grouped dir

* ✏️ Add minor clarifications

* ✏️ Add nested collection test

* ✏️ Add pending functionality

*  Generalize collections handling

* 🚚 Rename helper to remove redundancy

* 🚚 Improve naming in helpers

* ✏️ Improve helpers documentation

* ✏️ Improve i18n methods documentation

* 🚚 Make endpoint naming consistent

* ✏️ Add final newlines

* ✏️ Clean up JSON examples

*  Reuse i18n method

*  Improve utils readability

*  Return early if cred translation exists

* 🔥 Remove dummy translations
This commit is contained in:
Iván Ovejero
2022-01-07 22:02:21 +01:00
committed by GitHub
parent 6a2db6d107
commit 5fec563c5c
30 changed files with 920 additions and 634 deletions

View File

@@ -16,7 +16,7 @@ function copyIcons() {
task('build:translations', writeHeaders);
/**
* Write all node translation headers at `/dist/nodes/headers.js`.
* Write node translation headers to single file at `/dist/nodes/headers.js`.
*/
function writeHeaders(done) {
const { N8N_DEFAULT_LOCALE: locale } = process.env;
@@ -26,65 +26,48 @@ function writeHeaders(done) {
if (!locale || locale === 'en') {
log('No translation required - Skipping translations build...');
return done();
};
}
const paths = getTranslationPaths();
const headers = getHeaders(paths);
const nodeTranslationPaths = getNodeTranslationPaths();
const headers = getHeaders(nodeTranslationPaths);
const headersDistPath = path.join(__dirname, 'dist', 'nodes', 'headers.js');
const headersDestinationPath = path.join(__dirname, 'dist', 'nodes', 'headers.js');
writeDistFile(headers, headersDistPath);
writeDestinationFile(headersDestinationPath, headers);
log('Headers translation file written to:');
log(headersDestinationPath, { bulletpoint: true });
log('Headers file written to:');
log(headersDistPath, { bulletpoint: true });
done();
}
function getTranslationPaths() {
const destinationPaths = require('./package.json').n8n.nodes;
function getNodeTranslationPaths() {
const nodeDistPaths = require('./package.json').n8n.nodes;
const { N8N_DEFAULT_LOCALE: locale } = process.env;
const seen = {};
return destinationPaths.reduce((acc, cur) => {
const sourcePath = path.join(
return nodeDistPaths.reduce((acc, cur) => {
const nodeTranslationPath = path.join(
__dirname,
cur.split('/').slice(1, -1).join('/'),
'translations',
`${locale}.json`,
locale,
toTranslationFile(cur),
);
if (existsSync(sourcePath) && !seen[sourcePath]) {
seen[sourcePath] = true;
const destinationPath = path.join(
__dirname,
cur.split('/').slice(0, -1).join('/'),
'translations',
`${locale}.json`,
);
acc.push({
source: sourcePath,
destination: destinationPath,
});
if (existsSync(nodeTranslationPath)) {
acc.push(nodeTranslationPath);
};
return acc;
}, []);
}
function getHeaders(paths) {
return paths.reduce((acc, cur) => {
const translation = require(cur.source);
const nodeTypes = Object.keys(translation);
function getHeaders(nodeTranslationPaths) {
return nodeTranslationPaths.reduce((acc, cur) => {
const { header } = require(cur);
const nodeType = cur.split('/').pop().replace('.json', '');
for (const nodeType of nodeTypes) {
const { header } = translation[nodeType];
if (isValidHeader(header, ALLOWED_HEADER_KEYS)) {
acc[nodeType] = header;
}
if (isValidHeader(header, ALLOWED_HEADER_KEYS)) {
acc[nodeType] = header;
}
return acc;
@@ -96,6 +79,11 @@ function getHeaders(paths) {
// helpers
// ----------------------------------
function toTranslationFile(distPath) {
const raw = distPath.split('/').pop().replace('.node', '') + 'on';
return raw.charAt(0).toLowerCase() + raw.slice(1);
}
function isValidHeader(header, allowedHeaderKeys) {
if (!header) return false;
@@ -105,9 +93,9 @@ function isValidHeader(header, allowedHeaderKeys) {
headerKeys.every(key => allowedHeaderKeys.includes(key));
}
function writeDestinationFile(destinationPath, data) {
function writeDistFile(data, distPath) {
writeFile(
destinationPath,
distPath,
`module.exports = ${JSON.stringify(data, null, 2)}`,
);
}