Skip to content

Fix i18n scripts + Add 4.19 translation files #2060

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
457 changes: 365 additions & 92 deletions locales/es/plugin__odf-console.json

Large diffs are not rendered by default.

451 changes: 362 additions & 89 deletions locales/fr/plugin__odf-console.json

Large diffs are not rendered by default.

495 changes: 384 additions & 111 deletions locales/ja/plugin__odf-console.json

Large diffs are not rendered by default.

453 changes: 363 additions & 90 deletions locales/ko/plugin__odf-console.json

Large diffs are not rendered by default.

461 changes: 367 additions & 94 deletions locales/zh/plugin__odf-console.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"format-test": "yarn prettier -c .",
"i18n": "i18next \"packages/**/*.{ts,tsx}\" [-oc] -c i18next-parser.config.js",
"i18n-test": "yarn i18n --fail-on-update",
"i18n-to-po": "node ./scripts/i18n/i18n-to-po.js",
"i18n-to-po": "node ./scripts/i18n/i18n-to-po.mjs",
"lint": "yarn lint-ts && yarn lint-css",
"lint-css": "yarn stylelint packages/**/**/*.scss",
"lint-css-fix": "yarn stylelint packages/**/**/*.scss --fix",
Expand All @@ -46,7 +46,7 @@
"memsource-download": "./scripts/i18n/memsource-download.sh",
"memsource-upload": "./scripts/i18n/memsource-upload.sh",
"ocp-console": "./scripts/start-ocp-console.sh",
"po-to-i18n": "node ./scripts/i18n/po-to-i18n.js",
"po-to-i18n": "node ./scripts/i18n/po-to-i18n.mjs",
"prepare": "husky",
"serve-local-build": "./http-server.sh ./plugins/odf/dist",
"serve-local-build-mco": "./http-server.sh ./plugins/mco/dist",
Expand Down Expand Up @@ -76,8 +76,8 @@
"eslint-plugin-import/tsconfig-paths/json5": "^1.0.2",
"loader-utils": "^2.0.4",
"micromatch": "^4.0.8",
"minimist": "^1.2.8",
"minimatch": "^3.0.5",
"minimist": "^1.2.8",
"nanoid": "^3.3.8",
"postcss": "^8.4.49",
"tough-cookie": "^4.1.3",
Expand Down
2 changes: 1 addition & 1 deletion scripts/i18n/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This i18n directory contains all the required scripts for i18n automation. Also,

4. Upload translations: you need to create a new project using your project's template. Each template will have its own unique id and an owner (example: for odf-console, name of our template is "OCP ODF UI" and id is "193065").
Run `yarn memsource-upload -v <VERSION> -s <SPRINT>`.
This script will create a new project for you and will call `export-pos.sh` and `i18n-to-po.js` which will export all i18next `.json` files in `.po` format in all the languages we currently support, and will upload these `.po` files under newly created project on Memsource.
This script will create a new project for you and will call `export-pos.sh` and `i18n-to-po.mjs` which will export all i18next `.json` files in `.po` format in all the languages we currently support, and will upload these `.po` files under newly created project on Memsource.

5. Download translations: for downloading we download all files in `.po` format and then convert into `.json`.
Run `yarn memsource-download -p <PROJECT_ID>` (example: from the Memsource project URL "https://cloud.memsource.com/web/project2/show/FBfZeTEWPYaC4VXhgrW0R2" the series of numbers and letters after /show/).
Expand Down
19 changes: 0 additions & 19 deletions scripts/i18n/common.js

This file was deleted.

18 changes: 18 additions & 0 deletions scripts/i18n/common.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import fs from 'fs';
import path from 'path';

export function deleteFile(filePath) {
try {
fs.unlinkSync(filePath);
} catch (e) {
console.error(`Failed to delete file ${filePath}:`, e);
}
}

export function deleteDir(dirPath) {
try {
fs.rmSync(dirPath, { recursive: true, force: true });
} catch (e) {
console.error(`Failed to delete directory ${dirPath}:`, e);
}
}
57 changes: 38 additions & 19 deletions scripts/i18n/i18n-to-po.js → scripts/i18n/i18n-to-po.mjs
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
const fs = require('fs');
const path = require('path');
const { i18nextToPo } = require('i18next-conv');
const minimist = require('minimist');
const common = require('./common.js');
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
import { i18nextToPo } from 'i18next-conv';
import minimist from 'minimist';
import * as common from './common.mjs';

// __dirname is not defined by default in ES module scope
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

function save(target) {
return (result) => {
fs.writeFileSync(target, result);
};
}

function removeValues(i18nFile, filePath) {
const file = require(i18nFile);
async function removeValues(i18nFile, filePath) {
const file = await import(i18nFile, { assert: { type: 'json' } }).then(
(m) => m.default
);

const updatedFile = {};

Expand All @@ -26,14 +33,26 @@ function removeValues(i18nFile, filePath) {
fs.writeFileSync(tmpFile, JSON.stringify(updatedFile, null, 2));
}

function consolidateWithExistingTranslations(filePath, fileName, language) {
const englishFile = require(filePath);
async function consolidateWithExistingTranslations(
filePath,
fileName,
language
) {
const englishFile = await import(filePath, { assert: { type: 'json' } }).then(
(m) => m.default
);
const englishKeys = Object.keys(englishFile);
let existingTranslationsPath = `../../locales/${language}/${fileName}.json`;
if (fs.existsSync(path.join(__dirname, existingTranslationsPath))) {
const existingTranslationsFile = require(
path.join(__dirname, existingTranslationsPath)
);
const existingTranslationsPath = `../../locales/${language}/${fileName}.json`;
const existingTranslationsFullPath = path.join(
__dirname,
existingTranslationsPath
);

if (fs.existsSync(existingTranslationsFullPath)) {
const existingTranslationsFile = await import(
existingTranslationsFullPath,
{ assert: { type: 'json' } }
).then((m) => m.default);
const existingKeys = Object.keys(existingTranslationsFile);
const matchingKeys = englishKeys.filter(
(k) => existingKeys.indexOf(k) > -1
Expand All @@ -47,7 +66,7 @@ function consolidateWithExistingTranslations(filePath, fileName, language) {
}
}

function processFile(fileName, language) {
async function processFile(fileName, language) {
let tmpFile;
let dirPath;
const i18nFile = path.join(__dirname, `../../locales/en/${fileName}.json`);
Expand All @@ -62,8 +81,8 @@ function processFile(fileName, language) {

tmpFile = path.join(__dirname, `../../locales/tmp/${fileName}.json`);

removeValues(i18nFile, tmpFile);
consolidateWithExistingTranslations(tmpFile, fileName, language);
await removeValues(i18nFile, tmpFile);
await consolidateWithExistingTranslations(tmpFile, fileName, language);

fs.mkdirSync(path.join(__dirname, `../../po-files/${language}`), {
recursive: true,
Expand Down Expand Up @@ -116,9 +135,9 @@ if (args.help) {
} else if (args.files && args.language) {
if (Array.isArray(args.files)) {
for (let i = 0; i < args.files.length; i++) {
processFile(args.files[i], args.language);
await processFile(args.files[i], args.language);
}
} else {
processFile(args.files, args.language);
await processFile(args.files, args.language);
}
}
13 changes: 9 additions & 4 deletions scripts/i18n/po-to-i18n.js → scripts/i18n/po-to-i18n.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
const fs = require('fs');
const path = require('path');
const { gettextToI18next } = require('i18next-conv');
const minimist = require('minimist');
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
import { gettextToI18next } from 'i18next-conv';
import minimist from 'minimist';

// __dirname is not defined by default in ES module scope
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

function save(target) {
return (result) => {
Expand Down