Skip to content

Commit

Permalink
Add --useI18nRepoOnly=true
Browse files Browse the repository at this point in the history
  • Loading branch information
denysoblohin-okta committed Jul 9, 2024
1 parent bd398b9 commit 41ce2d7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
21 changes: 15 additions & 6 deletions packages/@okta/verify-translations/verify-translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { resolve } = require('path');
const fs = require('fs');
const properties = require('properties');

const { CI, I18N_REPO_PATH, WRITE_FIXED_I18N } = process.env;
const { CI, I18N_REPO_PATH, WRITE_FIXED_I18N, USE_I18N_REPO_ONLY } = process.env;
const ROOT_DIR = resolve(__dirname, '../../../');
const OKTA_I18N_PROPERTIES = `${ROOT_DIR}/packages/@okta/i18n/src/properties`;
const I18N_REPO = I18N_REPO_PATH ? I18N_REPO_PATH : resolve(ROOT_DIR, '../i18n');
Expand Down Expand Up @@ -64,6 +64,13 @@ const getCoreResourcesPath = () => {
throw new Error(`No i18n repo found at ${I18N_REPO}`);
};

const getSiwResourcesPath = () => {
if (USE_I18N_REPO_ONLY === 'true') {
return `${I18N_REPO}/packages/login`;
}
return OKTA_I18N_PROPERTIES;
};

const getLanguges = ({ resourcePath, bundle }) => {
const fileNames = fs.readdirSync(resourcePath).filter(fileName =>
fileName.startsWith(bundle) && fileName.endsWith('.properties')
Expand Down Expand Up @@ -124,9 +131,11 @@ const buildCompexityKeysMapping = (siwTranslations, coreTranslations) => {
const verifyTranslations = async ({ canUpdate }) => {
let res = 0;
const coreResourcesPath = getCoreResourcesPath();
console.log(`Using resource path: ${coreResourcesPath}`);
const siwResourcesPath = getSiwResourcesPath();
console.log(`Using core resource path: ${coreResourcesPath}`);
console.log(`Using widget resource path: ${siwResourcesPath}`);
const siwLangs = getLanguges({
resourcePath: OKTA_I18N_PROPERTIES,
resourcePath: siwResourcesPath,
bundle: 'login',
});
const coreLangs = getLanguges({
Expand All @@ -135,7 +144,7 @@ const verifyTranslations = async ({ canUpdate }) => {
});
for (let siwLang of siwLangs) {
const siwProperties = await parseProperties({
resourcePath: OKTA_I18N_PROPERTIES,
resourcePath: siwResourcesPath,
bundle: 'login',
lang: siwLang,
});
Expand Down Expand Up @@ -173,7 +182,7 @@ const verifyTranslations = async ({ canUpdate }) => {
console.log(updates);
if (canUpdate) {
updateProperties({
resourcePath: OKTA_I18N_PROPERTIES,
resourcePath: siwResourcesPath,
bundle: 'login',
lang: siwLang,
updates,
Expand All @@ -194,7 +203,7 @@ const verifyTranslations = async ({ canUpdate }) => {

const start = async () => {
const res = await verifyTranslations({
canUpdate: !CI && WRITE_FIXED_I18N === 'true'
canUpdate: !CI && WRITE_FIXED_I18N === 'true' && USE_I18N_REPO_ONLY !== 'true'
});
process.exit(res);
};
Expand Down
8 changes: 8 additions & 0 deletions scripts/buildtools/commands/verify-translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ exports.builder = {
type: 'boolean',
default: false,
},
useI18nRepoOnly: {
description: 'True to compare core and SIW translations in i18n repo only, ignoring translations in SIW repo',
type: 'boolean',
default: false,
}
};

exports.handler = async (argv) => {
Expand All @@ -31,6 +36,9 @@ exports.handler = async (argv) => {
if (argv.i18nRepoPath) {
verifyCmd = `I18N_REPO_PATH="${argv.i18nRepoPath}" ${verifyCmd}`;
}
if (argv.useI18nRepoOnly) {
verifyCmd = `USE_I18N_REPO_ONLY=true ${verifyCmd}`;
}
if (argv.write) {
verifyCmd = `WRITE_FIXED_I18N=true ${verifyCmd}`;
}
Expand Down

0 comments on commit 41ce2d7

Please sign in to comment.