diff --git a/src/components/footer/www/footer.jsx b/src/components/footer/www/footer.jsx index f533c8a3c..49e5f48a0 100644 --- a/src/components/footer/www/footer.jsx +++ b/src/components/footer/www/footer.jsx @@ -8,6 +8,7 @@ const FooterBox = require('../container/footer.jsx'); const LanguageChooser = require('../../languagechooser/languagechooser.jsx'); const frameless = require('../../../lib/frameless'); +const getScratchWikiLink = require('../../../lib/scratch-wiki'); require('./footer.scss'); @@ -108,7 +109,7 @@ const Footer = props => (
- +
diff --git a/src/lib/scratch-wiki.js b/src/lib/scratch-wiki.js new file mode 100644 index 000000000..b143fdbf8 --- /dev/null +++ b/src/lib/scratch-wiki.js @@ -0,0 +1,24 @@ +// This list has to be updated when a new Scratch Wiki is made. +// Note that wikis under testwiki are not included. +const wwwLocaleToScratchWikiLocale = { + en: 'en', + ja: 'ja', + fr: 'fr', + de: 'de', + ru: 'ru', + hu: 'hu', + nl: 'nl', + id: 'id' +}; + +const getScratchWikiLink = locale => { + if (!wwwLocaleToScratchWikiLocale.hasOwnProperty(locale)) { + locale = locale.split('-')[0]; + if (!wwwLocaleToScratchWikiLocale.hasOwnProperty(locale)) { + locale = 'en'; + } + } + return `https://${wwwLocaleToScratchWikiLocale[locale]}.scratch-wiki.info/`; +}; + +module.exports = getScratchWikiLink; diff --git a/test/unit/lib/scratch-wiki.test.js b/test/unit/lib/scratch-wiki.test.js new file mode 100644 index 000000000..ceb020110 --- /dev/null +++ b/test/unit/lib/scratch-wiki.test.js @@ -0,0 +1,19 @@ +const getScratchWikiLink = require('../../../src/lib/scratch-wiki'); + +describe('unit test lib/scratch-wiki.js', () => { + test('getScratchWikiLink exists', () => { + expect(typeof getScratchWikiLink).toBe('function'); + }); + + test('it returns link to jawiki when ja is given', () => { + expect(getScratchWikiLink('ja')).toBe('https://ja.scratch-wiki.info/'); + }); + + test('it returns link to jawiki when ja-Hira is given', () => { + expect(getScratchWikiLink('ja-Hira')).toBe('https://ja.scratch-wiki.info/'); + }); + + test('it returns link to enwiki when invalid locale is given', () => { + expect(getScratchWikiLink('test')).toBe('https://en.scratch-wiki.info/'); + }); +});