-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmobile-i18n-strings.mdc
More file actions
77 lines (54 loc) · 1.98 KB
/
mobile-i18n-strings.mdc
File metadata and controls
77 lines (54 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
---
description: Flag hardcoded user-facing strings that are not wrapped in a translation function. Catches strings in JSX text nodes and Flutter Text widgets that bypass the i18n layer.
alwaysApply: false
globs:
- "**/*.ts"
- "**/*.tsx"
- "**/*.dart"
standards-version: 1.6.3
---
# I18n Strings
Flag these internationalization issues:
## Hardcoded strings in JSX
- A `<Text>` component contains a raw string literal instead of a translation call like `t("key")` or `intl.formatMessage()`.
- String props that are user-visible (placeholder, title, label, accessibilityLabel) use a hardcoded English string instead of a translated value.
- Exception: strings that are not user-facing (testID values, console.log messages, error codes) do not need translation.
**Fix:** Wrap the string in a translation function:
```tsx
// Before
<Text>Welcome back</Text>
// After
<Text>{t("home.welcomeBack")}</Text>
```
## Hardcoded strings in Flutter Text widgets
- A `Text()` widget contains a raw string literal instead of `AppLocalizations.of(context)!.key` or equivalent.
- Exception: debug-only strings, Key values, and route names do not need translation.
**Fix:**
```dart
// Before
Text('Welcome back')
// After
Text(AppLocalizations.of(context)!.welcomeBack)
```
## String concatenation for sentences
- Building user-visible sentences with `+` or template literals instead of using interpolation in the translation file. Concatenation breaks in languages with different word order.
**Fix:** Use interpolation parameters:
```tsx
// Before
<Text>{"Hello " + user.name}</Text>
// After
<Text>{t("greeting", { name: user.name })}</Text>
```
With the translation file:
```json
{ "greeting": "Hello {{name}}" }
```
## Missing plural forms
- Displaying counts with simple conditional (`count === 1 ? "item" : "items"`) instead of ICU plural syntax in the translation file.
**Fix:** Use plural-aware translation keys:
```json
{
"itemCount_one": "{{count}} item",
"itemCount_other": "{{count}} items"
}
```