From 5cb3465a1dad9c5b7fad9c1683c322a04b5680be Mon Sep 17 00:00:00 2001 From: Mrugesh Mohapatra <1884376+raisedadead@users.noreply.github.com> Date: Thu, 6 May 2021 20:35:27 +0530 Subject: [PATCH] fix(i18n): ensure language redirects for Chinese traditional (#42020) --- .../src/components/createExternalRedirects.js | 7 +- .../createExternalRedirects.test.js | 51 +++++++++---- .../components/createLanguageRedirect.test.js | 76 ++++++++++++++----- 3 files changed, 98 insertions(+), 36 deletions(-) diff --git a/client/src/components/createExternalRedirects.js b/client/src/components/createExternalRedirects.js index 27ccfce994..2300dfb6c6 100644 --- a/client/src/components/createExternalRedirects.js +++ b/client/src/components/createExternalRedirects.js @@ -3,10 +3,13 @@ import envData from '../../../config/env.json'; const { forumLocation } = envData; const createExternalRedirect = (page, { clientLocale }) => { - const isNotEnglish = clientLocale !== 'english'; - if (clientLocale === 'chinese') { + // Handle Chinese + if (clientLocale === 'chinese' || clientLocale === 'chinese-traditional') { return `https://chinese.freecodecamp.org/${page}`; } + + // Handle Others + const isNotEnglish = clientLocale !== 'english'; if (page === 'forum') { return `${forumLocation}/${isNotEnglish ? 'c/' + clientLocale + '/' : ''}`; } diff --git a/client/src/components/createExternalRedirects.test.js b/client/src/components/createExternalRedirects.test.js index 4b966e985d..e3a00abc1a 100644 --- a/client/src/components/createExternalRedirects.test.js +++ b/client/src/components/createExternalRedirects.test.js @@ -8,17 +8,17 @@ describe('createExternalRedirects', () => { clientLocale: 'english' }; - const englishForumUrl = 'https://forum.freecodecamp.org/'; - const englishNewsUrl = 'https://www.freecodecamp.org/news'; + const forumURL = 'https://forum.freecodecamp.org/'; + const newsURL = 'https://www.freecodecamp.org/news'; it('should generate correct forum link', () => { const receivedUrl = createExternalRedirect('forum', { ...envVars }); - expect(receivedUrl).toBe(englishForumUrl); + expect(receivedUrl).toBe(forumURL); }); it('should generate correct news link', () => { const receivedUrl = createExternalRedirect('news', { ...envVars }); - expect(receivedUrl).toBe(englishNewsUrl); + expect(receivedUrl).toBe(newsURL); }); }); @@ -27,17 +27,17 @@ describe('createExternalRedirects', () => { clientLocale: 'chinese' }; - const englishForumUrl = 'https://chinese.freecodecamp.org/forum'; - const englishNewsUrl = 'https://chinese.freecodecamp.org/news'; + const forumURL = 'https://chinese.freecodecamp.org/forum'; + const newsURL = 'https://chinese.freecodecamp.org/news'; it('should generate correct forum link', () => { const receivedUrl = createExternalRedirect('forum', { ...envVars }); - expect(receivedUrl).toBe(englishForumUrl); + expect(receivedUrl).toBe(forumURL); }); it('should generate correct news link', () => { const receivedUrl = createExternalRedirect('news', { ...envVars }); - expect(receivedUrl).toBe(englishNewsUrl); + expect(receivedUrl).toBe(newsURL); }); }); @@ -46,17 +46,17 @@ describe('createExternalRedirects', () => { clientLocale: 'espanol' }; - const englishForumUrl = 'https://forum.freecodecamp.org/c/espanol/'; - const englishNewsUrl = 'https://www.freecodecamp.org/espanol/news'; + const forumURL = 'https://forum.freecodecamp.org/c/espanol/'; + const newsURL = 'https://www.freecodecamp.org/espanol/news'; it('should generate correct forum link', () => { const receivedUrl = createExternalRedirect('forum', { ...envVars }); - expect(receivedUrl).toBe(englishForumUrl); + expect(receivedUrl).toBe(forumURL); }); it('should generate correct news link', () => { const receivedUrl = createExternalRedirect('news', { ...envVars }); - expect(receivedUrl).toBe(englishNewsUrl); + expect(receivedUrl).toBe(newsURL); }); }); @@ -65,17 +65,36 @@ describe('createExternalRedirects', () => { clientLocale: 'francais' }; - const englishForumUrl = 'https://forum.freecodecamp.org/c/francais/'; - const englishNewsUrl = 'https://www.freecodecamp.org/francais/news'; + const forumURL = 'https://forum.freecodecamp.org/c/francais/'; + const newsURL = 'https://www.freecodecamp.org/francais/news'; it('should generate correct forum link', () => { const receivedUrl = createExternalRedirect('forum', { ...envVars }); - expect(receivedUrl).toBe(englishForumUrl); + expect(receivedUrl).toBe(forumURL); }); it('should generate correct news link', () => { const receivedUrl = createExternalRedirect('news', { ...envVars }); - expect(receivedUrl).toBe(englishNewsUrl); + expect(receivedUrl).toBe(newsURL); + }); + }); + + describe('chinese-traditional redirects', () => { + const envVars = { + clientLocale: 'chinese-traditional' + }; + + const forumURL = 'https://chinese.freecodecamp.org/forum'; + const newsURL = 'https://chinese.freecodecamp.org/news'; + + it('should generate correct forum link', () => { + const receivedUrl = createExternalRedirect('forum', { ...envVars }); + expect(receivedUrl).toBe(forumURL); + }); + + it('should generate correct news link', () => { + const receivedUrl = createExternalRedirect('news', { ...envVars }); + expect(receivedUrl).toBe(newsURL); }); }); }); diff --git a/client/src/components/createLanguageRedirect.test.js b/client/src/components/createLanguageRedirect.test.js index 74347d7144..6033615b96 100644 --- a/client/src/components/createLanguageRedirect.test.js +++ b/client/src/components/createLanguageRedirect.test.js @@ -14,8 +14,10 @@ describe('createLanguageRedirect for clientLocale === english', () => { 'https://chinese.freecodecamp.org/learn/responsive-web-design/basic-html-and-html5/inform-with-the-paragraph-element'; const espanolPageURL = 'https://www.freecodecamp.org/espanol/learn/responsive-web-design/basic-html-and-html5/inform-with-the-paragraph-element'; - const francaisPageURL = - 'https://www.freecodecamp.org/francais/learn/responsive-web-design/basic-html-and-html5/inform-with-the-paragraph-element'; + const chineseTraditionalPageURL = + 'https://www.freecodecamp.org/chinese-traditional/learn/responsive-web-design/basic-html-and-html5/inform-with-the-paragraph-element'; + const dothrakiPageURL = + 'https://www.freecodecamp.org/dothraki/learn/responsive-web-design/basic-html-and-html5/inform-with-the-paragraph-element'; const originalLocation = window.location; @@ -52,12 +54,20 @@ describe('createLanguageRedirect for clientLocale === english', () => { expect(receivedPageURL).toBe(espanolPageURL); }); - it('should redirect to francais version of page', () => { + it('should redirect to chinese-traditional version of page', () => { const receivedPageURL = createLanguageRedirect({ ...envVars, - lang: 'francais' + lang: 'chinese-traditional' }); - expect(receivedPageURL).toBe(francaisPageURL); + expect(receivedPageURL).toBe(chineseTraditionalPageURL); + }); + + it('should redirect to dothraki version of page', () => { + const receivedPageURL = createLanguageRedirect({ + ...envVars, + lang: 'dothraki' + }); + expect(receivedPageURL).toBe(dothrakiPageURL); }); }); @@ -65,7 +75,9 @@ describe('createLanguageRedirect for clientLocale === english', () => { const currentPageURL = 'https://www.freecodecamp.org/settings'; const chinesePageURL = 'https://chinese.freecodecamp.org/settings'; const espanolPageURL = 'https://www.freecodecamp.org/espanol/settings'; - const francaisPageURL = 'https://www.freecodecamp.org/francais/settings'; + const chineseTraditionalPageURL = + 'https://www.freecodecamp.org/chinese-traditional/settings'; + const dothrakiPageURL = 'https://www.freecodecamp.org/dothraki/settings'; const originalLocation = window.location; @@ -102,12 +114,20 @@ describe('createLanguageRedirect for clientLocale === english', () => { expect(receivedPageURL).toBe(espanolPageURL); }); - it('should redirect to francais version of page', () => { + it('should redirect to chinese-traditional version of page', () => { const receivedPageURL = createLanguageRedirect({ ...envVars, - lang: 'francais' + lang: 'chinese-traditional' }); - expect(receivedPageURL).toBe(francaisPageURL); + expect(receivedPageURL).toBe(chineseTraditionalPageURL); + }); + + it('should redirect to dothraki version of page', () => { + const receivedPageURL = createLanguageRedirect({ + ...envVars, + lang: 'dothraki' + }); + expect(receivedPageURL).toBe(dothrakiPageURL); }); }); }); @@ -124,8 +144,10 @@ describe('createLanguageRedirect for clientLocale === chinese', () => { 'https://www.freecodecamp.org/learn/responsive-web-design/basic-html-and-html5/inform-with-the-paragraph-element'; const espanolPageURL = 'https://www.freecodecamp.org/espanol/learn/responsive-web-design/basic-html-and-html5/inform-with-the-paragraph-element'; - const francaisPageURL = - 'https://www.freecodecamp.org/francais/learn/responsive-web-design/basic-html-and-html5/inform-with-the-paragraph-element'; + const chineseTraditionalPageURL = + 'https://www.freecodecamp.org/chinese-traditional/learn/responsive-web-design/basic-html-and-html5/inform-with-the-paragraph-element'; + const dothrakiPageURL = + 'https://www.freecodecamp.org/dothraki/learn/responsive-web-design/basic-html-and-html5/inform-with-the-paragraph-element'; const originalLocation = window.location; @@ -162,12 +184,20 @@ describe('createLanguageRedirect for clientLocale === chinese', () => { expect(receivedPageURL).toBe(espanolPageURL); }); - it('should redirect to francais version of page', () => { + it('should redirect to chinese-traditional version of page', () => { const receivedPageURL = createLanguageRedirect({ ...envVars, - lang: 'francais' + lang: 'chinese-traditional' }); - expect(receivedPageURL).toBe(francaisPageURL); + expect(receivedPageURL).toBe(chineseTraditionalPageURL); + }); + + it('should redirect to dothraki version of page', () => { + const receivedPageURL = createLanguageRedirect({ + ...envVars, + lang: 'dothraki' + }); + expect(receivedPageURL).toBe(dothrakiPageURL); }); }); @@ -175,7 +205,9 @@ describe('createLanguageRedirect for clientLocale === chinese', () => { const currentPageURL = 'https://chinese.freecodecamp.org/settings'; const englishPageURL = 'https://www.freecodecamp.org/settings'; const espanolPageURL = 'https://www.freecodecamp.org/espanol/settings'; - const francaisPageURL = 'https://www.freecodecamp.org/francais/settings'; + const chineseTraditionalPageURL = + 'https://www.freecodecamp.org/chinese-traditional/settings'; + const dothrakiPageURL = 'https://www.freecodecamp.org/dothraki/settings'; const originalLocation = window.location; @@ -212,12 +244,20 @@ describe('createLanguageRedirect for clientLocale === chinese', () => { expect(receivedPageURL).toBe(espanolPageURL); }); - it('should redirect to francais version of page', () => { + it('should redirect to chinese-traditional version of page', () => { const receivedPageURL = createLanguageRedirect({ ...envVars, - lang: 'francais' + lang: 'chinese-traditional' }); - expect(receivedPageURL).toBe(francaisPageURL); + expect(receivedPageURL).toBe(chineseTraditionalPageURL); + }); + + it('should redirect to dothraki version of page', () => { + const receivedPageURL = createLanguageRedirect({ + ...envVars, + lang: 'dothraki' + }); + expect(receivedPageURL).toBe(dothrakiPageURL); }); }); });