Skip to content

Prototype with proposed i18n architecture #1478

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 111 additions & 36 deletions client/components/Nav.jsx

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion client/components/__test__/Nav.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ describe('Nav', () => {
setToastText: jest.fn(),
rootFile: {
id: 'root-file'
}
},
t: jest.fn()
};
const getWrapper = () => shallow(<NavComponent {...props} />);

Expand Down
62 changes: 14 additions & 48 deletions client/components/__test__/__snapshots__/Nav.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ exports[`Nav renders correctly 1`] = `
>
<span
className="nav__item-header"
>
File
</span>
/>
<test-file-stub
aria-hidden="true"
className="nav__item-header-triangle"
Expand All @@ -49,9 +47,7 @@ exports[`Nav renders correctly 1`] = `
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
>
New
</button>
/>
</li>
<li
className="nav__dropdown-item"
Expand All @@ -60,9 +56,7 @@ exports[`Nav renders correctly 1`] = `
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
>
Duplicate
</button>
/>
</li>
<li
className="nav__dropdown-item"
Expand All @@ -71,9 +65,7 @@ exports[`Nav renders correctly 1`] = `
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
>
Share
</button>
/>
</li>
<li
className="nav__dropdown-item"
Expand All @@ -82,9 +74,7 @@ exports[`Nav renders correctly 1`] = `
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
>
Download
</button>
/>
</li>
<li
className="nav__dropdown-item"
Expand All @@ -94,9 +84,7 @@ exports[`Nav renders correctly 1`] = `
onClick={[Function]}
onFocus={[Function]}
style={Object {}}
>
Open
</a>
/>
</li>
</ul>
</li>
Expand All @@ -111,9 +99,7 @@ exports[`Nav renders correctly 1`] = `
>
<span
className="nav__item-header"
>
Edit
</span>
/>
<test-file-stub
aria-hidden="true"
className="nav__item-header-triangle"
Expand All @@ -131,7 +117,6 @@ exports[`Nav renders correctly 1`] = `
onClick={[Function]}
onFocus={[Function]}
>
Tidy Code
<span
className="nav__keyboard-shortcut"
>
Expand All @@ -148,7 +133,6 @@ exports[`Nav renders correctly 1`] = `
onClick={[Function]}
onFocus={[Function]}
>
Find
<span
className="nav__keyboard-shortcut"
>
Expand All @@ -165,7 +149,6 @@ exports[`Nav renders correctly 1`] = `
onClick={[Function]}
onFocus={[Function]}
>
Find Next
<span
className="nav__keyboard-shortcut"
>
Expand All @@ -182,7 +165,6 @@ exports[`Nav renders correctly 1`] = `
onClick={[Function]}
onFocus={[Function]}
>
Find Previous
<span
className="nav__keyboard-shortcut"
>
Expand All @@ -206,9 +188,7 @@ exports[`Nav renders correctly 1`] = `
>
<span
className="nav__item-header"
>
Sketch
</span>
/>
<test-file-stub
aria-hidden="true"
className="nav__item-header-triangle"
Expand All @@ -225,9 +205,7 @@ exports[`Nav renders correctly 1`] = `
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
>
Add File
</button>
/>
</li>
<li
className="nav__dropdown-item"
Expand All @@ -236,9 +214,7 @@ exports[`Nav renders correctly 1`] = `
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
>
Add Folder
</button>
/>
</li>
<li
className="nav__dropdown-item"
Expand All @@ -248,7 +224,6 @@ exports[`Nav renders correctly 1`] = `
onClick={[Function]}
onFocus={[Function]}
>
Run
<span
className="nav__keyboard-shortcut"
>
Expand All @@ -265,7 +240,6 @@ exports[`Nav renders correctly 1`] = `
onClick={[Function]}
onFocus={[Function]}
>
Stop
<span
className="nav__keyboard-shortcut"
>
Expand All @@ -289,9 +263,7 @@ exports[`Nav renders correctly 1`] = `
>
<span
className="nav__item-header"
>
Help
</span>
/>
<test-file-stub
aria-hidden="true"
className="nav__item-header-triangle"
Expand All @@ -308,9 +280,7 @@ exports[`Nav renders correctly 1`] = `
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
>
Keyboard Shortcuts
</button>
/>
</li>
<li
className="nav__dropdown-item"
Expand All @@ -322,9 +292,7 @@ exports[`Nav renders correctly 1`] = `
onFocus={[Function]}
rel="noopener noreferrer"
target="_blank"
>
Reference
</a>
/>
</li>
<li
className="nav__dropdown-item"
Expand All @@ -334,9 +302,7 @@ exports[`Nav renders correctly 1`] = `
onClick={[Function]}
onFocus={[Function]}
style={Object {}}
>
About
</a>
/>
</li>
</ul>
</li>
Expand Down
38 changes: 38 additions & 0 deletions client/i18n.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
import LanguageDetector from 'i18next-browser-languagedetector';
import Backend from 'i18next-http-backend';

const fallbackLng = ['en-US'];
const availableLanguages = ['en-US', 'es-419'];

const options = {
loadPath: '/translations/{{lng}}/translations.json',
requestOptions: { // used for fetch, can also be a function (payload) => ({ method: 'GET' })
mode: 'no-cors'
},
allowMultiLoading: false, // set loadPath: '/locales/resources.json?lng={{lng}}&ns={{ns}}' to adapt to multiLoading
};

i18n
.use(initReactI18next) // pass the i18n instance to react-i18next.
.use(LanguageDetector)// to detect the language from currentBrowser
.use(Backend) // to fetch the data from server
.init({
lng: 'en-US',
defaultNS: 'WebEditor',
fallbackLng, // if user computer language is not on the list of available languages, than we will be using the fallback language specified earlier
debug: false,
backend: options,
getAsync: false,
initImmediate: false,
useSuspense: true,
whitelist: availableLanguages,
interpolation: {
escapeValue: false, // react already safes from xss
},
saveMissing: false, // if a key is not found AND this flag is set to true, i18next will call the handler missingKeyHandler
missingKeyHandler: false // function(lng, ns, key, fallbackValue) { } custom logic about how to handle the missing keys
});

export default i18n;
8 changes: 6 additions & 2 deletions client/index.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { Suspense } from 'react';
import { render } from 'react-dom';
import { hot } from 'react-hot-loader/root';
import { Provider } from 'react-redux';
Expand All @@ -7,6 +7,8 @@ import { Router, browserHistory } from 'react-router';
import configureStore from './store';
import routes from './routes';
import ThemeProvider from './modules/App/components/ThemeProvider';
import Loader from './modules/App/components/loader';
import i18n from './i18n';

require('./styles/main.scss');

Expand All @@ -29,6 +31,8 @@ const App = () => (
const HotApp = hot(App);

render(
<HotApp />,
<Suspense fallback={(<Loader />)}>
<HotApp />
</Suspense>,
document.getElementById('root')
);
23 changes: 12 additions & 11 deletions client/modules/IDE/components/About.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import React from 'react';
import { Helmet } from 'react-helmet';

import { useTranslation } from 'react-i18next';
import SquareLogoIcon from '../../../images/p5js-square-logo.svg';
// import PlayIcon from '../../../images/play.svg';
import AsteriskIcon from '../../../images/p5-asterisk.svg';

function About(props) {
const { t } = useTranslation();
return (
<div className="about__content">
<Helmet>
<title>p5.js Web Editor | About</title>
<title>p5.js Web Editor | About </title>
</Helmet>
<div className="about__content-column">
<SquareLogoIcon className="about__logo" role="img" aria-label="p5.js Logo" focusable="false" />
Expand All @@ -25,15 +26,15 @@ function About(props) {
</p> */}
</div>
<div className="about__content-column">
<h3 className="about__content-column-title">New to p5.js?</h3>
<h3 className="about__content-column-title">{t('NewP5')}</h3>
<p className="about__content-column-list">
<a
href="https://p5js.org/examples/"
target="_blank"
rel="noopener noreferrer"
>
<AsteriskIcon className="about__content-column-asterisk" aria-hidden="true" focusable="false" />
Examples
{t('Examples')}
</a>
</p>
<p className="about__content-column-list">
Expand All @@ -43,20 +44,20 @@ function About(props) {
rel="noopener noreferrer"
>
<AsteriskIcon className="about__content-column-asterisk" aria-hidden="true" focusable="false" />
Learn
{t('Learn')}
</a>
</p>
</div>
<div className="about__content-column">
<h3 className="about__content-column-title">Resources</h3>
<h3 className="about__content-column-title">{t('Resources')}</h3>
<p className="about__content-column-list">
<a
href="https://p5js.org/libraries/"
target="_blank"
rel="noopener noreferrer"
>
<AsteriskIcon className="about__content-column-asterisk" aria-hidden="true" focusable="false" />
Libraries
{t('Libraries')}
</a>
</p>
<p className="about__content-column-list">
Expand All @@ -66,7 +67,7 @@ function About(props) {
rel="noopener noreferrer"
>
<AsteriskIcon className="about__content-column-asterisk" aria-hidden="true" focusable="false" />
Reference
{t('Reference')}
</a>
</p>
<p className="about__content-column-list">
Expand All @@ -76,7 +77,7 @@ function About(props) {
rel="noopener noreferrer"
>
<AsteriskIcon className="about__content-column-asterisk" aria-hidden="true" focusable="false" />
Forum
{t('Forum')}
</a>
</p>
</div>
Expand All @@ -86,15 +87,15 @@ function About(props) {
href="https://github.com/processing/p5.js-web-editor"
target="_blank"
rel="noopener noreferrer"
>Contribute
>{t('Contribute')}
</a>
</p>
<p className="about__footer-list">
<a
href="https://github.com/processing/p5.js-web-editor/issues/new"
target="_blank"
rel="noopener noreferrer"
>Report a bug
>{t('Report')}
</a>
</p>
<p className="about__footer-list">
Expand Down
Loading