Skip to content

Commit be203ae

Browse files
committed
handle persist flag
1 parent c516955 commit be203ae

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

README.md

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,60 +53,65 @@ const App = () => {
5353
**Basic usage:**
5454

5555
```typescript
56+
import { View, Text } from "react-native";
5657
import { useAutoTranslate } from "react-native-autolocalise";
5758

5859
const MyComponent = () => {
5960
const { t, loading, error } = useAutoTranslate();
6061

6162
return (
62-
<div>
63-
<h1>{t("Welcome to our app!", false)}</h1>
64-
<p>{t("This text will be automatically translated")}</p>
65-
<p style={{ color: "black" }}>
66-
welcome
67-
<p style={{ color: "read" }}> to </p>our app
68-
</p>
69-
</div>
63+
<View>
64+
<Text>{t("Welcome to our app!", false)}</Text>
65+
<Text>{t("This text will be automatically translated")}</Text>
66+
</View>
7067
);
7168
};
7269
```
7370

7471
**Use with nested text formatting:**
7572

7673
```typescript
74+
import { Text, View } from "react-native";
7775
import { useAutoTranslate, FormattedText } from "react-native-autolocalise";
7876

7977
const MyComponent = () => {
8078
const { t } = useAutoTranslate();
8179

8280
return (
83-
<FormattedText>
84-
<Text>
85-
Hello, we <Text style={{ color: "red" }}>want</Text> you to be{" "}
86-
<Text style={{ fontWeight: "bold" }}>happy</Text>!
87-
</Text>
88-
</FormattedText>
81+
<View>
82+
<FormattedText>
83+
<Text>
84+
Hello, we <Text style={{ color: "red" }}>want</Text> you to be{" "}
85+
<Text style={{ fontWeight: "bold" }}>happy</Text>!
86+
</Text>
87+
</FormattedText>
88+
<FormattedText persist={false}>
89+
Hello,
90+
<Text style={{ color: "red" }}>World</Text>
91+
</FormattedText>
92+
</View>
8993
);
9094
};
9195
```
9296

9397
**Use with params:**
9498

9599
```typescript
100+
import { View, Text } from "react-native";
96101
import { useAutoTranslate } from "react-native-autolocalise";
97102

98103
const MyComponent = () => {
99104
const { t } = useAutoTranslate();
100105
const name = "John";
101106

102107
return (
103-
<div>
104-
<p>
108+
<View>
109+
<Text>
105110
{t("Welcome, {{1}}!, Nice to meet you. {{2}}.")
106111
.replace("{{1}}", name)
107112
.replace("{{2}}", t("Have a great day!"))}
108-
</p>
109-
</div>
113+
</Text>
114+
</View>
110115
);
111116
};
112117
```

src/components/FormattedText.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,17 @@ import { useAutoTranslate } from "../context/TranslationContext";
1717
interface FormattedTextProps {
1818
children: React.ReactNode;
1919
style?: TextStyle;
20+
/**
21+
* Whether to persist the text for review in the dashboard.
22+
* @default true
23+
*/
24+
persist?: boolean;
2025
}
2126

2227
export const FormattedText: React.FC<FormattedTextProps> = ({
2328
children,
2429
style,
30+
persist = true,
2531
}) => {
2632
const { t } = useAutoTranslate();
2733

@@ -88,7 +94,7 @@ export const FormattedText: React.FC<FormattedTextProps> = ({
8894
};
8995

9096
const { text, styles } = extractTextAndStyles(children);
91-
const translatedText = t(text);
97+
const translatedText = t(text, persist);
9298

9399
return <Text style={style}>{restoreStyledText(translatedText, styles)}</Text>;
94100
};

0 commit comments

Comments
 (0)