React Native
Add your provider directly in
App.(js|tsx)
import { StyleSheet, Text, View } from "react-native";
import { Talkr } from "talkr";
import en from "./src/i18n/en.json";
import fr from "./src/i18n/fr.json";
import MyComponent from "./src/MyComponent";
export default function App() {
return (
<Talkr languages={{ en, fr }} defaultLanguage="en">
<View style={styles.container}>
<MyComponent />
</View>
</Talkr>
);
}
All the exemples above are valid in React Native. You only have to replace html tags (
div
,h1
, etc.) byText
.Since
Intl
api is not available in React Native, thecount
param will only return three types of plural keys:zero
,one
andmany
. Please adjust your json files accordingly.
import React, { Text, Button } from "react-native";
import { useState } from "react";
import { useT } from "talkr";
export default function MyComponent() {
const { T } = useT();
const [count, setCount] = useState(0);
return (
<>
<Text>{T("hello")}</Text>
<Text>
{T("user.describe.complex", { name: "joe", hobby: "coding" })}
</Text>
<Text>{T("message-count", { count })}</Text>
<Button onPress={() => setCount(count + 1)} title="+1" />
</>
);
}
Last updated