Set wiki link per user's selected language

This commit is contained in:
apple502j 2020-06-18 20:22:22 +09:00
parent cdd33ffa1c
commit a903e3e9b2
3 changed files with 45 additions and 1 deletions

View file

@ -8,6 +8,7 @@ const FooterBox = require('../container/footer.jsx');
const LanguageChooser = require('../../languagechooser/languagechooser.jsx'); const LanguageChooser = require('../../languagechooser/languagechooser.jsx');
const frameless = require('../../../lib/frameless'); const frameless = require('../../../lib/frameless');
const getScratchWikiLink = require('../../../lib/scratch-wiki');
require('./footer.scss'); require('./footer.scss');
@ -108,7 +109,7 @@ const Footer = props => (
</a> </a>
</dd> </dd>
<dd> <dd>
<a href="https://en.scratch-wiki.info/"> <a href={getScratchWikiLink(props.intl.locale)}>
<FormattedMessage id="general.wiki" /> <FormattedMessage id="general.wiki" />
</a> </a>
</dd> </dd>

24
src/lib/scratch-wiki.js Normal file
View file

@ -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;

View file

@ -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/');
});
});