Skip to content

Instantly share code, notes, and snippets.

View ryandrewjohnson's full-sized avatar

Ryan Johnson ryandrewjohnson

View GitHub Profile
import React from "react";
import { withLocalize } from "react-localize-redux";
const LanguageToggle = ({ languages, activeLanguage, setActiveLanguage }) => (
<ul className="selector">
{languages.map(lang => (
<li key={lang.code}>
<button onClick={() => setActiveLanguage(lang.code)}>
{lang.name}
</button>
@ryandrewjohnson
ryandrewjohnson / movie.json
Last active July 1, 2018 01:05
react-localize-redux - movies.json
{
"movie": {
"title": ["Jurassic Park", "Le Parc jurassique"]
}
}
@ryandrewjohnson
ryandrewjohnson / translate-renderprops.jsx
Last active July 1, 2018 01:03
react-localize-redux - renderprops.jsx
const Movies = props => (
<Translate>
{({ translate }) => <h1>{translate("movie.title")}</h1>}
</Translate>
);
@ryandrewjohnson
ryandrewjohnson / translate-selfclosing.jsx
Last active July 1, 2018 01:02
react-localize-redux - Translate with self-closing tag
const Movies = props => (
<h1>
<Translate id="movie.title" />
</h1>
);
@ryandrewjohnson
ryandrewjohnson / translate-with-defaults.jsx
Last active July 1, 2018 01:00
react-localize-redux - Translate with default translations:
import React from "react";
import { Translate } from "react-localize-redux";
const Movies = props => (
<h1>
<Translate id="movie.title">Jurassic Park</Translate>
</h1>
);
@ryandrewjohnson
ryandrewjohnson / addTranslationForLanguage.jsx
Last active July 1, 2018 00:57
react-localize-redux - addTranslationForLanguage.jsx
import frenchMovieTranslations from "./translations/fr.movies.json";
this.props.addTranslationForLanguage(frenchMovieTranslations, "fr");
@ryandrewjohnson
ryandrewjohnson / addTranslation.jsx
Last active July 1, 2018 00:54
react-localize-redux - addTranslations.js
import React from "react";
import { withLocalize } from "react-localize-redux";
import movieTranslations from "./translations/movies.json";
class Movies extends React.Component {
constructor(props) {
super(props);
this.props.addTranslation(movieTranslations);
}
@ryandrewjohnson
ryandrewjohnson / initialize.jsx
Last active July 1, 2018 00:50
react-localize-redux - setLanguages.js
import React from "react";
import { renderToStaticMarkup } from "react-dom/server";
import { withLocalize } from "react-localize-redux";
import globalTranslations from "./translations/global.json";
class Main extends React.Component {
constructor(props) {
super(props);
this.props.initialize({
@ryandrewjohnson
ryandrewjohnson / app.jsx
Last active July 1, 2018 00:47
react-localize-redux - app.js
import React from "react";
import { render } from "react-dom";
import { BrowserRouter as Router, Route } from "react-router-dom";
import { LocalizeProvider } from "react-localize-redux";
import Main from "./Main";
const App = props => (
<LocalizeProvider>
<Router>
<Route path="/" component={Main} />
import React from 'react';
import Enzyme, { mount } from 'enzyme';
// ensure you're resetting modules before each test
beforeEach(() => {
jest.resetModules();
});
// Takes the context data we want to test, or uses defaults
const getLanguageSelectorWithContext = (context = {languages: ['en', 'fr', 'es'], activeLanguage: 'en'}) => {