diff --git a/fluent-react/.npmignore b/fluent-react/.npmignore index d8caf6300..8a6c92eba 100644 --- a/fluent-react/.npmignore +++ b/fluent-react/.npmignore @@ -1,7 +1,7 @@ .nyc_output coverage esm/.compiled -examples +example src test makefile diff --git a/fluent-react/examples/change-language/.gitignore b/fluent-react/example/.gitignore similarity index 66% rename from fluent-react/examples/change-language/.gitignore rename to fluent-react/example/.gitignore index ba70f3893..9f10b5e9c 100644 --- a/fluent-react/examples/change-language/.gitignore +++ b/fluent-react/example/.gitignore @@ -1,2 +1,3 @@ .cache dist +*.tgz diff --git a/fluent-react/example/README.md b/fluent-react/example/README.md new file mode 100644 index 000000000..acc458471 --- /dev/null +++ b/fluent-react/example/README.md @@ -0,0 +1,27 @@ +# @fluent/react Example + +This tiny React app demonstrates how `@fluent/react` can integrate with React. + +## Running + +The example app requires a local build of `@fluent/react`. In the root of +your `fluent.js` clone install the build tools: + + cd fluent.js/ + npm install + +Then build and package `@fluent/react`: + + cd fluent.js/fluent-react/ + npm install + make + npm pack + mv fluent-react-*.tgz example/fluent-react.tgz + +Finally, change back to this directory, and build the example: + + cd fluent.js/fluent-react/example/ + npm install + npm start + +Open http://localhost:1234 to see the example running. diff --git a/fluent-react/example/package.json b/fluent-react/example/package.json new file mode 100644 index 000000000..6cde412ce --- /dev/null +++ b/fluent-react/example/package.json @@ -0,0 +1,25 @@ +{ + "name": "fluent-react-example", + "version": "0.1.0", + "private": true, + "scripts": { + "start": "parcel serve public/index.html", + "build": "parcel build public/index.html" + }, + "dependencies": { + "@fluent/bundle": "0.15.x", + "@fluent/langneg": "0.4.x", + "@fluent/react": "file:fluent-react.tgz", + "react": "16.8.x", + "react-dom": "16.8.x" + }, + "devDependencies": { + "@types/react": "^16.9.32", + "@types/react-dom": "^16.9.6", + "parcel-bundler": "1.12.x" + }, + "engines": { + "node": ">=10.0.0", + "browsers": "Firefox >= 57" + } +} diff --git a/fluent-react/example/public/en-US.ftl b/fluent-react/example/public/en-US.ftl new file mode 100644 index 000000000..f37f9eb0f --- /dev/null +++ b/fluent-react/example/public/en-US.ftl @@ -0,0 +1,13 @@ +hello = Hello, { $userName }! +hello-no-name = Hello, stranger! +type-name = + .placeholder = Your name + +# $date (Date) - Current date, formatted as month and day. +today-date = Today is {$date}. +# $date (Date) - Current date, formatted as weekday. +today-weekday = It's {$date}. + +sign-in-or-cancel = Sign in or cancel. +clicked-sign-in = You are now signed in. +clicked-cancel = OK, nevermind. diff --git a/fluent-react/examples/redux-sync/public/index.html b/fluent-react/example/public/index.html similarity index 67% rename from fluent-react/examples/redux-sync/public/index.html rename to fluent-react/example/public/index.html index d9767e9a0..d6d65308f 100644 --- a/fluent-react/examples/redux-sync/public/index.html +++ b/fluent-react/example/public/index.html @@ -3,10 +3,10 @@ - Redux sync - a fluent-react example + @fluent/react Example
- + diff --git a/fluent-react/example/public/pl.ftl b/fluent-react/example/public/pl.ftl new file mode 100644 index 000000000..646d96617 --- /dev/null +++ b/fluent-react/example/public/pl.ftl @@ -0,0 +1,15 @@ +hello = Cześć { $userName }! +hello-no-name = Witaj nieznajomy! +type-name = + .placeholder = Twoje imię + +# $date (Date) - Current date, formatted as month and day. +today-date = Dziś jest {$date}. + +# Commented out to demonstrate fallback. +# $date (Date) - Current date, formatted as weekday. +# today-weekday = Jest {$date}. + +sign-in-or-cancel = Zaloguj albo anuluj. +clicked-sign-in = Brawo! +clicked-cancel = OK, nieważne. diff --git a/fluent-react/example/src/App.tsx b/fluent-react/example/src/App.tsx new file mode 100644 index 000000000..2d68cc4f5 --- /dev/null +++ b/fluent-react/example/src/App.tsx @@ -0,0 +1,41 @@ +import React, { useState } from "react"; +import { Localized } from "@fluent/react"; +import { FluentDateTime } from "@fluent/bundle"; +import { Hello } from "./Hello"; +import { LocalizedSignIn } from "./SignIn"; + +export function App() { + let [date] = useState(() => new Date()); + return <> + + + +

+ {"Today is {$date}."} +

+
+ + +

+ {"It's {$date}."} +

+
+ + + ; +} diff --git a/fluent-react/example/src/Hello.tsx b/fluent-react/example/src/Hello.tsx new file mode 100644 index 000000000..3355ac533 --- /dev/null +++ b/fluent-react/example/src/Hello.tsx @@ -0,0 +1,29 @@ +import React, { useState } from "react"; +import { Localized } from "@fluent/react"; + +export function Hello() { + let [userName, setUserName] = useState(""); + + return ( +
+ {userName ? + +

{'Hello, { $userName }!'}

+
+ : + +

Hello, stranger!

+
+ } + + + setUserName(evt.target.value)} + value={userName} + /> + +
+ ); +} diff --git a/fluent-react/example/src/SignIn.tsx b/fluent-react/example/src/SignIn.tsx new file mode 100644 index 000000000..97a2f4ea6 --- /dev/null +++ b/fluent-react/example/src/SignIn.tsx @@ -0,0 +1,25 @@ +import React from "react"; +import { Localized, withLocalization, WithLocalizationProps } from "@fluent/react"; + +function SignIn(props: WithLocalizationProps) { + function showAlert(id: string) { + const { getString } = props; + alert(getString(id)); + } + + return ( +
+ showAlert('clicked-sign-in')}>, + cancel: + }} + > +

{'Sign in or cancel.'}

+
+
+ ); +} + +export const LocalizedSignIn = withLocalization(SignIn); diff --git a/fluent-react/example/src/index.tsx b/fluent-react/example/src/index.tsx new file mode 100644 index 000000000..e6359fa89 --- /dev/null +++ b/fluent-react/example/src/index.tsx @@ -0,0 +1,12 @@ +import React from "react"; +import ReactDOM from "react-dom"; + +import { AppLocalizationProvider } from "./l10n"; +import { App } from "./App"; + +ReactDOM.render( + + + , + document.getElementById("root") +); diff --git a/fluent-react/example/src/l10n.tsx b/fluent-react/example/src/l10n.tsx new file mode 100644 index 000000000..16e1172dd --- /dev/null +++ b/fluent-react/example/src/l10n.tsx @@ -0,0 +1,77 @@ +import React, { Children, useEffect, useState, ReactNode } from "react"; + +import { negotiateLanguages } from "@fluent/langneg"; +import { FluentBundle, FluentResource } from "@fluent/bundle"; +import { ReactLocalization, LocalizationProvider } from "@fluent/react"; + +// Parcel decorates filenames with cache-busting hashes. +const ftl = require("../public/*.ftl"); + +const DEFAULT_LOCALE = "en-US"; +const AVAILABLE_LOCALES = { + "en-US": "English", + "pl": "Polish", +}; + +async function fetchMessages(locale: string): Promise<[string, string]> { + let response = await fetch(ftl[locale]); + let messages = await response.text(); + return [locale, messages]; +} + +function* lazilyParsedBundles(fetchedMessages: Array<[string, string]>) { + for (let [locale, messages] of fetchedMessages) { + let resource = new FluentResource(messages); + let bundle = new FluentBundle(locale); + bundle.addResource(resource); + yield bundle; + } +} + +interface AppLocalizationProviderProps { + children: ReactNode; +} + +export function AppLocalizationProvider(props: AppLocalizationProviderProps) { + let [currentLocales, setCurrentLocales] = useState([DEFAULT_LOCALE]); + let [l10n, setL10n] = useState(null); + + useEffect(() => { + changeLocales(navigator.languages as Array); + }, []); + + async function changeLocales(userLocales: Array) { + let currentLocales = negotiateLanguages( + userLocales, + Object.keys(AVAILABLE_LOCALES), + { defaultLocale: DEFAULT_LOCALE } + ); + setCurrentLocales(currentLocales); + + let fetchedMessages = await Promise.all( + currentLocales.map(fetchMessages) + ); + + let bundles = lazilyParsedBundles(fetchedMessages); + setL10n(new ReactLocalization(bundles)); + } + + if (l10n === null) { + return
Loading…
; + } + + return <> + + {Children.only(props.children)} + + +
+ + ; +} diff --git a/fluent-react/example/tsconfig.json b/fluent-react/example/tsconfig.json new file mode 100644 index 000000000..a40a15d27 --- /dev/null +++ b/fluent-react/example/tsconfig.json @@ -0,0 +1,7 @@ +{ + "compilerOptions": { + "esModuleInterop": true, + "strict": true, + "jsx": "react", + } +} diff --git a/fluent-react/examples/README.md b/fluent-react/examples/README.md deleted file mode 100644 index 25367a71b..000000000 --- a/fluent-react/examples/README.md +++ /dev/null @@ -1,19 +0,0 @@ -# fluent-react examples - -These tiny React apps demonstrate how `fluent-react` can integrate with React. -To run each example, `cd` into that folder and run the following commands: - - npm install - npm start - -__Note__: Because these examples require your local version of `fluent-react`, -you need to build that first. - -In the root of this git repository (`fluent.js/`), run: - - npm install - -Then in `fluent.js/fluent-react/`, run: - - npm install - make diff --git a/fluent-react/examples/async-messages/.gitignore b/fluent-react/examples/async-messages/.gitignore deleted file mode 100644 index ba70f3893..000000000 --- a/fluent-react/examples/async-messages/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -.cache -dist diff --git a/fluent-react/examples/async-messages/package.json b/fluent-react/examples/async-messages/package.json deleted file mode 100644 index 33c807d54..000000000 --- a/fluent-react/examples/async-messages/package.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "name": "fluent-react-example-async-messages", - "version": "0.1.0", - "private": true, - "scripts": { - "start": "parcel serve public/index.html", - "build": "parcel build public/index.html" - }, - "dependencies": { - "delay": "^2.0.0", - "fluent": "^0.8.0", - "fluent-langneg": "^0.1.0", - "fluent-react": "file:../../", - "react": "^16.3.2", - "react-dom": "^16.3.3" - }, - "devDependencies": { - "parcel-bundler": "^1.9.7" - }, - "engines": { - "node": ">=10.0.0", - "browsers": "Firefox >= 57" - } -} diff --git a/fluent-react/examples/async-messages/public/en-US.ftl b/fluent-react/examples/async-messages/public/en-US.ftl deleted file mode 100644 index f0fd75d00..000000000 --- a/fluent-react/examples/async-messages/public/en-US.ftl +++ /dev/null @@ -1 +0,0 @@ -title = Hello, world! diff --git a/fluent-react/examples/async-messages/public/index.html b/fluent-react/examples/async-messages/public/index.html deleted file mode 100644 index 3ad23b31c..000000000 --- a/fluent-react/examples/async-messages/public/index.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - Async messages - a fluent-react example - - -
- - - diff --git a/fluent-react/examples/async-messages/public/pl.ftl b/fluent-react/examples/async-messages/public/pl.ftl deleted file mode 100644 index d7a365eb9..000000000 --- a/fluent-react/examples/async-messages/public/pl.ftl +++ /dev/null @@ -1 +0,0 @@ -title = Witaj świecie! diff --git a/fluent-react/examples/async-messages/src/App.js b/fluent-react/examples/async-messages/src/App.js deleted file mode 100644 index 104da4098..000000000 --- a/fluent-react/examples/async-messages/src/App.js +++ /dev/null @@ -1,12 +0,0 @@ -import React from 'react'; -import { Localized } from 'fluent-react/compat'; - -export default function App() { - return ( -
- -

Something went wrong.

-
-
- ); -} diff --git a/fluent-react/examples/async-messages/src/index.js b/fluent-react/examples/async-messages/src/index.js deleted file mode 100644 index a7be9495e..000000000 --- a/fluent-react/examples/async-messages/src/index.js +++ /dev/null @@ -1,12 +0,0 @@ -import React from 'react'; -import ReactDOM from 'react-dom'; - -import { AppLocalizationProvider } from './l10n'; -import App from './App'; - -ReactDOM.render( - - - , - document.getElementById('root') -); diff --git a/fluent-react/examples/async-messages/src/l10n.js b/fluent-react/examples/async-messages/src/l10n.js deleted file mode 100644 index 8ba39a995..000000000 --- a/fluent-react/examples/async-messages/src/l10n.js +++ /dev/null @@ -1,74 +0,0 @@ -import React, { Component } from 'react'; -import delay from 'delay'; - -import { FluentBundle } from 'fluent/compat'; -import { LocalizationProvider } from 'fluent-react/compat'; -import { negotiateLanguages } from 'fluent-langneg/compat'; - -// Hand off handling FTL assets to Parcel. -import ftl from '../public/*.ftl'; - -async function fetchMessages(locale) { - const response = await fetch(ftl[locale]); - const messages = await response.text(); - - await delay(1000); - return { [locale]: messages }; -} - -async function createMessagesGenerator(currentLocales) { - const fetched = await Promise.all( - currentLocales.map(fetchMessages) - ); - const messages = fetched.reduce( - (obj, cur) => Object.assign(obj, cur) - ); - - return function* generateBundles() { - for (const locale of currentLocales) { - const bundle = new FluentBundle(locale); - bundle.addMessages(messages[locale]); - yield bundle; - } - } -} - -export class AppLocalizationProvider extends Component { - constructor(props) { - super(props); - - const { userLocales } = props; - - const currentLocales = negotiateLanguages( - userLocales, - ['en-US', 'pl'], - { defaultLocale: 'en-US' } - ); - - this.state = { - currentLocales, - }; - } - - async componentWillMount() { - const { currentLocales } = this.state; - const generateBundles = await createMessagesGenerator(currentLocales); - this.setState({ bundles: generateBundles() }); - } - - render() { - const { children } = this.props; - const { bundles } = this.state; - - if (!bundles) { - // Show a loader. - return
; - } - - return ( - - {children} - - ); - } -} diff --git a/fluent-react/examples/change-language/package.json b/fluent-react/examples/change-language/package.json deleted file mode 100644 index a9754cf8d..000000000 --- a/fluent-react/examples/change-language/package.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "name": "fluent-react-example-change-language", - "version": "0.1.0", - "private": true, - "scripts": { - "start": "parcel serve public/index.html", - "build": "parcel build public/index.html" - }, - "dependencies": { - "fluent": "^0.8.0", - "fluent-langneg": "^0.1.0", - "fluent-react": "file:../../", - "react": "^16.3.2", - "react-dom": "^16.3.3" - }, - "devDependencies": { - "parcel-bundler": "^1.9.7" - }, - "engines": { - "node": ">=10.0.0", - "browsers": "Firefox >= 57" - } -} diff --git a/fluent-react/examples/change-language/public/index.html b/fluent-react/examples/change-language/public/index.html deleted file mode 100644 index a33b4923d..000000000 --- a/fluent-react/examples/change-language/public/index.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - Change language - a fluent-react example - - -
- - - diff --git a/fluent-react/examples/change-language/src/App.js b/fluent-react/examples/change-language/src/App.js deleted file mode 100644 index 5d4756640..000000000 --- a/fluent-react/examples/change-language/src/App.js +++ /dev/null @@ -1,28 +0,0 @@ -import React from 'react'; -import { Localized } from 'fluent-react/compat'; - -export default function App(props) { - const { currentLocales, handleLocaleChange } = props; - - const [current] = currentLocales; - const available = ['en-US', 'pl']; - const next = available[(available.indexOf(current) + 1) % available.length]; - - return ( -
- -

Hello, world!

-
- - -

{'Current locale: { $locale }'}

-
- - - - -
- ); -} diff --git a/fluent-react/examples/change-language/src/index.js b/fluent-react/examples/change-language/src/index.js deleted file mode 100644 index a7be9495e..000000000 --- a/fluent-react/examples/change-language/src/index.js +++ /dev/null @@ -1,12 +0,0 @@ -import React from 'react'; -import ReactDOM from 'react-dom'; - -import { AppLocalizationProvider } from './l10n'; -import App from './App'; - -ReactDOM.render( - - - , - document.getElementById('root') -); diff --git a/fluent-react/examples/change-language/src/l10n.js b/fluent-react/examples/change-language/src/l10n.js deleted file mode 100644 index 0094672e1..000000000 --- a/fluent-react/examples/change-language/src/l10n.js +++ /dev/null @@ -1,66 +0,0 @@ -import React, { cloneElement, Children, Component } from 'react'; - -import { FluentBundle } from 'fluent/compat'; -import { LocalizationProvider } from 'fluent-react/compat'; -import { negotiateLanguages } from 'fluent-langneg/compat'; - -const MESSAGES_ALL = { - 'pl': ` -title = Witaj świecie! -current = Bieżący język: { $locale } -change = Zmień na { $locale } - `, - 'en-US': ` -title = Hello, world! -current = Current locale: { $locale } -change = Change to { $locale } - `, -}; - -function* generateBundles(currentLocales) { - for (const locale of currentLocales) { - const bundle = new FluentBundle(locale); - bundle.addMessages(MESSAGES_ALL[locale]); - yield bundle; - } -} - -export class AppLocalizationProvider extends Component { - constructor(props) { - super(props); - - const { userLocales } = props; - - const currentLocales = negotiateLanguages( - userLocales, - ['en-US', 'pl'], - { defaultLocale: 'en-US' } - ); - - this.state = { - currentLocales - }; - } - - handleLocaleChange(locale) { - this.setState({ - currentLocales: [locale] - }); - } - - render() { - const { currentLocales } = this.state; - const child = Children.only(this.props.children); - - const l10nProps = { - currentLocales, - handleLocaleChange: locale => this.handleLocaleChange(locale) - }; - - return ( - - { cloneElement(child, l10nProps) } - - ); - } -} diff --git a/fluent-react/examples/fallback-sync/.gitignore b/fluent-react/examples/fallback-sync/.gitignore deleted file mode 100644 index ba70f3893..000000000 --- a/fluent-react/examples/fallback-sync/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -.cache -dist diff --git a/fluent-react/examples/fallback-sync/package.json b/fluent-react/examples/fallback-sync/package.json deleted file mode 100644 index 459d5f0d2..000000000 --- a/fluent-react/examples/fallback-sync/package.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "name": "fluent-react-example-fallback-sync", - "version": "0.1.0", - "private": true, - "scripts": { - "start": "parcel serve public/index.html", - "build": "parcel build public/index.html" - }, - "dependencies": { - "fluent": "^0.8.0", - "fluent-langneg": "^0.1.0", - "fluent-react": "file:../../", - "react": "^16.3.2", - "react-dom": "^16.3.3" - }, - "devDependencies": { - "parcel-bundler": "^1.9.7" - }, - "engines": { - "node": ">=10.0.0", - "browsers": "Firefox >= 57" - } -} diff --git a/fluent-react/examples/fallback-sync/public/index.html b/fluent-react/examples/fallback-sync/public/index.html deleted file mode 100644 index ec560fd46..000000000 --- a/fluent-react/examples/fallback-sync/public/index.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - Fallback Sync - a fluent-react example - - -
- - - diff --git a/fluent-react/examples/fallback-sync/src/App.js b/fluent-react/examples/fallback-sync/src/App.js deleted file mode 100644 index 16fcec3ea..000000000 --- a/fluent-react/examples/fallback-sync/src/App.js +++ /dev/null @@ -1,28 +0,0 @@ -import React from 'react'; -import { Localized } from 'fluent-react/compat'; - -export default function App() { - return ( -
-

- This example is hardcoded to use ['pl', 'en-US']. -

- - -

Foo

-
- - -

Bar

-
- - -

Baz is missing from all locales

-
- - -

{'Qux is like { $baz }: missing from all locales.'}

-
-
- ); -} diff --git a/fluent-react/examples/fallback-sync/src/index.js b/fluent-react/examples/fallback-sync/src/index.js deleted file mode 100644 index 88e0fb083..000000000 --- a/fluent-react/examples/fallback-sync/src/index.js +++ /dev/null @@ -1,13 +0,0 @@ -import React from 'react'; -import ReactDOM from 'react-dom'; -import { LocalizationProvider } from 'fluent-react/compat'; - -import { generateBundles } from './l10n'; -import App from './App'; - -ReactDOM.render( - - - , - document.getElementById('root') -); diff --git a/fluent-react/examples/fallback-sync/src/l10n.js b/fluent-react/examples/fallback-sync/src/l10n.js deleted file mode 100644 index 64d77dee7..000000000 --- a/fluent-react/examples/fallback-sync/src/l10n.js +++ /dev/null @@ -1,19 +0,0 @@ -import { FluentBundle } from 'fluent/compat'; - -const MESSAGES_ALL = { - 'pl': ` -foo = Foo po polsku - `, - 'en-US': ` -foo = Foo in English -bar = Bar in English - `, -}; - -export function* generateBundles() { - for (const locale of ['pl', 'en-US']) { - const bundle = new FluentBundle(locale); - bundle.addMessages(MESSAGES_ALL[locale]); - yield bundle; - } -} diff --git a/fluent-react/examples/hello-world/.gitignore b/fluent-react/examples/hello-world/.gitignore deleted file mode 100644 index ba70f3893..000000000 --- a/fluent-react/examples/hello-world/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -.cache -dist diff --git a/fluent-react/examples/hello-world/package.json b/fluent-react/examples/hello-world/package.json deleted file mode 100644 index 2f5b384b5..000000000 --- a/fluent-react/examples/hello-world/package.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "name": "fluent-react-example-hello-world", - "version": "0.1.0", - "private": true, - "scripts": { - "start": "parcel serve public/index.html", - "build": "parcel build public/index.html" - }, - "dependencies": { - "fluent": "^0.8.0", - "fluent-langneg": "^0.1.0", - "fluent-react": "file:../../", - "react": "^16.3.2", - "react-dom": "^16.3.3" - }, - "devDependencies": { - "parcel-bundler": "^1.9.7" - }, - "engines": { - "node": ">=10.0.0", - "browsers": "Firefox >= 57" - } -} diff --git a/fluent-react/examples/hello-world/public/index.html b/fluent-react/examples/hello-world/public/index.html deleted file mode 100644 index b09381573..000000000 --- a/fluent-react/examples/hello-world/public/index.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - Hello world - a fluent-react example - - -
- - - diff --git a/fluent-react/examples/hello-world/src/App.js b/fluent-react/examples/hello-world/src/App.js deleted file mode 100644 index 6632300c7..000000000 --- a/fluent-react/examples/hello-world/src/App.js +++ /dev/null @@ -1,17 +0,0 @@ -import React from 'react'; -import { Localized } from 'fluent-react/compat'; - -export default function App() { - return ( -
- -

Hello, world!

-
- -

- {'Today is { DATETIME($date, month: "long", day: "numeric") }.'} -

-
-
- ); -} diff --git a/fluent-react/examples/hello-world/src/index.js b/fluent-react/examples/hello-world/src/index.js deleted file mode 100644 index f5205ea57..000000000 --- a/fluent-react/examples/hello-world/src/index.js +++ /dev/null @@ -1,13 +0,0 @@ -import React from 'react'; -import ReactDOM from 'react-dom'; -import { LocalizationProvider } from 'fluent-react/compat'; - -import { generateBundles } from './l10n'; -import App from './App'; - -ReactDOM.render( - - - , - document.getElementById('root') -); diff --git a/fluent-react/examples/hello-world/src/l10n.js b/fluent-react/examples/hello-world/src/l10n.js deleted file mode 100644 index 1393707df..000000000 --- a/fluent-react/examples/hello-world/src/l10n.js +++ /dev/null @@ -1,28 +0,0 @@ -import { FluentBundle } from 'fluent/compat'; -import { negotiateLanguages } from 'fluent-langneg/compat'; - -const MESSAGES_ALL = { - 'pl': ` -title = Witaj świecie! -today-is = Dziś jest { DATETIME($date, month: "long", day: "numeric") }. - `, - 'en-US': ` -title = Hello, world! -today-is = Today is { DATETIME($date, month: "long", day: "numeric") }. - `, -}; - -export function* generateBundles(userLocales) { - // Choose locales that are best for the user. - const currentLocales = negotiateLanguages( - userLocales, - ['en-US', 'pl'], - { defaultLocale: 'en-US' } - ); - - for (const locale of currentLocales) { - const bundle = new FluentBundle(locale); - bundle.addMessages(MESSAGES_ALL[locale]); - yield bundle; - } -} diff --git a/fluent-react/examples/higher-order/.gitignore b/fluent-react/examples/higher-order/.gitignore deleted file mode 100644 index ba70f3893..000000000 --- a/fluent-react/examples/higher-order/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -.cache -dist diff --git a/fluent-react/examples/higher-order/package.json b/fluent-react/examples/higher-order/package.json deleted file mode 100644 index deef89cba..000000000 --- a/fluent-react/examples/higher-order/package.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "name": "fluent-react-example-higher-order", - "version": "0.1.0", - "private": true, - "scripts": { - "start": "parcel serve public/index.html", - "build": "parcel build public/index.html" - }, - "dependencies": { - "fluent": "^0.8.0", - "fluent-langneg": "^0.1.0", - "fluent-react": "file:../../", - "react": "^16.3.2", - "react-dom": "^16.3.3" - }, - "devDependencies": { - "parcel-bundler": "^1.9.7" - }, - "engines": { - "node": ">=10.0.0", - "browsers": "Firefox >= 57" - } -} diff --git a/fluent-react/examples/higher-order/public/index.html b/fluent-react/examples/higher-order/public/index.html deleted file mode 100644 index 1f6f68b36..000000000 --- a/fluent-react/examples/higher-order/public/index.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - Higher-order component - a fluent-react example - - -
- - - diff --git a/fluent-react/examples/higher-order/src/App.js b/fluent-react/examples/higher-order/src/App.js deleted file mode 100644 index 347ad50be..000000000 --- a/fluent-react/examples/higher-order/src/App.js +++ /dev/null @@ -1,19 +0,0 @@ -import React from 'react'; -import { Localized, withLocalization } from 'fluent-react/compat'; - -function App(props) { - function showAlert() { - const { getString } = props; - alert(getString('hello')); - } - - return ( -
- - - -
- ); -} - -export default withLocalization(App); diff --git a/fluent-react/examples/higher-order/src/index.js b/fluent-react/examples/higher-order/src/index.js deleted file mode 100644 index f5205ea57..000000000 --- a/fluent-react/examples/higher-order/src/index.js +++ /dev/null @@ -1,13 +0,0 @@ -import React from 'react'; -import ReactDOM from 'react-dom'; -import { LocalizationProvider } from 'fluent-react/compat'; - -import { generateBundles } from './l10n'; -import App from './App'; - -ReactDOM.render( - - - , - document.getElementById('root') -); diff --git a/fluent-react/examples/higher-order/src/l10n.js b/fluent-react/examples/higher-order/src/l10n.js deleted file mode 100644 index f6fba26fc..000000000 --- a/fluent-react/examples/higher-order/src/l10n.js +++ /dev/null @@ -1,28 +0,0 @@ -import { FluentBundle } from 'fluent/compat'; -import { negotiateLanguages } from 'fluent-langneg/compat'; - -const MESSAGES_ALL = { - 'pl': ` -hello = Witaj świecie! -button-show-alert = Kliknij mnie - `, - 'en-US': ` -hello = Hello, world! -button-show-alert = Click me - `, -}; - -export function* generateBundles(userLocales) { - // Choose locales that are best for the user. - const currentLocales = negotiateLanguages( - userLocales, - ['en-US', 'pl'], - { defaultLocale: 'en-US' } - ); - - for (const locale of currentLocales) { - const bundle = new FluentBundle(locale); - bundle.addMessages(MESSAGES_ALL[locale]); - yield bundle; - } -} diff --git a/fluent-react/examples/html-markup/.gitignore b/fluent-react/examples/html-markup/.gitignore deleted file mode 100644 index ba70f3893..000000000 --- a/fluent-react/examples/html-markup/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -.cache -dist diff --git a/fluent-react/examples/html-markup/package.json b/fluent-react/examples/html-markup/package.json deleted file mode 100644 index 317a15452..000000000 --- a/fluent-react/examples/html-markup/package.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "name": "fluent-react-example-html-markup", - "version": "0.1.0", - "private": true, - "scripts": { - "start": "parcel serve public/index.html", - "build": "parcel build public/index.html" - }, - "dependencies": { - "fluent": "^0.8.0", - "fluent-langneg": "^0.1.0", - "fluent-react": "file:../../", - "react": "^16.3.2", - "react-dom": "^16.3.3" - }, - "devDependencies": { - "parcel-bundler": "^1.9.7" - }, - "engines": { - "node": ">=10.0.0", - "browsers": "Firefox >= 57" - } -} diff --git a/fluent-react/examples/html-markup/public/index.html b/fluent-react/examples/html-markup/public/index.html deleted file mode 100644 index 467ff44f5..000000000 --- a/fluent-react/examples/html-markup/public/index.html +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - HTML Markup in translations - a fluent-react example - - - -
- - - diff --git a/fluent-react/examples/html-markup/src/App.js b/fluent-react/examples/html-markup/src/App.js deleted file mode 100644 index e85c1a00c..000000000 --- a/fluent-react/examples/html-markup/src/App.js +++ /dev/null @@ -1,29 +0,0 @@ -import React from 'react'; -import { Localized, withLocalization } from 'fluent-react/compat'; - -function App(props) { - function showAlert(id) { - const { getString } = props; - alert(getString(id)); - } - - return ( -
- showAlert('clicked-sign-in')}>} - cancel={} - > -

{'Sign in or cancel.'}

-
- - } - button={} - > -

{'My name is and .'}

-
-
- ); -} - -export default withLocalization(App); diff --git a/fluent-react/examples/html-markup/src/index.js b/fluent-react/examples/html-markup/src/index.js deleted file mode 100644 index f5205ea57..000000000 --- a/fluent-react/examples/html-markup/src/index.js +++ /dev/null @@ -1,13 +0,0 @@ -import React from 'react'; -import ReactDOM from 'react-dom'; -import { LocalizationProvider } from 'fluent-react/compat'; - -import { generateBundles } from './l10n'; -import App from './App'; - -ReactDOM.render( - - - , - document.getElementById('root') -); diff --git a/fluent-react/examples/html-markup/src/l10n.js b/fluent-react/examples/html-markup/src/l10n.js deleted file mode 100644 index 4b2358acc..000000000 --- a/fluent-react/examples/html-markup/src/l10n.js +++ /dev/null @@ -1,36 +0,0 @@ -import { FluentBundle } from 'fluent/compat'; -import { negotiateLanguages } from 'fluent-langneg/compat'; - -const MESSAGES_ALL = { - 'pl': ` -sign-in-or-cancel = Zaloguj albo anuluj. -clicked-sign-in = Brawo! -clicked-cancel = OK, nieważne. - -agree-prompt = Nazywam się i . -agree-alert = Fajnie, zgadzamy się. - `, - 'en-US': ` -sign-in-or-cancel = Sign in or cancel. -clicked-sign-in = You are now signed in. -clicked-cancel = OK, nevermind. - -agree-prompt = My name is and . -agree-alert = Cool, agreed. - `, -}; - -export function* generateBundles(userLocales) { - // Choose locales that are best for the user. - const currentLocales = negotiateLanguages( - userLocales, - ['en-US', 'pl'], - { defaultLocale: 'en-US' } - ); - - for (const locale of currentLocales) { - const bundle = new FluentBundle(locale); - bundle.addMessages(MESSAGES_ALL[locale]); - yield bundle; - } -} diff --git a/fluent-react/examples/redux-async/.gitignore b/fluent-react/examples/redux-async/.gitignore deleted file mode 100644 index ba70f3893..000000000 --- a/fluent-react/examples/redux-async/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -.cache -dist diff --git a/fluent-react/examples/redux-async/package.json b/fluent-react/examples/redux-async/package.json deleted file mode 100644 index 4c33ef050..000000000 --- a/fluent-react/examples/redux-async/package.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "name": "fluent-react-example-with-redux", - "version": "0.1.0", - "private": true, - "scripts": { - "start": "parcel serve public/index.html", - "build": "parcel build public/index.html" - }, - "dependencies": { - "delay": "^2.0.0", - "fluent": "^0.8.0", - "fluent-langneg": "^0.1.0", - "fluent-react": "file:../../", - "react": "^16.3.2", - "react-dom": "^16.3.3", - "react-redux": "^5.0.6", - "redux": "^3.7.2", - "redux-logger": "^3.0.6", - "redux-thunk": "^2.2.0" - }, - "devDependencies": { - "parcel-bundler": "^1.9.7" - }, - "engines": { - "node": ">=10.0.0", - "browsers": "Firefox >= 57" - } -} diff --git a/fluent-react/examples/redux-async/public/en-US.ftl b/fluent-react/examples/redux-async/public/en-US.ftl deleted file mode 100644 index 31e5f22db..000000000 --- a/fluent-react/examples/redux-async/public/en-US.ftl +++ /dev/null @@ -1,3 +0,0 @@ -title = Hello, world! -current = Current locale: { $locale } -change = Change to { $locale } diff --git a/fluent-react/examples/redux-async/public/index.html b/fluent-react/examples/redux-async/public/index.html deleted file mode 100644 index 54f3e4717..000000000 --- a/fluent-react/examples/redux-async/public/index.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - Redux async- a fluent-react example - - -
- - - diff --git a/fluent-react/examples/redux-async/public/pl.ftl b/fluent-react/examples/redux-async/public/pl.ftl deleted file mode 100644 index 130acfc23..000000000 --- a/fluent-react/examples/redux-async/public/pl.ftl +++ /dev/null @@ -1,3 +0,0 @@ -title = Witaj świecie! -current = Bieżący język: { $locale } -change = Zmień na { $locale } diff --git a/fluent-react/examples/redux-async/src/App.js b/fluent-react/examples/redux-async/src/App.js deleted file mode 100644 index 0463d6898..000000000 --- a/fluent-react/examples/redux-async/src/App.js +++ /dev/null @@ -1,39 +0,0 @@ -import React from 'react'; -import { connect} from 'react-redux'; -import { Localized } from 'fluent-react/compat'; - -import { changeLocales } from './actions'; - -function App(props) { - const { currentLocales, isFetching, changeLocales } = props; - - const [current] = currentLocales; - const available = ['en-US', 'pl']; - const next = available[(available.indexOf(current ) + 1) % available.length]; - - return ( -
- -

Hello, world!

-
- - -

{'Current locale: { $locale }'}

-
- - - - -
- ); -} - -const mapStateToProps = state => ({ - currentLocales: state.currentLocales, - isFetching: state.isFetching -}); -const mapDispatchToProps = { changeLocales }; - -export default connect(mapStateToProps, mapDispatchToProps)(App); diff --git a/fluent-react/examples/redux-async/src/actions.js b/fluent-react/examples/redux-async/src/actions.js deleted file mode 100644 index b0e4d240e..000000000 --- a/fluent-react/examples/redux-async/src/actions.js +++ /dev/null @@ -1,49 +0,0 @@ -import { FluentBundle } from 'fluent/compat'; -import { negotiateLanguages } from 'fluent-langneg/compat'; -import delay from 'delay'; - -// Hand off handling FTL assets to Parcel. -import ftl from "../public/*.ftl"; - -async function fetchMessages(locale) { - const response = await fetch(ftl[locale]); - const messages = await response.text(); - - await delay(1000); - return { [locale]: messages }; -} - -export function changeLocales(userLocales) { - return async function(dispatch) { - dispatch({ type: 'CHANGE_LOCALES_REQUEST' }); - - const currentLocales = negotiateLanguages( - userLocales, - ['en-US', 'pl'], - { defaultLocale: 'en-US' } - ); - - const fetched = await Promise.all( - currentLocales.map(fetchMessages) - ); - - const messages = fetched.reduce( - (obj, cur) => Object.assign(obj, cur) - ); - - const generateBundles = function* () { - for (const locale of currentLocales) { - const bundle = new FluentBundle(locale); - bundle.addMessages(messages[locale]); - yield bundle; - } - } - - dispatch({ - type: 'CHANGE_LOCALES_RESPONSE', - userLocales, - currentLocales, - bundles: generateBundles() - }); - }; -} diff --git a/fluent-react/examples/redux-async/src/index.js b/fluent-react/examples/redux-async/src/index.js deleted file mode 100644 index 0681013db..000000000 --- a/fluent-react/examples/redux-async/src/index.js +++ /dev/null @@ -1,16 +0,0 @@ -import React from 'react'; -import ReactDOM from 'react-dom'; -import { Provider } from 'react-redux'; - -import store from './store'; -import AppLocalizationProvider from './l10n'; -import App from './App'; - -ReactDOM.render( - - - - - , - document.getElementById('root') -); diff --git a/fluent-react/examples/redux-async/src/l10n.js b/fluent-react/examples/redux-async/src/l10n.js deleted file mode 100644 index 3d39c48f8..000000000 --- a/fluent-react/examples/redux-async/src/l10n.js +++ /dev/null @@ -1,35 +0,0 @@ -import React, { Component } from 'react'; -import { connect } from 'react-redux'; - -import { LocalizationProvider } from 'fluent-react/compat'; - -import { changeLocales } from './actions'; - - -class AppLocalizationProvider extends Component { - componentWillMount() { - this.props.changeLocales(navigator.languages); - } - - render() { - const { bundles, children } = this.props; - - if (!bundles) { - // Show a loader - return
; - } - - return ( - - {children} - - ); - } -} - -const mapStateToProps = state => ({ bundles: state.bundles }); -const mapDispatchToProps = { changeLocales }; - -export default connect(mapStateToProps, mapDispatchToProps)( - AppLocalizationProvider -); diff --git a/fluent-react/examples/redux-async/src/reducer.js b/fluent-react/examples/redux-async/src/reducer.js deleted file mode 100644 index 33aac9863..000000000 --- a/fluent-react/examples/redux-async/src/reducer.js +++ /dev/null @@ -1,27 +0,0 @@ -export default function reducer(state = { - isFetching: false, - userLocales: ['en-US'], - currentLocales: ['en-US'], - bundles: null -}, action) { - switch (action.type) { - case 'CHANGE_LOCALES_REQUEST': { - return { - ...state, - isFetching: true - }; - } - case 'CHANGE_LOCALES_RESPONSE': { - const { userLocales, currentLocales, bundles } = action; - return { - ...state, - isFetching: false, - userLocales, - currentLocales, - bundles - }; - } - default: - return state; - } -} diff --git a/fluent-react/examples/redux-async/src/store.js b/fluent-react/examples/redux-async/src/store.js deleted file mode 100644 index f1701b5a7..000000000 --- a/fluent-react/examples/redux-async/src/store.js +++ /dev/null @@ -1,14 +0,0 @@ -import { createStore, applyMiddleware } from 'redux'; -import thunk from 'redux-thunk'; -import { createLogger } from 'redux-logger'; - -import reducer from './reducer'; - -const middlewares = process.env.NODE_ENV === 'development' ? - [thunk, createLogger()] : - [thunk]; - -export default createStore( - reducer, - applyMiddleware(...middlewares) -); diff --git a/fluent-react/examples/redux-sync/.gitignore b/fluent-react/examples/redux-sync/.gitignore deleted file mode 100644 index ba70f3893..000000000 --- a/fluent-react/examples/redux-sync/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -.cache -dist diff --git a/fluent-react/examples/redux-sync/package.json b/fluent-react/examples/redux-sync/package.json deleted file mode 100644 index c441cb68a..000000000 --- a/fluent-react/examples/redux-sync/package.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "name": "fluent-react-example-with-redux", - "version": "0.1.0", - "private": true, - "scripts": { - "start": "parcel serve public/index.html", - "build": "parcel build public/index.html" - }, - "dependencies": { - "delay": "^2.0.0", - "fluent": "^0.8.0", - "fluent-langneg": "^0.1.0", - "fluent-react": "file:../../", - "react": "^16.3.2", - "react-dom": "^16.3.3", - "react-redux": "^5.0.6", - "redux": "^3.7.2", - "redux-logger": "^3.0.6" - }, - "devDependencies": { - "parcel-bundler": "^1.9.7" - }, - "engines": { - "node": ">=10.0.0", - "browsers": "Firefox >= 57" - } -} diff --git a/fluent-react/examples/redux-sync/src/App.js b/fluent-react/examples/redux-sync/src/App.js deleted file mode 100644 index a3681f3bb..000000000 --- a/fluent-react/examples/redux-sync/src/App.js +++ /dev/null @@ -1,36 +0,0 @@ -import React from 'react'; -import { connect} from 'react-redux'; -import { Localized } from 'fluent-react/compat'; - -import { changeLocales } from './actions'; - -function App(props) { - const { currentLocales, changeLocales } = props; - - const [current] = currentLocales; - const available = ['en-US', 'pl']; - const next = available[(available.indexOf(current ) + 1) % available.length]; - - return ( -
- -

Hello, world!

-
- - -

{'Current locale: { $locale }'}

-
- - - - -
- ); -} - -const mapStateToProps = state => ({ currentLocales: state.currentLocales }); -const mapDispatchToProps = { changeLocales }; - -export default connect(mapStateToProps, mapDispatchToProps)(App); diff --git a/fluent-react/examples/redux-sync/src/actions.js b/fluent-react/examples/redux-sync/src/actions.js deleted file mode 100644 index 5a122cf83..000000000 --- a/fluent-react/examples/redux-sync/src/actions.js +++ /dev/null @@ -1,38 +0,0 @@ -import { FluentBundle } from 'fluent/compat'; -import { negotiateLanguages } from 'fluent-langneg/compat'; - -const MESSAGES_ALL = { - 'pl': ` -title = Witaj świecie! -current = Bieżący język: { $locale } -change = Zmień na { $locale } - `, - 'en-US': ` -title = Hello, world! -current = Current locale: { $locale } -change = Change to { $locale } - `, -}; - -export function changeLocales(userLocales) { - const currentLocales = negotiateLanguages( - userLocales, - ['en-US', 'pl'], - { defaultLocale: 'en-US' } - ); - - const generateBundles = function* () { - for (const locale of currentLocales) { - const bundle = new FluentBundle(locale); - bundle.addMessages(MESSAGES_ALL[locale]); - yield bundle; - } - } - - return { - type: 'CHANGE_LOCALES', - userLocales, - currentLocales, - bundles: generateBundles() - }; -} diff --git a/fluent-react/examples/redux-sync/src/index.js b/fluent-react/examples/redux-sync/src/index.js deleted file mode 100644 index 0681013db..000000000 --- a/fluent-react/examples/redux-sync/src/index.js +++ /dev/null @@ -1,16 +0,0 @@ -import React from 'react'; -import ReactDOM from 'react-dom'; -import { Provider } from 'react-redux'; - -import store from './store'; -import AppLocalizationProvider from './l10n'; -import App from './App'; - -ReactDOM.render( - - - - - , - document.getElementById('root') -); diff --git a/fluent-react/examples/redux-sync/src/l10n.js b/fluent-react/examples/redux-sync/src/l10n.js deleted file mode 100644 index b68c665fd..000000000 --- a/fluent-react/examples/redux-sync/src/l10n.js +++ /dev/null @@ -1,34 +0,0 @@ -import React, { Component } from 'react'; -import { connect } from 'react-redux'; - -import { LocalizationProvider } from 'fluent-react/compat'; - -import { changeLocales } from './actions'; - -class AppLocalizationProvider extends Component { - componentWillMount() { - this.props.changeLocales(navigator.languages); - } - - render() { - const { bundles, children } = this.props; - - if (!bundles) { - // Show a loader - return
; - } - - return ( - - {children} - - ); - } -} - -const mapStateToProps = state => ({ bundles: state.bundles }); -const mapDispatchToProps = { changeLocales }; - -export default connect(mapStateToProps, mapDispatchToProps)( - AppLocalizationProvider -); diff --git a/fluent-react/examples/redux-sync/src/reducer.js b/fluent-react/examples/redux-sync/src/reducer.js deleted file mode 100644 index 20dd93c19..000000000 --- a/fluent-react/examples/redux-sync/src/reducer.js +++ /dev/null @@ -1,19 +0,0 @@ -export default function reducer(state = { - userLocales: ['en-US'], - currentLocales: ['en-US'], - bundles: null -}, action) { - switch (action.type) { - case 'CHANGE_LOCALES': { - const { userLocales, currentLocales, bundles } = action; - return { - ...state, - userLocales, - currentLocales, - bundles - }; - } - default: - return state; - } -} diff --git a/fluent-react/examples/redux-sync/src/store.js b/fluent-react/examples/redux-sync/src/store.js deleted file mode 100644 index 68f500cd1..000000000 --- a/fluent-react/examples/redux-sync/src/store.js +++ /dev/null @@ -1,13 +0,0 @@ -import { createStore, applyMiddleware } from 'redux'; -import { createLogger } from 'redux-logger'; - -import reducer from './reducer'; - -const middlewares = process.env.NODE_ENV === 'development' ? - [createLogger()] : - []; - -export default createStore( - reducer, - applyMiddleware(...middlewares) -); diff --git a/fluent-react/examples/text-input/.gitignore b/fluent-react/examples/text-input/.gitignore deleted file mode 100644 index ba70f3893..000000000 --- a/fluent-react/examples/text-input/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -.cache -dist diff --git a/fluent-react/examples/text-input/package.json b/fluent-react/examples/text-input/package.json deleted file mode 100644 index 1baff8eb7..000000000 --- a/fluent-react/examples/text-input/package.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "name": "fluent-react-example-text-input", - "version": "0.1.0", - "private": true, - "scripts": { - "start": "parcel serve public/index.html", - "build": "parcel build public/index.html" - }, - "dependencies": { - "fluent": "^0.8.0", - "fluent-langneg": "^0.1.0", - "fluent-react": "file:../../", - "react": "^16.3.2", - "react-dom": "^16.3.3" - }, - "devDependencies": { - "parcel-bundler": "^1.9.7" - }, - "engines": { - "node": ">=10.0.0", - "browsers": "Firefox >= 57" - } -} diff --git a/fluent-react/examples/text-input/public/index.html b/fluent-react/examples/text-input/public/index.html deleted file mode 100644 index f34d4fe85..000000000 --- a/fluent-react/examples/text-input/public/index.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - Text input - a fluent-react example - - -
- - - diff --git a/fluent-react/examples/text-input/src/App.js b/fluent-react/examples/text-input/src/App.js deleted file mode 100644 index bc47f36f5..000000000 --- a/fluent-react/examples/text-input/src/App.js +++ /dev/null @@ -1,49 +0,0 @@ -import React, { Component } from 'react'; -import { Localized } from 'fluent-react/compat'; - -function Header(props) { - const { children } = props; - return ( -

{children}

- ); -} - -export default class App extends Component { - constructor(props) { - super(props); - this.state = { - name: '' - }; - } - - handleNameChange(name) { - this.setState({ name }); - } - - render() { - const { name } = this.state; - - return ( -
- { name ? - -
{'Hello, { $username }!'}
-
- : - -
Hello, stranger!
-
- } - - - this.handleNameChange(evt.target.value)} - value={name} - /> - -
- ); - } -} diff --git a/fluent-react/examples/text-input/src/index.js b/fluent-react/examples/text-input/src/index.js deleted file mode 100644 index f5205ea57..000000000 --- a/fluent-react/examples/text-input/src/index.js +++ /dev/null @@ -1,13 +0,0 @@ -import React from 'react'; -import ReactDOM from 'react-dom'; -import { LocalizationProvider } from 'fluent-react/compat'; - -import { generateBundles } from './l10n'; -import App from './App'; - -ReactDOM.render( - - - , - document.getElementById('root') -); diff --git a/fluent-react/examples/text-input/src/l10n.js b/fluent-react/examples/text-input/src/l10n.js deleted file mode 100644 index f19cf8dda..000000000 --- a/fluent-react/examples/text-input/src/l10n.js +++ /dev/null @@ -1,32 +0,0 @@ -import { FluentBundle } from 'fluent/compat'; -import { negotiateLanguages } from 'fluent-langneg/compat'; - -const MESSAGES_ALL = { - 'pl': ` -hello = Cześć { $username }! -hello-no-name = Witaj nieznajomy! -type-name = - .placeholder = Twoje imię - `, - 'en-US': ` -hello = Hello, { $username }! -hello-no-name = Hello, stranger! -type-name = - .placeholder = Your name - `, -}; - -export function* generateBundles(userLocales) { - // Choose locales that are best for the user. - const currentLocales = negotiateLanguages( - userLocales, - ['en-US', 'pl'], - { defaultLocale: 'en-US' } - ); - - for (const locale of currentLocales) { - const bundle = new FluentBundle(locale); - bundle.addMessages(MESSAGES_ALL[locale]); - yield bundle; - } -}