Skip to content

Instantly share code, notes, and snippets.

@AdamRamberg
Created August 28, 2019 17:50
Show Gist options
  • Save AdamRamberg/34a59b2511e3353f6058c3bef0859742 to your computer and use it in GitHub Desktop.
Save AdamRamberg/34a59b2511e3353f6058c3bef0859742 to your computer and use it in GitHub Desktop.
Translate your React app with ease using Facebook's own framework (FBT) - toggleLocale.js
import React from 'react';
import { LocaleConsumer } from 'fbt-easy-setup';
import fbt from 'fbt';
const ToggleLocale = () => (
<LocaleConsumer>
{({ locale, setLocale }) => (
<button
type="button"
onClick={() => setLocale(locale === 'sv_SE' ? 'en_US' : 'sv_SE')}
>
<fbt desc="Toggle locale button">
Toggle Locale
</fbt>
</button>
)}
</LocaleConsumer>
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment