You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is done automatically when the app starts, but if you want to build in a language selector, you can use this method to highlight the currently selected language.
76
79
77
-
### Full example
78
-
See the 'example' folder for a complete example.
80
+
## Examples
81
+
### Basic translation (tl)
82
+
```json
83
+
{
84
+
"English": "English"
85
+
}
86
+
```
87
+
```dart
88
+
Text(tl('English'));
89
+
```
90
+
91
+
### Translation with a variable (tlv)
92
+
```json
93
+
"{0} has won the game!": "{0} has won the game!"
94
+
```
95
+
```dart
96
+
Text(tlv('{0} has won the game!', 'David'));
97
+
```
98
+
99
+
### Translation with multiple variables (tlvm)
100
+
```json
101
+
"He came in {0}, while his partner came in at the {1} place": "He came in {0}, while his partner came in at the {1} place",
102
+
```
103
+
```dart
104
+
Text(tlvm('He came in {0}, while his partner came in at the {1} place', ['first', 'second']));
105
+
```
106
+
107
+
### Pluralization (tlp)
108
+
```json
109
+
"I have {0} apples": {
110
+
"zero": "I have no apples",
111
+
"one": "I have 1 apple",
112
+
"other": "I have {0} apples"
113
+
},
114
+
```
115
+
```dart
116
+
Text(tlp('I have {0} apples', 0)); // I have no apples
117
+
Text(tlp('I have {0} apples', 1)); // I have 1 apple
118
+
Text(tlp('I have {0} apples', 5)); // I have 5 apples
119
+
```
79
120
121
+
### Pluralization with multiple counts (tlpm)
122
+
```json
123
+
"I have {0} strawberries and {1} bananas": {
124
+
"zero_zero": "I have no strawberries and no bananas",
125
+
"one_one": "I have 1 strawberry and 1 banana",
126
+
"one_other": "I have 1 strawberry and {1} bananas",
127
+
"other_one": "I have {0} strawberries and 1 banana",
128
+
"other_other": "I have bo strawberries and {1} bananas"
129
+
}
130
+
```
80
131
81
-
## Additional features
82
-
More features could be implemented. As my time is limited, feel free to open an issue and I will look into when I have time.
83
-
- Planned for Q3: a dropdown menu to select the language
132
+
```dart
133
+
Text(tlpm('I have {0} strawberries and {1} bananas', [1, 1])); // I have 1 strawberry and 1 banana
134
+
Text(tlpm('I have {0} strawberries and {1} bananas', [0, 0])); // I have no strawberries and no bananas
135
+
Text(tlpm('I have {0} strawberries and {1} bananas', [2, 3])); // I have bo strawberries and 3 bananas
136
+
```
84
137
85
-
## Credits
86
-
All this is possible because of the best state management package out there: [Signals](https://pub.dev/packages/signals). Credits should go there :)
138
+
#### Note on pluralization:
139
+
For English, the text 'I have no strawberries and no bananas' is grammarly same as 'I have 0 strawberries and 0 bananas'. That means that you don't have to add a 'zero' entry for 'no strawberries and no bananas'. zero and other is sufficient. But for
140
+
See the 'example' folder for a complete example.
87
141
88
142
## Development
89
-
Publish extension using dart pub publish --dry-run
143
+
Publish extension using dart pub publish --dry-run
144
+
145
+
## Considerations
146
+
* Plural 'like there are / is 5 / winners' is not supported yet, might consider ICU here for the future..
0 commit comments