Skip to content

Commit a5c4b1f

Browse files
committed
Started working on internationalization
1 parent d307aa6 commit a5c4b1f

20 files changed

+667
-26
lines changed

example/lib/main.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import 'package:flutter/cupertino.dart';
22
import 'package:flutter/material.dart';
3+
import 'package:flutter_form_builder/flutter_form_builder.dart';
4+
import 'package:flutter_localizations/flutter_localizations.dart';
35

46
import 'home_page.dart';
57

@@ -16,6 +18,15 @@ class MyApp extends StatelessWidget {
1618
labelStyle: TextStyle(color: Colors.purple),
1719
),
1820
),
21+
localizationsDelegates: [
22+
FormBuilderLocalizationsDelegate(),
23+
GlobalMaterialLocalizations.delegate,
24+
GlobalWidgetsLocalizations.delegate,
25+
],
26+
supportedLocales: [
27+
Locale('en', ''),
28+
Locale('es', ''),
29+
],
1930
home: HomePage(),
2031
);
2132
}

example/lib/sources/complete_form.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class CompleteFormState extends State<CompleteForm> {
2727

2828
@override
2929
Widget build(BuildContext context) {
30+
print(Localizations.localeOf(context));
3031
return Padding(
3132
padding: EdgeInsets.all(10),
3233
child: SingleChildScrollView(
@@ -245,7 +246,7 @@ class CompleteFormState extends State<CompleteForm> {
245246
),
246247
),
247248
validator: FormBuilderValidators.compose([
248-
FormBuilderValidators.requiredTrue(
249+
FormBuilderValidators.requireTrue(
249250
errorText:
250251
'You must accept terms and conditions to continue',
251252
),
@@ -445,7 +446,6 @@ class CompleteFormState extends State<CompleteForm> {
445446
border: OutlineInputBorder(),
446447
),
447448
attribute: 'signature',
448-
clearButtonText: 'Start Over',
449449
border: Border.all(color: Colors.green),
450450
onChanged: _onChanged,
451451
),
@@ -460,7 +460,7 @@ class CompleteFormState extends State<CompleteForm> {
460460
},
461461
colorPickerType: ColorPickerType.ColorPicker,
462462
validator: FormBuilderValidators.compose([
463-
FormBuilderValidators.required(),
463+
FormBuilderValidators.required(errorText: FormBuilderLocalizations.of(context).requiredErrorText),
464464
]),
465465
// readOnly: true,
466466
),

example/pubspec.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ environment:
99
dependencies:
1010
flutter:
1111
sdk: flutter
12+
flutter_localizations:
13+
sdk: flutter
1214

1315
flutter_form_builder:
1416
path: ../
@@ -18,6 +20,7 @@ dependencies:
1820
dev_dependencies:
1921
flutter_test:
2022
sdk: flutter
23+
intl_translation:
2124

2225
flutter:
2326
uses-material-design: true

lib/flutter_form_builder.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ library flutter_form_builder;
33
export 'package:flutter_typeahead/flutter_typeahead.dart';
44
export 'package:signature/signature.dart';
55

6+
export './localization/form_builder_localizations.dart';
67
export './src/fields/form_builder_checkbox.dart';
78
export './src/fields/form_builder_checkbox_list.dart';
89
export './src/fields/form_builder_chips_input.dart';

lib/l10n/intl_en.arb

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
{
2+
"@@last_modified": "2020-06-19T21:53:39.706877",
3+
"requiredErrorText": "This field cannot be empty.",
4+
"@requiredErrorText": {
5+
"description": "Error Text for required field",
6+
"type": "text",
7+
"placeholders": {}
8+
},
9+
"requireTrueErrorText": "This field must be set to true.",
10+
"@requireTrueErrorText": {
11+
"description": "Error Text for required field",
12+
"type": "text",
13+
"placeholders": {}
14+
},
15+
"minErrorText": "Value must be greater than or equal to {min}.",
16+
"@minErrorText": {
17+
"description": "Error Text for required field",
18+
"type": "text",
19+
"placeholders": {
20+
"min": {}
21+
}
22+
},
23+
"minLengthErrorText": "Value must have a length greater than or equal to {minLength}",
24+
"@minLengthErrorText": {
25+
"description": "Error Text for required field",
26+
"type": "text",
27+
"placeholders": {
28+
"minLength": {}
29+
}
30+
},
31+
"maxErrorText": "Value must be less than or equal to {max}",
32+
"@maxErrorText": {
33+
"description": "Error Text for required field",
34+
"type": "text",
35+
"placeholders": {
36+
"max": {}
37+
}
38+
},
39+
"maxLengthErrorText": "Value must have a length less than or equal to {maxLength}",
40+
"@maxLengthErrorText": {
41+
"description": "Error Text for required field",
42+
"type": "text",
43+
"placeholders": {
44+
"maxLength": {}
45+
}
46+
},
47+
"emailErrorText": "This field requires a valid email address.",
48+
"@emailErrorText": {
49+
"description": "Error Text for email field",
50+
"type": "text",
51+
"placeholders": {}
52+
},
53+
"urlErrorText": "This field requires a valid URL address.",
54+
"@urlErrorText": {
55+
"description": "Error Text for URL field",
56+
"type": "text",
57+
"placeholders": {}
58+
},
59+
"patternErrorText": "Value does not match pattern.",
60+
"@patternErrorText": {
61+
"description": "Error Text for pattern field",
62+
"type": "text",
63+
"placeholders": {}
64+
},
65+
"numericErrorText": "Value must be numeric.",
66+
"@numericErrorText": {
67+
"description": "Error Text for numeric field",
68+
"type": "text",
69+
"placeholders": {}
70+
},
71+
"creditCardErrorText": "This field requires a valid credit card number.",
72+
"@creditCardErrorText": {
73+
"description": "Error Text for credit card field",
74+
"type": "text",
75+
"placeholders": {}
76+
},
77+
"ipErrorText": "This field requires a valid IP.",
78+
"@ipErrorText": {
79+
"description": "Error Text for IP address field",
80+
"type": "text",
81+
"placeholders": {}
82+
},
83+
"dateStringErrorText": "This field requires a valid date string.",
84+
"@dateStringErrorText": {
85+
"description": "Error Text for date string field",
86+
"type": "text",
87+
"placeholders": {}
88+
}
89+
}

lib/l10n/intl_es.arb

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
{
2+
"@@last_modified": "2020-06-19T21:53:39.706877",
3+
"requiredErrorText": "Este campo no puede estar vacío.",
4+
"@requiredErrorText": {
5+
"description": "Error Text for required field",
6+
"type": "text",
7+
"placeholders": {}
8+
},
9+
"requireTrueErrorText": "This field must be set to true.",
10+
"@requireTrueErrorText": {
11+
"description": "Error Text for required field",
12+
"type": "text",
13+
"placeholders": {}
14+
},
15+
"minErrorText": "Value must be greater than or equal to {min}.",
16+
"@minErrorText": {
17+
"description": "Error Text for required field",
18+
"type": "text",
19+
"placeholders": {
20+
"min": {}
21+
}
22+
},
23+
"minLengthErrorText": "Value must have a length greater than or equal to {minLength}",
24+
"@minLengthErrorText": {
25+
"description": "Error Text for required field",
26+
"type": "text",
27+
"placeholders": {
28+
"minLength": {}
29+
}
30+
},
31+
"maxErrorText": "Value must be less than or equal to {max}",
32+
"@maxErrorText": {
33+
"description": "Error Text for required field",
34+
"type": "text",
35+
"placeholders": {
36+
"max": {}
37+
}
38+
},
39+
"maxLengthErrorText": "Value must have a length less than or equal to {maxLength}",
40+
"@maxLengthErrorText": {
41+
"description": "Error Text for required field",
42+
"type": "text",
43+
"placeholders": {
44+
"maxLength": {}
45+
}
46+
},
47+
"emailErrorText": "This field requires a valid email address.",
48+
"@emailErrorText": {
49+
"description": "Error Text for email field",
50+
"type": "text",
51+
"placeholders": {}
52+
},
53+
"urlErrorText": "This field requires a valid URL address.",
54+
"@urlErrorText": {
55+
"description": "Error Text for URL field",
56+
"type": "text",
57+
"placeholders": {}
58+
},
59+
"patternErrorText": "Value does not match pattern.",
60+
"@patternErrorText": {
61+
"description": "Error Text for pattern field",
62+
"type": "text",
63+
"placeholders": {}
64+
},
65+
"numericErrorText": "Value must be numeric.",
66+
"@numericErrorText": {
67+
"description": "Error Text for numeric field",
68+
"type": "text",
69+
"placeholders": {}
70+
},
71+
"creditCardErrorText": "This field requires a valid credit card number.",
72+
"@creditCardErrorText": {
73+
"description": "Error Text for credit card field",
74+
"type": "text",
75+
"placeholders": {}
76+
},
77+
"ipErrorText": "This field requires a valid IP.",
78+
"@ipErrorText": {
79+
"description": "Error Text for IP address field",
80+
"type": "text",
81+
"placeholders": {}
82+
},
83+
"dateStringErrorText": "This field requires a valid date string.",
84+
"@dateStringErrorText": {
85+
"description": "Error Text for date string field",
86+
"type": "text",
87+
"placeholders": {}
88+
}
89+
}

lib/l10n/intl_messages.arb

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
{
2+
"@@last_modified": "2020-06-19T21:53:39.706877",
3+
"requiredErrorText": "This field cannot be empty.",
4+
"@requiredErrorText": {
5+
"description": "Error Text for required field",
6+
"type": "text",
7+
"placeholders": {}
8+
},
9+
"requireTrueErrorText": "This field must be set to true.",
10+
"@requireTrueErrorText": {
11+
"description": "Error Text for required field",
12+
"type": "text",
13+
"placeholders": {}
14+
},
15+
"minErrorText": "Value must be greater than or equal to {min}.",
16+
"@minErrorText": {
17+
"description": "Error Text for required field",
18+
"type": "text",
19+
"placeholders": {
20+
"min": {}
21+
}
22+
},
23+
"minLengthErrorText": "Value must have a length greater than or equal to {minLength}",
24+
"@minLengthErrorText": {
25+
"description": "Error Text for required field",
26+
"type": "text",
27+
"placeholders": {
28+
"minLength": {}
29+
}
30+
},
31+
"maxErrorText": "Value must be less than or equal to {max}",
32+
"@maxErrorText": {
33+
"description": "Error Text for required field",
34+
"type": "text",
35+
"placeholders": {
36+
"max": {}
37+
}
38+
},
39+
"maxLengthErrorText": "Value must have a length less than or equal to {maxLength}",
40+
"@maxLengthErrorText": {
41+
"description": "Error Text for required field",
42+
"type": "text",
43+
"placeholders": {
44+
"maxLength": {}
45+
}
46+
},
47+
"emailErrorText": "This field requires a valid email address.",
48+
"@emailErrorText": {
49+
"description": "Error Text for email field",
50+
"type": "text",
51+
"placeholders": {}
52+
},
53+
"urlErrorText": "This field requires a valid URL address.",
54+
"@urlErrorText": {
55+
"description": "Error Text for URL field",
56+
"type": "text",
57+
"placeholders": {}
58+
},
59+
"patternErrorText": "Value does not match pattern.",
60+
"@patternErrorText": {
61+
"description": "Error Text for pattern field",
62+
"type": "text",
63+
"placeholders": {}
64+
},
65+
"numericErrorText": "Value must be numeric.",
66+
"@numericErrorText": {
67+
"description": "Error Text for numeric field",
68+
"type": "text",
69+
"placeholders": {}
70+
},
71+
"creditCardErrorText": "This field requires a valid credit card number.",
72+
"@creditCardErrorText": {
73+
"description": "Error Text for credit card field",
74+
"type": "text",
75+
"placeholders": {}
76+
},
77+
"ipErrorText": "This field requires a valid IP.",
78+
"@ipErrorText": {
79+
"description": "Error Text for IP address field",
80+
"type": "text",
81+
"placeholders": {}
82+
},
83+
"dateStringErrorText": "This field requires a valid date string.",
84+
"@dateStringErrorText": {
85+
"description": "Error Text for date string field",
86+
"type": "text",
87+
"placeholders": {}
88+
}
89+
}

0 commit comments

Comments
 (0)