fix(i18n): ensure language redirects for Chinese traditional (#42020)

This commit is contained in:
Mrugesh Mohapatra
2021-05-06 20:35:27 +05:30
committed by GitHub
parent 0b5553002a
commit 5cb3465a1d
3 changed files with 98 additions and 36 deletions

View File

@ -3,10 +3,13 @@ import envData from '../../../config/env.json';
const { forumLocation } = envData; const { forumLocation } = envData;
const createExternalRedirect = (page, { clientLocale }) => { const createExternalRedirect = (page, { clientLocale }) => {
const isNotEnglish = clientLocale !== 'english'; // Handle Chinese
if (clientLocale === 'chinese') { if (clientLocale === 'chinese' || clientLocale === 'chinese-traditional') {
return `https://chinese.freecodecamp.org/${page}`; return `https://chinese.freecodecamp.org/${page}`;
} }
// Handle Others
const isNotEnglish = clientLocale !== 'english';
if (page === 'forum') { if (page === 'forum') {
return `${forumLocation}/${isNotEnglish ? 'c/' + clientLocale + '/' : ''}`; return `${forumLocation}/${isNotEnglish ? 'c/' + clientLocale + '/' : ''}`;
} }

View File

@ -8,17 +8,17 @@ describe('createExternalRedirects', () => {
clientLocale: 'english' clientLocale: 'english'
}; };
const englishForumUrl = 'https://forum.freecodecamp.org/'; const forumURL = 'https://forum.freecodecamp.org/';
const englishNewsUrl = 'https://www.freecodecamp.org/news'; const newsURL = 'https://www.freecodecamp.org/news';
it('should generate correct forum link', () => { it('should generate correct forum link', () => {
const receivedUrl = createExternalRedirect('forum', { ...envVars }); const receivedUrl = createExternalRedirect('forum', { ...envVars });
expect(receivedUrl).toBe(englishForumUrl); expect(receivedUrl).toBe(forumURL);
}); });
it('should generate correct news link', () => { it('should generate correct news link', () => {
const receivedUrl = createExternalRedirect('news', { ...envVars }); const receivedUrl = createExternalRedirect('news', { ...envVars });
expect(receivedUrl).toBe(englishNewsUrl); expect(receivedUrl).toBe(newsURL);
}); });
}); });
@ -27,17 +27,17 @@ describe('createExternalRedirects', () => {
clientLocale: 'chinese' clientLocale: 'chinese'
}; };
const englishForumUrl = 'https://chinese.freecodecamp.org/forum'; const forumURL = 'https://chinese.freecodecamp.org/forum';
const englishNewsUrl = 'https://chinese.freecodecamp.org/news'; const newsURL = 'https://chinese.freecodecamp.org/news';
it('should generate correct forum link', () => { it('should generate correct forum link', () => {
const receivedUrl = createExternalRedirect('forum', { ...envVars }); const receivedUrl = createExternalRedirect('forum', { ...envVars });
expect(receivedUrl).toBe(englishForumUrl); expect(receivedUrl).toBe(forumURL);
}); });
it('should generate correct news link', () => { it('should generate correct news link', () => {
const receivedUrl = createExternalRedirect('news', { ...envVars }); const receivedUrl = createExternalRedirect('news', { ...envVars });
expect(receivedUrl).toBe(englishNewsUrl); expect(receivedUrl).toBe(newsURL);
}); });
}); });
@ -46,17 +46,17 @@ describe('createExternalRedirects', () => {
clientLocale: 'espanol' clientLocale: 'espanol'
}; };
const englishForumUrl = 'https://forum.freecodecamp.org/c/espanol/'; const forumURL = 'https://forum.freecodecamp.org/c/espanol/';
const englishNewsUrl = 'https://www.freecodecamp.org/espanol/news'; const newsURL = 'https://www.freecodecamp.org/espanol/news';
it('should generate correct forum link', () => { it('should generate correct forum link', () => {
const receivedUrl = createExternalRedirect('forum', { ...envVars }); const receivedUrl = createExternalRedirect('forum', { ...envVars });
expect(receivedUrl).toBe(englishForumUrl); expect(receivedUrl).toBe(forumURL);
}); });
it('should generate correct news link', () => { it('should generate correct news link', () => {
const receivedUrl = createExternalRedirect('news', { ...envVars }); const receivedUrl = createExternalRedirect('news', { ...envVars });
expect(receivedUrl).toBe(englishNewsUrl); expect(receivedUrl).toBe(newsURL);
}); });
}); });
@ -65,17 +65,36 @@ describe('createExternalRedirects', () => {
clientLocale: 'francais' clientLocale: 'francais'
}; };
const englishForumUrl = 'https://forum.freecodecamp.org/c/francais/'; const forumURL = 'https://forum.freecodecamp.org/c/francais/';
const englishNewsUrl = 'https://www.freecodecamp.org/francais/news'; const newsURL = 'https://www.freecodecamp.org/francais/news';
it('should generate correct forum link', () => { it('should generate correct forum link', () => {
const receivedUrl = createExternalRedirect('forum', { ...envVars }); const receivedUrl = createExternalRedirect('forum', { ...envVars });
expect(receivedUrl).toBe(englishForumUrl); expect(receivedUrl).toBe(forumURL);
}); });
it('should generate correct news link', () => { it('should generate correct news link', () => {
const receivedUrl = createExternalRedirect('news', { ...envVars }); 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);
}); });
}); });
}); });

View File

@ -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'; 'https://chinese.freecodecamp.org/learn/responsive-web-design/basic-html-and-html5/inform-with-the-paragraph-element';
const espanolPageURL = const espanolPageURL =
'https://www.freecodecamp.org/espanol/learn/responsive-web-design/basic-html-and-html5/inform-with-the-paragraph-element'; 'https://www.freecodecamp.org/espanol/learn/responsive-web-design/basic-html-and-html5/inform-with-the-paragraph-element';
const francaisPageURL = const chineseTraditionalPageURL =
'https://www.freecodecamp.org/francais/learn/responsive-web-design/basic-html-and-html5/inform-with-the-paragraph-element'; '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; const originalLocation = window.location;
@ -52,12 +54,20 @@ describe('createLanguageRedirect for clientLocale === english', () => {
expect(receivedPageURL).toBe(espanolPageURL); expect(receivedPageURL).toBe(espanolPageURL);
}); });
it('should redirect to francais version of page', () => { it('should redirect to chinese-traditional version of page', () => {
const receivedPageURL = createLanguageRedirect({ const receivedPageURL = createLanguageRedirect({
...envVars, ...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 currentPageURL = 'https://www.freecodecamp.org/settings';
const chinesePageURL = 'https://chinese.freecodecamp.org/settings'; const chinesePageURL = 'https://chinese.freecodecamp.org/settings';
const espanolPageURL = 'https://www.freecodecamp.org/espanol/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; const originalLocation = window.location;
@ -102,12 +114,20 @@ describe('createLanguageRedirect for clientLocale === english', () => {
expect(receivedPageURL).toBe(espanolPageURL); expect(receivedPageURL).toBe(espanolPageURL);
}); });
it('should redirect to francais version of page', () => { it('should redirect to chinese-traditional version of page', () => {
const receivedPageURL = createLanguageRedirect({ const receivedPageURL = createLanguageRedirect({
...envVars, ...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'; 'https://www.freecodecamp.org/learn/responsive-web-design/basic-html-and-html5/inform-with-the-paragraph-element';
const espanolPageURL = const espanolPageURL =
'https://www.freecodecamp.org/espanol/learn/responsive-web-design/basic-html-and-html5/inform-with-the-paragraph-element'; 'https://www.freecodecamp.org/espanol/learn/responsive-web-design/basic-html-and-html5/inform-with-the-paragraph-element';
const francaisPageURL = const chineseTraditionalPageURL =
'https://www.freecodecamp.org/francais/learn/responsive-web-design/basic-html-and-html5/inform-with-the-paragraph-element'; '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; const originalLocation = window.location;
@ -162,12 +184,20 @@ describe('createLanguageRedirect for clientLocale === chinese', () => {
expect(receivedPageURL).toBe(espanolPageURL); expect(receivedPageURL).toBe(espanolPageURL);
}); });
it('should redirect to francais version of page', () => { it('should redirect to chinese-traditional version of page', () => {
const receivedPageURL = createLanguageRedirect({ const receivedPageURL = createLanguageRedirect({
...envVars, ...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 currentPageURL = 'https://chinese.freecodecamp.org/settings';
const englishPageURL = 'https://www.freecodecamp.org/settings'; const englishPageURL = 'https://www.freecodecamp.org/settings';
const espanolPageURL = 'https://www.freecodecamp.org/espanol/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; const originalLocation = window.location;
@ -212,12 +244,20 @@ describe('createLanguageRedirect for clientLocale === chinese', () => {
expect(receivedPageURL).toBe(espanolPageURL); expect(receivedPageURL).toBe(espanolPageURL);
}); });
it('should redirect to francais version of page', () => { it('should redirect to chinese-traditional version of page', () => {
const receivedPageURL = createLanguageRedirect({ const receivedPageURL = createLanguageRedirect({
...envVars, ...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);
}); });
}); });
}); });