fix localization

This commit is contained in:
Salvatore Giordano
2020-03-08 23:30:49 +01:00
parent d17678dc8d
commit 28e5cd8a7f
5 changed files with 33 additions and 5 deletions

View File

@@ -1,3 +1,7 @@
## 1.3.3
- Fix a bug in localization
## 1.3.2 ## 1.3.2
- Add `enable` property in order to use the disable the button - Add `enable` property in order to use the disable the button

View File

@@ -46,6 +46,24 @@ void _onCountryChange(CountryCode countryCode) {
``` ```
### i18n
Just add the `CountryLocalizations.delegate` in the list of your app delegates
```dart
return new MaterialApp(
supportedLocales: [
Locale('en'),
Locale('it'),
Locale('en'),
],
localizationsDelegates: [
CountryLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
```
## Contributions ## Contributions
Contributions of any kind are more than welcome! Feel free to fork and improve country_code_picker in any way you want, make a pull request, or open an issue. Contributions of any kind are more than welcome! Feel free to fork and improve country_code_picker in any way you want, make a pull request, or open an issue.

View File

@@ -83,7 +83,7 @@ class _MyAppState extends State<MyApp> {
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
child: CountryCodePicker( child: CountryCodePicker(
enabled: false, enabled: false,
onChanged: print, onChanged: (c) => c.name,
initialSelection: 'TF', initialSelection: 'TF',
showCountryOnly: true, showCountryOnly: true,
showOnlyCountryWhenClosed: true, showOnlyCountryWhenClosed: true,

View File

@@ -41,6 +41,12 @@ class CountryCode {
return CountryCode.fromJson(jsonCode); return CountryCode.fromJson(jsonCode);
} }
CountryCode localize(BuildContext context) {
return this
..name =
CountryLocalizations.of(context)?.translate(this.code) ?? this.name;
}
factory CountryCode.fromJson(Map<String, dynamic> json) { factory CountryCode.fromJson(Map<String, dynamic> json) {
return CountryCode( return CountryCode(
name: json['name'], name: json['name'],

View File

@@ -90,7 +90,7 @@ class _CountryCodePickerState extends State<CountryCodePicker> {
if (widget.builder != null) if (widget.builder != null)
_widget = InkWell( _widget = InkWell(
onTap: _showSelectionDialog, onTap: _showSelectionDialog,
child: widget.builder(selectedItem), child: widget.builder(selectedItem.localize(context)),
); );
else { else {
_widget = FlatButton( _widget = FlatButton(
@@ -200,13 +200,13 @@ class _CountryCodePickerState extends State<CountryCodePicker> {
void _publishSelection(CountryCode e) { void _publishSelection(CountryCode e) {
if (widget.onChanged != null) { if (widget.onChanged != null) {
widget.onChanged(e); widget.onChanged(e.localize(context));
} }
} }
void _onInit(CountryCode initialData) { void _onInit(CountryCode e) {
if (widget.onInit != null) { if (widget.onInit != null) {
widget.onInit(initialData); widget.onInit(e.localize(context));
} }
} }
} }