From b393d88b9e6b96cb0977d4b85ce3fcac549e1e2a Mon Sep 17 00:00:00 2001 From: Mrugesh Mohapatra <1884376+raisedadead@users.noreply.github.com> Date: Wed, 26 Oct 2022 22:38:27 +0530 Subject: [PATCH] refactor: s/all-langs/i18n/g (#48258) --- .eslintignore | 2 +- .gitignore | 2 +- .prettierignore | 2 +- api-server/src/server/component-passport.js | 2 +- api-server/src/server/utils/redirection.js | 2 +- client/i18n/config.js | 2 +- client/i18n/locales.test.ts | 6 +----- client/i18n/schema-validation.ts | 2 +- client/src/client-only-routes/show-certification.tsx | 2 +- client/src/components/Header/components/nav-links.tsx | 2 +- client/src/components/app-mount-notifier.test.tsx | 2 +- client/src/components/profile/components/camper.tsx | 2 +- client/src/components/profile/components/heat-map.tsx | 2 +- client/src/components/profile/components/time-line.tsx | 2 +- config/{i18n/all-langs.ts => i18n.ts} | 2 +- curriculum/getChallenges.js | 2 +- curriculum/utils.js | 2 +- curriculum/utils.test.ts | 2 +- cypress/e2e/default/learn/header/universal-navigation.js | 2 +- tools/challenge-auditor/index.ts | 2 +- tools/scripts/build/ensure-env.ts | 6 +++--- utils/is-audited.js | 2 +- 22 files changed, 24 insertions(+), 28 deletions(-) rename config/{i18n/all-langs.ts => i18n.ts} (99%) diff --git a/.eslintignore b/.eslintignore index 8a0feccda32..55ab6121244 100644 --- a/.eslintignore +++ b/.eslintignore @@ -3,6 +3,6 @@ client/static/** client/public/** api-server/src/public/** api-server/lib/** -config/i18n/all-langs.js +config/i18n.js config/certification-settings.js web/** diff --git a/.gitignore b/.gitignore index 727d4af32ac..bc796f46f03 100644 --- a/.gitignore +++ b/.gitignore @@ -162,7 +162,7 @@ config/client/sass-compile.json config/client/frame-runner.json config/client/test-evaluator.json config/curriculum.json -config/i18n/all-langs.js +config/i18n.js config/certification-settings.js ### Generated utils files ### diff --git a/.prettierignore b/.prettierignore index 9c47bebba6e..c2f88809e28 100644 --- a/.prettierignore +++ b/.prettierignore @@ -5,7 +5,7 @@ client/static curriculum/challenges/_meta/*/* curriculum/challenges/**/* config/**/*.json -config/i18n/all-langs.js +config/i18n.js config/certification-settings.js docs/i18n utils/block-nameify.js diff --git a/api-server/src/server/component-passport.js b/api-server/src/server/component-passport.js index 2ef67379986..71779f2092a 100644 --- a/api-server/src/server/component-passport.js +++ b/api-server/src/server/component-passport.js @@ -2,7 +2,7 @@ import { PassportConfigurator } from '@freecodecamp/loopback-component-passport' import dedent from 'dedent'; import passport from 'passport'; -import { availableLangs } from '../../../config/i18n/all-langs'; +import { availableLangs } from '../../../config/i18n'; import { jwtSecret } from '../../../config/secrets'; import passportProviders from './passport-providers'; import { setAccessTokenToResponse } from './utils/getSetAccessToken'; diff --git a/api-server/src/server/utils/redirection.js b/api-server/src/server/utils/redirection.js index 326d9c1c45b..dd21ad48a61 100644 --- a/api-server/src/server/utils/redirection.js +++ b/api-server/src/server/utils/redirection.js @@ -3,7 +3,7 @@ const { allowedOrigins } = require('../../../../config/cors-settings'); // homeLocation is being used as a fallback here. If the one provided by the // client is invalid we default to this. const { homeLocation } = require('../../../../config/env.json'); -const { availableLangs } = require('../../../../config/i18n/all-langs'); +const { availableLangs } = require('../../../../config/i18n'); function getReturnTo(encryptedParams, secret, _homeLocation = homeLocation) { let params; diff --git a/client/i18n/config.js b/client/i18n/config.js index 676e06215b8..6ff8c543192 100644 --- a/client/i18n/config.js +++ b/client/i18n/config.js @@ -4,7 +4,7 @@ import i18n from 'i18next'; import { initReactI18next } from 'react-i18next'; const envData = require('../../config/env.json'); -const { i18nextCodes } = require('../../config/i18n/all-langs'); +const { i18nextCodes } = require('../../config/i18n'); const { clientLocale } = envData; diff --git a/client/i18n/locales.test.ts b/client/i18n/locales.test.ts index d753efb3b83..8cc283b715f 100644 --- a/client/i18n/locales.test.ts +++ b/client/i18n/locales.test.ts @@ -1,10 +1,6 @@ import fs from 'fs'; import { setup } from 'jest-json-schema-extended'; -import { - availableLangs, - LangNames, - LangCodes -} from '../../config/i18n/all-langs'; +import { availableLangs, LangNames, LangCodes } from '../../config/i18n'; setup(); diff --git a/client/i18n/schema-validation.ts b/client/i18n/schema-validation.ts index c066cdc1fe0..65ff5eaedb0 100644 --- a/client/i18n/schema-validation.ts +++ b/client/i18n/schema-validation.ts @@ -1,6 +1,6 @@ import path from 'path'; import { readFile } from 'fs/promises'; -import { availableLangs } from '../../config/i18n/all-langs'; +import { availableLangs } from '../../config/i18n'; import introSchema from './locales/english/intro.json'; import linksSchema from './locales/english/links.json'; import metaTagsSchema from './locales/english/meta-tags.json'; diff --git a/client/src/client-only-routes/show-certification.tsx b/client/src/client-only-routes/show-certification.tsx index a46b0886c34..cac667f9e79 100644 --- a/client/src/client-only-routes/show-certification.tsx +++ b/client/src/client-only-routes/show-certification.tsx @@ -7,7 +7,7 @@ import { bindActionCreators, Dispatch } from 'redux'; import { createSelector } from 'reselect'; import envData from '../../../config/env.json'; -import { getLangCode } from '../../../config/i18n/all-langs'; +import { getLangCode } from '../../../config/i18n'; import FreeCodeCampLogo from '../assets/icons/FreeCodeCamp-logo'; import DonateForm from '../components/Donation/donate-form'; diff --git a/client/src/components/Header/components/nav-links.tsx b/client/src/components/Header/components/nav-links.tsx index a833918dc38..c7479afe9ca 100644 --- a/client/src/components/Header/components/nav-links.tsx +++ b/client/src/components/Header/components/nav-links.tsx @@ -17,7 +17,7 @@ import { LangNames, LangCodes, hiddenLangs -} from '../../../../../config/i18n/all-langs'; +} from '../../../../../config/i18n'; import { hardGoTo as navigate } from '../../../redux/actions'; import { updateMyTheme } from '../../../redux/settings/actions'; import createLanguageRedirect from '../../create-language-redirect'; diff --git a/client/src/components/app-mount-notifier.test.tsx b/client/src/components/app-mount-notifier.test.tsx index e3610a61ff5..78c83e1ba8b 100644 --- a/client/src/components/app-mount-notifier.test.tsx +++ b/client/src/components/app-mount-notifier.test.tsx @@ -3,7 +3,7 @@ import React from 'react'; import { I18nextProvider } from 'react-i18next'; import { Provider } from 'react-redux'; -import { i18nextCodes } from '../../../config/i18n/all-langs'; +import { i18nextCodes } from '../../../config/i18n'; import i18nTestConfig from '../../i18n/config-for-tests'; import { createStore } from '../redux/createStore'; import AppMountNotifier from './app-mount-notifier'; diff --git a/client/src/components/profile/components/camper.tsx b/client/src/components/profile/components/camper.tsx index f4c4688ec22..ce940eb5121 100644 --- a/client/src/components/profile/components/camper.tsx +++ b/client/src/components/profile/components/camper.tsx @@ -9,7 +9,7 @@ import React from 'react'; import { TFunction, useTranslation } from 'react-i18next'; import envData from '../../../../../config/env.json'; -import { getLangCode } from '../../../../../config/i18n/all-langs'; +import { getLangCode } from '../../../../../config/i18n'; import { AvatarRenderer } from '../../helpers'; import Link from '../../helpers/link'; import SocialIcons from './social-icons'; diff --git a/client/src/components/profile/components/heat-map.tsx b/client/src/components/profile/components/heat-map.tsx index 0fb0d851361..c088684e955 100644 --- a/client/src/components/profile/components/heat-map.tsx +++ b/client/src/components/profile/components/heat-map.tsx @@ -16,7 +16,7 @@ import './heatmap.css'; // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore import envData from '../../../../../config/env.json'; -import { getLangCode } from '../../../../../config/i18n/all-langs'; +import { getLangCode } from '../../../../../config/i18n'; import { User } from '../../../redux/prop-types'; import FullWidthRow from '../../helpers/full-width-row'; import Spacer from '../../helpers/spacer'; diff --git a/client/src/components/profile/components/time-line.tsx b/client/src/components/profile/components/time-line.tsx index 2a082a3cfa2..3efef9267cc 100644 --- a/client/src/components/profile/components/time-line.tsx +++ b/client/src/components/profile/components/time-line.tsx @@ -7,7 +7,7 @@ import { TFunction, withTranslation } from 'react-i18next'; import { connect } from 'react-redux'; import envData from '../../../../../config/env.json'; -import { getLangCode } from '../../../../../config/i18n/all-langs'; +import { getLangCode } from '../../../../../config/i18n'; import { getCertIds, getPathFromID, diff --git a/config/i18n/all-langs.ts b/config/i18n.ts similarity index 99% rename from config/i18n/all-langs.ts rename to config/i18n.ts index 544cb59497a..0d7daae0882 100644 --- a/config/i18n/all-langs.ts +++ b/config/i18n.ts @@ -1,5 +1,5 @@ // --------------------------------------------------------------------------- -import { SuperBlocks } from '../certification-settings'; +import { SuperBlocks } from './certification-settings'; /* * List of languages with localizations enabled for builds. * diff --git a/curriculum/getChallenges.js b/curriculum/getChallenges.js index c435f58f0d9..6782ed96839 100644 --- a/curriculum/getChallenges.js +++ b/curriculum/getChallenges.js @@ -8,7 +8,7 @@ const readDirP = require('readdirp'); const { helpCategoryMap } = require('../client/utils/challenge-types'); const { showUpcomingChanges } = require('../config/env.json'); const { curriculum: curriculumLangs } = - require('../config/i18n/all-langs').availableLangs; + require('../config/i18n').availableLangs; const { parseMD } = require('../tools/challenge-parser/parser'); /* eslint-disable max-len */ const { diff --git a/curriculum/utils.js b/curriculum/utils.js index be37ea8cdff..d06f9bb58c4 100644 --- a/curriculum/utils.js +++ b/curriculum/utils.js @@ -4,7 +4,7 @@ require('dotenv').config({ path: path.resolve(__dirname, '../.env') }); const { availableLangs, languagesWithAuditedBetaReleases -} = require('../config/i18n/all-langs'); +} = require('../config/i18n'); const curriculumLangs = availableLangs.curriculum; exports.testedLang = function testedLang() { diff --git a/curriculum/utils.test.ts b/curriculum/utils.test.ts index 1d5c3c2453d..b663a305c80 100644 --- a/curriculum/utils.test.ts +++ b/curriculum/utils.test.ts @@ -5,7 +5,7 @@ import fs from 'fs'; import path from 'path'; import { config } from 'dotenv'; import { SuperBlocks } from '../config/certification-settings'; -import { languagesWithAuditedBetaReleases } from '../config/i18n/all-langs'; +import { languagesWithAuditedBetaReleases } from '../config/i18n'; import { getSuperOrder, getSuperBlockFromDir } from './utils'; config({ path: path.resolve(__dirname, '../.env') }); diff --git a/cypress/e2e/default/learn/header/universal-navigation.js b/cypress/e2e/default/learn/header/universal-navigation.js index 5cac3f80327..c8b77df0b3d 100644 --- a/cypress/e2e/default/learn/header/universal-navigation.js +++ b/cypress/e2e/default/learn/header/universal-navigation.js @@ -2,7 +2,7 @@ import { availableLangs, hiddenLangs, LangNames -} from '../../../../../config/i18n/all-langs'; +} from '../../../../../config/i18n'; import envData from '../../../../../config/env.json'; const { clientLocale } = envData; diff --git a/tools/challenge-auditor/index.ts b/tools/challenge-auditor/index.ts index 08aaebb9d09..202a0146c6f 100644 --- a/tools/challenge-auditor/index.ts +++ b/tools/challenge-auditor/index.ts @@ -7,7 +7,7 @@ import { config } from 'dotenv'; const envPath = resolve(__dirname, '../../.env'); config({ path: envPath }); -import { availableLangs, auditedCerts } from '../../config/i18n/all-langs'; +import { availableLangs, auditedCerts } from '../../config/i18n'; import { getChallengesForLang } from '../../curriculum/getChallenges'; import { SuperBlocks } from '../../config/certification-settings'; import { ChallengeNode } from '../../client/src/redux/prop-types'; diff --git a/tools/scripts/build/ensure-env.ts b/tools/scripts/build/ensure-env.ts index 1f296823581..eac3cd37dc6 100644 --- a/tools/scripts/build/ensure-env.ts +++ b/tools/scripts/build/ensure-env.ts @@ -2,7 +2,7 @@ import { spawn } from 'child_process'; import * as fs from 'fs'; import * as path from 'path'; -import { availableLangs } from '../../../config/i18n/all-langs'; +import { availableLangs } from '../../../config/i18n'; import env from '../../../config/read-env'; const globalConfigPath = path.resolve(__dirname, '../../../config'); @@ -14,7 +14,7 @@ function checkClientLocale() { if (!availableLangs.client.includes(process.env.CLIENT_LOCALE)) { throw Error(` - CLIENT_LOCALE, ${process.env.CLIENT_LOCALE}, is not an available language in config/i18n/all-langs.ts + CLIENT_LOCALE, ${process.env.CLIENT_LOCALE}, is not an available language in config/i18n.ts `); } @@ -26,7 +26,7 @@ function checkCurriculumLocale() { if (!availableLangs.curriculum.includes(process.env.CURRICULUM_LOCALE)) { throw Error(` - CURRICULUM_LOCALE, ${process.env.CURRICULUM_LOCALE}, is not an available language in config/i18n/all-langs.ts + CURRICULUM_LOCALE, ${process.env.CURRICULUM_LOCALE}, is not an available language in config/i18n.ts `); } diff --git a/utils/is-audited.js b/utils/is-audited.js index 95d9d3b44a6..3bca0d21038 100644 --- a/utils/is-audited.js +++ b/utils/is-audited.js @@ -9,7 +9,7 @@ // translated, but when they are they can be included by adding 'certificates' // to the arrays below -const { auditedCerts } = require('../config/i18n/all-langs'); +const { auditedCerts } = require('../config/i18n'); function isAuditedCert(lang, cert) { if (!lang || !cert)