From 1a642ba5426c64bc5ed3b8ed39f0a655ed948103 Mon Sep 17 00:00:00 2001 From: "Nicholas Carrigan (he/him)" Date: Wed, 3 Feb 2021 00:03:52 -0800 Subject: [PATCH] feat(i18n, client): migrate meta translations (#40885) --- client/i18n/config.js | 5 +-- client/i18n/locales.test.js | 3 ++ client/i18n/locales/chinese/meta-tags.json | 27 ++++++++++++++++ client/i18n/locales/chinese/translations.json | 27 ---------------- client/i18n/locales/english/meta-tags.json | 29 +++++++++++++++++ client/i18n/locales/english/translations.json | 29 ----------------- client/i18n/locales/espanol/meta-tags.json | 29 +++++++++++++++++ client/i18n/locales/espanol/translations.json | 29 ----------------- client/i18n/meta-tags-schema.js | 31 +++++++++++++++++++ client/i18n/schema-validation.js | 30 ++++++++++++++++++ client/i18n/translations-schema.js | 29 ----------------- .../client-only-routes/ShowUnsubscribed.js | 2 +- client/src/components/landing/index.js | 2 +- client/src/components/layouts/Default.js | 4 +-- client/src/pages/learn.js | 2 +- client/utils/tags.js | 4 +-- 16 files changed, 159 insertions(+), 123 deletions(-) create mode 100644 client/i18n/locales/chinese/meta-tags.json create mode 100644 client/i18n/locales/english/meta-tags.json create mode 100644 client/i18n/locales/espanol/meta-tags.json create mode 100644 client/i18n/meta-tags-schema.js diff --git a/client/i18n/config.js b/client/i18n/config.js index ede88b4af0..9684b6deb9 100644 --- a/client/i18n/config.js +++ b/client/i18n/config.js @@ -14,10 +14,11 @@ i18n.use(initReactI18next).init({ [i18nextCode]: { translations: require(`./locales/${clientLocale}/translations.json`), trending: require(`./locales/${clientLocale}/trending.json`), - intro: require(`./locales/${clientLocale}/intro.json`) + intro: require(`./locales/${clientLocale}/intro.json`), + metaTags: require(`./locales/${clientLocale}/meta-tags.json`) } }, - ns: ['translations', 'trending', 'intro'], + ns: ['translations', 'trending', 'intro', 'metaTags'], defaultNS: 'translations', returnObjects: true, // Uncomment the next line for debug logging diff --git a/client/i18n/locales.test.js b/client/i18n/locales.test.js index 0e0d726fa5..88cf15046d 100644 --- a/client/i18n/locales.test.js +++ b/client/i18n/locales.test.js @@ -23,6 +23,9 @@ const filesThatShouldExist = [ }, { name: 'intro.json' + }, + { + name: 'meta-tags.json' } ]; diff --git a/client/i18n/locales/chinese/meta-tags.json b/client/i18n/locales/chinese/meta-tags.json new file mode 100644 index 0000000000..3704d10111 --- /dev/null +++ b/client/i18n/locales/chinese/meta-tags.json @@ -0,0 +1,27 @@ +{ + "title": "免费学习编程 – 适合忙碌人士的编程课程", + "description": "在家学习编程,构建项目,获得认证。自 2014 年以来,已有超过 40,000 名 freeCodeCamp 学员入职谷歌、苹果、亚马逊、微软等科技公司。", + "social-description": "Learn to Code — For Free", + "keywords": [ + "javascript", + "js", + "网站", + "web", + "开发", + "free", + "code", + "camp", + "课程", + "html", + "css", + "react", + "redux", + "api", + "前端", + "后端", + "学习", + "教程", + "编程" + ], + "youre-unsubscribed": "你已取消订阅" +} diff --git a/client/i18n/locales/chinese/translations.json b/client/i18n/locales/chinese/translations.json index 082a3af833..5d95ea600c 100644 --- a/client/i18n/locales/chinese/translations.json +++ b/client/i18n/locales/chinese/translations.json @@ -1,31 +1,4 @@ { - "meta": { - "title": "免费学习编程 – 适合忙碌人士的编程课程", - "description": "在家学习编程,构建项目,获得认证。自 2014 年以来,已有超过 40,000 名 freeCodeCamp 学员入职谷歌、苹果、亚马逊、微软等科技公司。", - "social-description": "Learn to Code — For Free", - "keywords": [ - "javascript", - "js", - "网站", - "web", - "开发", - "free", - "code", - "camp", - "课程", - "html", - "css", - "react", - "redux", - "api", - "前端", - "后端", - "学习", - "教程", - "编程" - ], - "youre-unsubscribed": "你已取消订阅" - }, "buttons": { "logged-in-cta-btn": "开始学习(免费)", "logged-out-cta-btn": "登录以保存你的学习进度(免费)", diff --git a/client/i18n/locales/english/meta-tags.json b/client/i18n/locales/english/meta-tags.json new file mode 100644 index 0000000000..239cb89d9c --- /dev/null +++ b/client/i18n/locales/english/meta-tags.json @@ -0,0 +1,29 @@ +{ + "title": "Learn to Code — For Free — Coding Courses for Busy People", + "description": "Learn to Code — For Free", + "social-description": "Learn to Code — For Free", + "keywords": [ + "javascript", + "js", + "website", + "web", + "development", + "free", + "code", + "camp", + "course", + "courses", + "html", + "css", + "react", + "redux", + "api", + "front", + "back", + "end", + "learn", + "tutorial", + "programming" + ], + "youre-unsubscribed": "You have been unsubscribed" +} diff --git a/client/i18n/locales/english/translations.json b/client/i18n/locales/english/translations.json index 4351bde18c..f51dfd150d 100644 --- a/client/i18n/locales/english/translations.json +++ b/client/i18n/locales/english/translations.json @@ -1,33 +1,4 @@ { - "meta": { - "title": "Learn to Code — For Free — Coding Courses for Busy People", - "description": "Learn to Code — For Free", - "social-description": "Learn to Code — For Free", - "keywords": [ - "javascript", - "js", - "website", - "web", - "development", - "free", - "code", - "camp", - "course", - "courses", - "html", - "css", - "react", - "redux", - "api", - "front", - "back", - "end", - "learn", - "tutorial", - "programming" - ], - "youre-unsubscribed": "You have been unsubscribed" - }, "buttons": { "logged-in-cta-btn": "Get started (it's free)", "logged-out-cta-btn": "Sign in to save your progress (it's free)", diff --git a/client/i18n/locales/espanol/meta-tags.json b/client/i18n/locales/espanol/meta-tags.json new file mode 100644 index 0000000000..684efdac44 --- /dev/null +++ b/client/i18n/locales/espanol/meta-tags.json @@ -0,0 +1,29 @@ +{ + "title": "Aprende a codificar gratis: cursos de programación para personas ocupadas", + "description": "Aprende a codificar en casa. Construye proyectos. Obtén certificaciones. Desde el 2014, más de 40,000 graduados de freeCodeCamp.org han conseguido trabajos en empresas de tecnología como Google, Apple, Amazon y Microsoft.", + "social-description": "Learn to Code — For Free", + "keywords": [ + "javascript", + "js", + "sitio web", + "web", + "desarrollo", + "gratis", + "código", + "camp", + "curso", + "cursos", + "html", + "css", + "react", + "redux", + "api", + "front", + "back", + "end", + "aprende", + "tutorial", + "programación" + ], + "youre-unsubscribed": "Tu suscripción ha sido cancelada" +} diff --git a/client/i18n/locales/espanol/translations.json b/client/i18n/locales/espanol/translations.json index b5a55f50bf..ff32dfa1e7 100644 --- a/client/i18n/locales/espanol/translations.json +++ b/client/i18n/locales/espanol/translations.json @@ -1,33 +1,4 @@ { - "meta": { - "title": "Aprende a codificar gratis: cursos de programación para personas ocupadas", - "description": "Aprende a codificar en casa. Construye proyectos. Obtén certificaciones. Desde el 2014, más de 40,000 graduados de freeCodeCamp.org han conseguido trabajos en empresas de tecnología como Google, Apple, Amazon y Microsoft.", - "social-description": "Learn to Code — For Free", - "keywords": [ - "javascript", - "js", - "sitio web", - "web", - "desarrollo", - "gratis", - "código", - "camp", - "curso", - "cursos", - "html", - "css", - "react", - "redux", - "api", - "front", - "back", - "end", - "aprende", - "tutorial", - "programación" - ], - "youre-unsubscribed": "Tu suscripción ha sido cancelada" - }, "buttons": { "logged-in-cta-btn": "Empieza es gratis", "logged-out-cta-btn": "Inicia sesión para guardar tu progreso (es gratis)", diff --git a/client/i18n/meta-tags-schema.js b/client/i18n/meta-tags-schema.js new file mode 100644 index 0000000000..9751f11157 --- /dev/null +++ b/client/i18n/meta-tags-schema.js @@ -0,0 +1,31 @@ +const metaTagsSchema = { + title: 'Learn to Code — For Free — Coding Courses for Busy People', + description: 'Learn to Code — For Free', + 'social-description': 'Learn to Code — For Free', + keywords: [ + 'javascript', + 'js', + 'website', + 'web', + 'development', + 'free', + 'code', + 'camp', + 'course', + 'courses', + 'html', + 'css', + 'react', + 'redux', + 'api', + 'front', + 'back', + 'end', + 'learn', + 'tutorial', + 'programming' + ], + 'youre-unsubscribed': 'You have been unsubscribed' +}; + +exports.metaTagsSchema = metaTagsSchema; diff --git a/client/i18n/schema-validation.js b/client/i18n/schema-validation.js index c711571d78..22e1e7b251 100644 --- a/client/i18n/schema-validation.js +++ b/client/i18n/schema-validation.js @@ -5,6 +5,7 @@ const { availableLangs } = require('./allLangs'); const { trendingSchema } = require('./trending-schema'); const { motivationSchema } = require('./motivation-schema'); const { introSchema } = require('./intro-schema'); +const { metaTagsSchema } = require('./meta-tags-schema'); /** * Flattens a nested object structure into a single @@ -105,6 +106,7 @@ const translationSchemaKeys = Object.keys(flattenAnObject(translationsSchema)); const trendingSchemaKeys = Object.keys(flattenAnObject(trendingSchema)); const motivationSchemaKeys = Object.keys(flattenAnObject(motivationSchema)); const introSchemaKeys = Object.keys(flattenAnObject(introSchema)); +const metaTagsSchemaKeys = Object.keys(flattenAnObject(metaTagsSchema)); /** * Function that checks the translations.json file @@ -236,7 +238,35 @@ const introSchemaValidation = languages => { }); }; +const metaTagsSchemaValidation = languages => { + languages.forEach(language => { + const filePath = path.join( + __dirname, + `/locales/${language}/meta-tags.json` + ); + const fileData = fs.readFileSync(filePath); + const fileJson = JSON.parse(fileData); + const fileKeys = Object.keys(flattenAnObject(fileJson)); + findMissingKeys(fileKeys, metaTagsSchemaKeys, `${language}/meta-tags.json`); + findExtraneousKeys( + fileKeys, + metaTagsSchemaKeys, + `${language}/metaTags.json` + ); + const emptyKeys = noEmptyObjectValues(fileJson); + if (emptyKeys.length) { + throw new Error( + `${language}/metaTags.json has these empty keys: ${emptyKeys.join( + ', ' + )}` + ); + } + console.info(`${language} metaTags.json is correct!`); + }); +}; + translationSchemaValidation(availableLangs.client); trendingSchemaValidation(availableLangs.client); motivationSchemaValidation(availableLangs.client); introSchemaValidation(availableLangs.client); +metaTagsSchemaValidation(availableLangs.client); diff --git a/client/i18n/translations-schema.js b/client/i18n/translations-schema.js index f71c00d04f..7530734244 100644 --- a/client/i18n/translations-schema.js +++ b/client/i18n/translations-schema.js @@ -3,35 +3,6 @@ * structure here exactly, the tests will fail. */ const translationsSchema = { - meta: { - title: 'Learn to Code — For Free — Coding Courses for Busy People', - description: 'Learn to Code — For Free', - 'social-description': 'Learn to Code — For Free', - keywords: [ - 'javascript', - 'js', - 'website', - 'web', - 'development', - 'free', - 'code', - 'camp', - 'course', - 'courses', - 'html', - 'css', - 'react', - 'redux', - 'api', - 'front', - 'back', - 'end', - 'learn', - 'tutorial', - 'programming' - ], - 'youre-unsubscribed': 'You have been unsubscribed' - }, buttons: { 'logged-in-cta-btn': "Get started (it's free)", 'logged-out-cta-btn': "Sign in to save your progress (it's free)", diff --git a/client/src/client-only-routes/ShowUnsubscribed.js b/client/src/client-only-routes/ShowUnsubscribed.js index 17b0d29d53..e3827dd5de 100644 --- a/client/src/client-only-routes/ShowUnsubscribed.js +++ b/client/src/client-only-routes/ShowUnsubscribed.js @@ -15,7 +15,7 @@ function ShowUnsubscribed({ unsubscribeId }) { return ( - {t('meta.youre-unsubscribed')} | freeCodeCamp.org + {t('metaTags:youre-unsubscribed')} | freeCodeCamp.org
diff --git a/client/src/components/landing/index.js b/client/src/components/landing/index.js index 46aafd4ec5..20d44e90d7 100644 --- a/client/src/components/landing/index.js +++ b/client/src/components/landing/index.js @@ -21,7 +21,7 @@ export const Landing = ({ page = 'landing' }) => { return ( - {t('meta.title')} + {t('metaTags:title')}
diff --git a/client/src/components/layouts/Default.js b/client/src/components/layouts/Default.js index f92c3858a4..e0d8c1ab6c 100644 --- a/client/src/components/layouts/Default.js +++ b/client/src/components/layouts/Default.js @@ -152,9 +152,9 @@ class DefaultLayout extends Component { meta={[ { name: 'description', - content: t('meta.description') + content: t('metaTags:description') }, - { name: 'keywords', content: t('meta.keywords') } + { name: 'keywords', content: t('metaTags:keywords') } ]} > - + diff --git a/client/utils/tags.js b/client/utils/tags.js index 548705521c..d40c2212be 100644 --- a/client/utils/tags.js +++ b/client/utils/tags.js @@ -16,7 +16,7 @@ export const getheadTagComponents = () => { , , , @@ -37,7 +37,7 @@ export const getheadTagComponents = () => { name='twitter:title' />, ,