-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(@fluent/react) Add changeLocales and currentLocales on provider
- Loading branch information
Showing
8 changed files
with
53 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from "react"; | ||
import { useLocalization } from "@fluent/react"; | ||
import { AVAILABLE_LOCALES } from "./l10n"; | ||
|
||
export function LanguageSelector() { | ||
const { changeLocales, currentLocales } = useLocalization() | ||
|
||
return ( | ||
<select | ||
onChange={event => changeLocales([event.target.value])} | ||
value={currentLocales[0]}> | ||
{Object.entries(AVAILABLE_LOCALES).map( | ||
([code, name]) => <option key={code} value={code}>{name}</option> | ||
)} | ||
</select> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
import { createContext } from "react"; | ||
import { ReactLocalization } from "./localization"; | ||
|
||
export let FluentContext = createContext(new ReactLocalization([], null)); | ||
const defaultValue = { | ||
l10n: new ReactLocalization([], null), | ||
changeLocales: (_changeLocales: string[]) => undefined as void, | ||
currentLocales: [] as string[], | ||
}; | ||
|
||
export let FluentContext = createContext(defaultValue); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters