File tree Expand file tree Collapse file tree 4 files changed +33
-23
lines changed Expand file tree Collapse file tree 4 files changed +33
-23
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,12 @@ import 'package:flutter_localization/model/local_file.dart';
4
4
5
5
class LocalizationSettings {
6
6
/// Path to the localisation file in app bundle
7
- final String localisationFilePath;
7
+ /// Use either [localisationFilePath] or [localisationJson]
8
+ final String ? localisationFilePath;
9
+
10
+ /// Localisation json
11
+ /// Use either [localisationFilePath] or [localisationJson]
12
+ final String ? localisationJson;
8
13
9
14
/// The [supportedLanguages] of the app.
10
15
///
@@ -17,8 +22,11 @@ class LocalizationSettings {
17
22
final List <LocalFile > localFiles;
18
23
19
24
LocalizationSettings ({
20
- required this .localisationFilePath,
25
+ this .localisationFilePath,
26
+ this .localisationJson,
21
27
this .supportedLanguages = const ['en' ],
22
28
this .localFiles = const [],
23
- }) : assert (supportedLanguages.length > 0 , 'supportedLanguages cannot be empty' );
29
+ }) : assert (supportedLanguages.length > 0 , 'supportedLanguages cannot be empty' ),
30
+ assert (localisationFilePath != null || localisationJson != null ,
31
+ 'localisationFilePath or localisationJson must not be null' );
24
32
}
Original file line number Diff line number Diff line change 1
1
import 'dart:convert' ;
2
- import 'dart:ui' ;
3
2
4
3
import 'package:flutter_localization/model/localization_settings.dart' ;
5
4
import 'package:flutter_localization/model/localized_string.dart' ;
@@ -44,8 +43,8 @@ class LocalizationService {
44
43
}
45
44
46
45
Future <void > _readLocalization () async {
47
- final Map < String , dynamic > localizationMap =
48
- jsonDecode (await rootBundle. loadString (_settings.localisationFilePath) );
46
+ final localizationJson = _settings.localisationJson ?? await rootBundle. loadString (_settings.localisationFilePath ! );
47
+ final Map < String , dynamic > localizationMap = jsonDecode (localizationJson );
49
48
_initLocalizationStringFromJsonMap (localizationMap);
50
49
}
51
50
@@ -122,13 +121,10 @@ class LocalizationService {
122
121
}
123
122
124
123
Future <String ?> getLocalizedLocalFile (String id) async {
125
- var localFile =
126
- _settings.localFiles.firstWhereOrNull ((file) => file.id == id && file.langCode == currentLanguageCode);
124
+ var localFile = _settings.localFiles.firstWhereOrNull ((file) => file.id == id && file.langCode == currentLanguageCode);
127
125
if (localFile == null ) {
128
- print (
129
- 'flutter_localization: Local file with id: $id not found for current language. Fallback to default language' );
130
- localFile =
131
- _settings.localFiles.firstWhereOrNull ((file) => file.id == id && file.langCode == defaultLanguageCode);
126
+ print ('flutter_localization: Local file with id: $id not found for current language. Fallback to default language' );
127
+ localFile = _settings.localFiles.firstWhereOrNull ((file) => file.id == id && file.langCode == defaultLanguageCode);
132
128
}
133
129
if (localFile == null ) {
134
130
print ('flutter_localization: Local file with id: $id not found for default language' );
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ packages:
7
7
name: async
8
8
url: "https://pub.dartlang.org"
9
9
source: hosted
10
- version: "2.6.1 "
10
+ version: "2.8.2 "
11
11
boolean_selector:
12
12
dependency: transitive
13
13
description:
@@ -21,14 +21,14 @@ packages:
21
21
name: characters
22
22
url: "https://pub.dartlang.org"
23
23
source: hosted
24
- version: "1.1 .0"
24
+ version: "1.2 .0"
25
25
charcode:
26
26
dependency: transitive
27
27
description:
28
28
name: charcode
29
29
url: "https://pub.dartlang.org"
30
30
source: hosted
31
- version: "1.2.0 "
31
+ version: "1.3.1 "
32
32
clock:
33
33
dependency: transitive
34
34
description:
@@ -85,14 +85,21 @@ packages:
85
85
name: matcher
86
86
url: "https://pub.dartlang.org"
87
87
source: hosted
88
- version: "0.12.10"
88
+ version: "0.12.11"
89
+ material_color_utilities:
90
+ dependency: transitive
91
+ description:
92
+ name: material_color_utilities
93
+ url: "https://pub.dartlang.org"
94
+ source: hosted
95
+ version: "0.1.3"
89
96
meta:
90
97
dependency: transitive
91
98
description:
92
99
name: meta
93
100
url: "https://pub.dartlang.org"
94
101
source: hosted
95
- version: "1.3 .0"
102
+ version: "1.7 .0"
96
103
path:
97
104
dependency: transitive
98
105
description:
@@ -146,7 +153,7 @@ packages:
146
153
name: test_api
147
154
url: "https://pub.dartlang.org"
148
155
source: hosted
149
- version: "0.3.0 "
156
+ version: "0.4.8 "
150
157
typed_data:
151
158
dependency: transitive
152
159
description:
@@ -160,7 +167,7 @@ packages:
160
167
name: vector_math
161
168
url: "https://pub.dartlang.org"
162
169
source: hosted
163
- version: "2.1.0 "
170
+ version: "2.1.1 "
164
171
sdks:
165
- dart: ">=2.12 .0 <3.0.0"
172
+ dart: ">=2.14 .0 <3.0.0"
166
173
flutter: ">=1.20.0"
Original file line number Diff line number Diff line change 1
1
name : flutter_localization
2
2
description : Flutter Localization
3
- version : 2.0.0
4
- author : Filip Rajicic
5
- homepage : www.credeo.de
3
+ version : 2.1.0
4
+ homepage : www.credeo.rs
6
5
7
6
environment :
8
7
sdk : " >=2.12.0 <3.0.0"
You can’t perform that action at this time.
0 commit comments