From a903e3e9b21694f31b0786b1722eb1d339df5423 Mon Sep 17 00:00:00 2001
From: apple502j <33279053+apple502j@users.noreply.github.com>
Date: Thu, 18 Jun 2020 20:22:22 +0900
Subject: [PATCH 1/2] Set wiki link per user's selected language
---
src/components/footer/www/footer.jsx | 3 ++-
src/lib/scratch-wiki.js | 24 ++++++++++++++++++++++++
test/unit/lib/scratch-wiki.test.js | 19 +++++++++++++++++++
3 files changed, 45 insertions(+), 1 deletion(-)
create mode 100644 src/lib/scratch-wiki.js
create mode 100644 test/unit/lib/scratch-wiki.test.js
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/');
+ });
+});
From a635cd932c4a5d5dbe842e92be0432b3532bd0cf Mon Sep 17 00:00:00 2001
From: Ben Wheeler
Date: Thu, 25 Jun 2020 14:09:32 -0400
Subject: [PATCH 2/2] make scratchWikiLink prop
---
src/components/footer/www/footer.jsx | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/src/components/footer/www/footer.jsx b/src/components/footer/www/footer.jsx
index 49e5f48a0..a195702a2 100644
--- a/src/components/footer/www/footer.jsx
+++ b/src/components/footer/www/footer.jsx
@@ -2,6 +2,8 @@ const FormattedMessage = require('react-intl').FormattedMessage;
const injectIntl = require('react-intl').injectIntl;
const intlShape = require('react-intl').intlShape;
const MediaQuery = require('react-responsive').default;
+const connect = require('react-redux').connect;
+const PropTypes = require('prop-types');
const React = require('react');
const FooterBox = require('../container/footer.jsx');
@@ -109,7 +111,7 @@ const Footer = props => (
-
+
@@ -214,7 +216,13 @@ const Footer = props => (
);
Footer.propTypes = {
- intl: intlShape.isRequired
+ intl: intlShape.isRequired,
+ scratchWikiLink: PropTypes.string
};
-module.exports = injectIntl(Footer);
+const mapStateToProps = (state, ownProps) => ({
+ scratchWikiLink: getScratchWikiLink(ownProps.intl.locale)
+});
+
+const ConnectedFooter = connect(mapStateToProps)(Footer);
+module.exports = injectIntl(ConnectedFooter);