@@ -3,6 +3,9 @@ import 'package:flutter/services.dart';
3
3
import 'package:flutter_localizations/flutter_localizations.dart' ;
4
4
import 'package:global_refresh/global_refresh.dart' ;
5
5
import 'package:go_router/go_router.dart' ;
6
+ import 'package:stringcare/src/compile/stringcare_impl.dart' as compile;
7
+ import 'package:stringcare/src/i18n/app_localizations_interface.dart' ;
8
+ import 'package:stringcare/src/i18n/app_localizations_test.dart' ;
6
9
import 'package:stringcare/src/web/stringcare_impl.dart'
7
10
if (dart.library.io) 'package:stringcare/src/native/stringcare_impl.dart' ;
8
11
@@ -40,7 +43,18 @@ class Stringcare {
40
43
return _instance! ;
41
44
}
42
45
46
+ /// Disables native libs (.so and .dylib) and uses the Dart implementation.
47
+ var disableNative = false ;
48
+
49
+ /// Defines the origin of the text resources. When the encrypted mode is TRUE,
50
+ /// the encrypted resources are consumed, otherwise the original unencrypted
51
+ /// resources are used.
52
+ var useEncrypted = true ;
53
+
43
54
var langPath = "lang" ;
55
+ var langBasePath = "lang_base" ;
56
+
57
+ String get languageOrigin => useEncrypted ? langPath : langBasePath;
44
58
45
59
String ? Function () withLang = () {
46
60
return null ;
@@ -52,16 +66,28 @@ class Stringcare {
52
66
53
67
List <Locale > locales = [Locale ('en' )];
54
68
55
- List <LocalizationsDelegate <dynamic >> delegates = [
69
+ List <LocalizationsDelegate <dynamic >> commonDelegates = [
56
70
FallbackCupertinoLocalisationsDelegate (),
57
- // A class which loads the translations from JSON files
58
- AppLocalizations .delegate,
59
71
// Built-in localization of basic text for Material widgets
60
72
GlobalMaterialLocalizations .delegate,
61
73
// Built-in localization for text direction LTR/RTL
62
74
GlobalWidgetsLocalizations .delegate,
63
75
];
64
76
77
+ List <LocalizationsDelegate <dynamic >> get delegates {
78
+ final list = < LocalizationsDelegate <dynamic >> [];
79
+ for (var delegate in commonDelegates) {
80
+ list.add (delegate);
81
+ }
82
+ // A class which loads the translations from JSON files
83
+ if (useEncrypted) {
84
+ list.add (AppLocalizations .delegate);
85
+ } else {
86
+ list.add (AppLocalizationsTest .delegate);
87
+ }
88
+ return list;
89
+ }
90
+
65
91
final Locale ? Function (Locale ? , Iterable <Locale >)? localeResolutionCallback =
66
92
(locale, supportedLocales) {
67
93
if (locale == null ) return supportedLocales.first;
@@ -92,83 +118,67 @@ class Stringcare {
92
118
return supportedLocales.first;
93
119
};
94
120
95
- final StringcareCommons api = StringcareImpl ();
121
+ final StringcareCommons _productionApi = StringcareImpl ();
96
122
97
- Future <String ?> get platformVersion async {
98
- return api.platformVersion;
99
- }
123
+ final StringcareCommons _testApi = compile.StringcareImpl ();
100
124
101
- String testHash (List <String > keys) {
102
- return api.testHash (keys);
103
- }
125
+ StringcareCommons get _api => disableNative ? _testApi : _productionApi;
104
126
105
- String testSign (List <String > keys) {
106
- return api.testSign (keys);
107
- }
127
+ Future <String ?> get platformVersion => _api.platformVersion;
108
128
109
- String obfuscate (String value) {
110
- return api.obfuscate (value);
111
- }
129
+ String testHash (List <String > keys) => _api.testHash (keys);
112
130
113
- String obfuscateWith (List <String > keys, String value) {
114
- return api.obfuscateWith (keys, value);
115
- }
131
+ String testSign (List <String > keys) => _api.testSign (keys);
116
132
117
- Uint8List ? obfuscateData (Uint8List value) {
118
- return api.obfuscateData (value);
119
- }
133
+ String obfuscate (String value) => _api.obfuscate (value);
120
134
121
- Uint8List ? obfuscateDataWith (List <String > keys, Uint8List value) {
122
- return api.obfuscateDataWith (keys, value);
123
- }
135
+ String obfuscateWith (List <String > keys, String value) =>
136
+ _api.obfuscateWith (keys, value);
124
137
125
- String reveal (String value) {
126
- return api.reveal (value);
127
- }
138
+ Uint8List ? obfuscateData (Uint8List value) => _api.obfuscateData (value);
128
139
129
- String revealWith (List <String > keys, String value) {
130
- return api.revealWith (keys, value);
131
- }
140
+ Uint8List ? obfuscateDataWith (List <String > keys, Uint8List value) =>
141
+ _api.obfuscateDataWith (keys, value);
132
142
133
- Uint8List ? revealData (Uint8List ? value) {
134
- return api.revealData (value);
135
- }
143
+ String reveal (String value) => _api.reveal (value);
136
144
137
- Uint8List ? revealDataWith (List <String > keys, Uint8List value) {
138
- return api.revealDataWith (keys, value);
139
- }
145
+ String revealWith (List <String > keys, String value) =>
146
+ _api.revealWith (keys, value);
140
147
141
- String getSignature (List <String > keys) {
142
- return api.getSignature (keys);
143
- }
148
+ Uint8List ? revealData (Uint8List ? value) => _api.revealData (value);
144
149
145
- String getSignatureOfValue (String value) {
146
- return api.getSignatureOfValue (value);
147
- }
150
+ Uint8List ? revealDataWith (List <String > keys, Uint8List value) =>
151
+ _api.revealDataWith (keys, value);
148
152
149
- String getSignatureOfBytes (List <int > data) {
150
- return api.getSignatureOfBytes (data);
151
- }
153
+ String getSignature (List <String > keys) => _api.getSignature (keys);
152
154
153
- bool validSignature (String signature, List <String > keys) {
154
- return api.validSignature (signature, keys);
155
- }
155
+ String getSignatureOfValue (String value) => _api.getSignatureOfValue (value);
156
156
157
- String readableObfuscate (String value) {
158
- return api.readableObfuscate (value);
159
- }
157
+ String getSignatureOfBytes (List <int > data) => _api.getSignatureOfBytes (data);
160
158
161
- String ? translate (BuildContext context, String key, {List <String >? values}) {
162
- return AppLocalizations .of (context)! .translate (
163
- key,
164
- values: values,
165
- );
166
- }
159
+ bool validSignature (String signature, List <String > keys) =>
160
+ _api.validSignature (signature, keys);
167
161
168
- Future <String ?> translateWithLang (String lang, String key,
169
- {List <String >? values}) {
170
- return AppLocalizations .sTranslate (lang, key, values: values);
171
- }
162
+ String readableObfuscate (String value) => _api.readableObfuscate (value);
163
+
164
+ String ? translate (
165
+ BuildContext context,
166
+ String key, {
167
+ List <String >? values,
168
+ }) =>
169
+ appLocalizations? .translate (
170
+ key,
171
+ values: values,
172
+ );
173
+
174
+ Future <String ?> translateWithLang (
175
+ String lang,
176
+ String key, {
177
+ List <String >? values,
178
+ }) =>
179
+ useEncrypted
180
+ ? AppLocalizations .sTranslate (lang, key, values: values)
181
+ : AppLocalizationsTest .sTranslate (lang, key, values: values);
172
182
173
183
Future <Uint8List ?> revealAsset (String key) async {
174
184
var asset = await rootBundle.load (key);
@@ -180,14 +190,18 @@ class Stringcare {
180
190
181
191
String ? getLangWithContext (BuildContext ? context) {
182
192
if (context == null ) return null ;
183
- return AppLocalizations . of (context) ? .getLang ();
193
+ return appLocalizations ? .getLang ();
184
194
}
185
195
186
196
Future <bool > load () => loadWithContext (context);
187
197
198
+ AppLocalizationsInterface ? get appLocalizations => useEncrypted
199
+ ? AppLocalizations .of (context)
200
+ : AppLocalizationsTest .of (context);
201
+
188
202
Future <bool > loadWithContext (BuildContext ? context) async {
189
203
if (context == null ) return false ;
190
- return AppLocalizations . of (context) ? .load () ?? Future .value (false );
204
+ return appLocalizations ? .load () ?? Future .value (false );
191
205
}
192
206
193
207
Future <void > refreshWithLangWithContext (
0 commit comments