-
-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add scaffold for localizations (l10n) in Sharezone #1798
Changes from 15 commits
9f98365
b841cd2
5667f0c
4280f15
32939a7
d1afc7a
aa376d4
adf6fc9
75b5833
7e3077e
acbc2b6
f0b2eac
021633b
5613aae
0a34df3
ab7a1f9
fc6e506
c431931
25709b8
78f0901
1d30db9
efbfe0a
a000ce1
43f5a6e
bba7b76
9861a84
5276989
9a4161c
20e863a
ad73eaa
80cb441
3585edc
16da52f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
// See https://go.microsoft.com/fwlink/?LinkId=733558 | ||
// for the documentation about the tasks.json format | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
// This task generates the l10n files for the | ||
// sharezone_localizations. | ||
// | ||
// FVM is required to run this task. | ||
"label": "Generate l10n for sharezone_localizations", | ||
"type": "shell", | ||
// We also format the files after generating the l10n files because | ||
// the generated files use a different formatting style than the | ||
// rest of the project. | ||
"command": "fvm flutter gen-l10n && fvm dart format .", | ||
"options": { | ||
"cwd": "${workspaceFolder}/lib/sharezone_localizations" | ||
}, | ||
"problemMatcher": [] | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:flutter/foundation.dart'; | ||
import 'package:sharezone/util/cache/streaming_key_value_store.dart'; | ||
|
||
class FeatureFlagl10n extends ChangeNotifier { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a temporary class. Will be removed when we're done with translating. |
||
FeatureFlagl10n(this.keyValueStore) { | ||
_subscription = keyValueStore | ||
.getBool('l10n_enabled', defaultValue: false) | ||
.listen((event) { | ||
final newValue = event == true; | ||
if (isl10nEnabled != newValue) { | ||
isl10nEnabled = newValue; | ||
notifyListeners(); | ||
} | ||
}); | ||
} | ||
nilsreichardt marked this conversation as resolved.
Show resolved
Hide resolved
nilsreichardt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
final StreamingKeyValueStore keyValueStore; | ||
late StreamSubscription<bool> _subscription; | ||
bool isl10nEnabled = false; | ||
nilsreichardt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
void toggle() { | ||
isl10nEnabled = !isl10nEnabled; | ||
keyValueStore.setBool('l10n_enabled', isl10nEnabled); | ||
notifyListeners(); | ||
} | ||
|
||
@override | ||
void dispose() { | ||
_subscription.cancel(); | ||
super.dispose(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:sharezone/l10n/feature_flag_l10n.dart'; | ||
import 'package:sharezone/util/cache/streaming_key_value_store.dart'; | ||
import 'package:sharezone_localizations/sharezone_localizations.dart'; | ||
|
||
class FlutterAppLocaleProviderGateway extends AppLocaleProviderGateway { | ||
FlutterAppLocaleProviderGateway({ | ||
required this.keyValueStore, | ||
required this.featureFlagl10n, | ||
}); | ||
|
||
final FeatureFlagl10n featureFlagl10n; | ||
final StreamingKeyValueStore keyValueStore; | ||
|
||
@override | ||
Stream<AppLocales> getLocale() { | ||
final defaultValue = jsonEncode(featureFlagl10n.isl10nEnabled | ||
? AppLocales.system.toMap() | ||
: AppLocales.en.toMap()); | ||
return keyValueStore | ||
.getString('locale', defaultValue: defaultValue) | ||
.map((event) => AppLocales.fromMap(jsonDecode(event))); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Later, we will stream the locale from Firebase. Will be done in a future pull request. |
||
|
||
@override | ||
Future<void> setLocale(AppLocales locale) async { | ||
final value = jsonEncode(locale.toMap()); | ||
keyValueStore.setString( | ||
'locale', | ||
value, | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Later, we can create a
sz
command for this: #1799