-
-
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
Merged
nilsreichardt
merged 33 commits into
SharezoneApp:main
from
flowhorn:sharezone_localizations_demo
Dec 29, 2024
Merged
Changes from 32 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
9f98365
initial commit
flowhorn b841cd2
Format files
nilsreichardt 5667f0c
Add `.gen` suffix to generated localization files to indicate that th…
nilsreichardt 4280f15
Add VS Code Task
nilsreichardt 32939a7
Migrate to from `bloc` to `provider`
nilsreichardt d1afc7a
Use `sharezone_lints` instead of `flutter_lints`
nilsreichardt aa376d4
missing gateway to provider bloc added
flowhorn adf6fc9
Extract `AppLocaleProviderGateway` to into a separate file
nilsreichardt 75b5833
Merge branch 'sharezone_localizations_demo' of https://github.com/flo…
nilsreichardt 7e3077e
Add `getNativeName`, `getTranslatedName`, `toMap` and `fromMap` to `A…
nilsreichardt acbc2b6
Set locale to gateway in `AppLocaleProvider`
nilsreichardt f0b2eac
Format comment in `SharezoneLocalizationsContextExtension`
nilsreichardt 021633b
Add languages to `app_en` and `app_de`
nilsreichardt 5613aae
Add language page
nilsreichardt 0a34df3
Add feature flag for l10n feature
nilsreichardt ab7a1f9
Rename `AppLocales` to `AppLocale`
nilsreichardt fc6e506
Remove `SharezoneAppLocales`
nilsreichardt c431931
Remove `AppLocaleBuilder` from `README.md`
nilsreichardt 25709b8
Add comment to README
nilsreichardt 78f0901
Make AppLocaleProviderGateway const
nilsreichardt 1d30db9
Remove rxdart
nilsreichardt efbfe0a
Add license header
nilsreichardt a000ce1
Add `sharezone_localizations` to licenses_config.yaml
nilsreichardt 43f5a6e
Switch l10n strings to CamelCase instead of snake_case
nilsreichardt bba7b76
Change `app_de.arb` as template file
nilsreichardt 9861a84
Automatically add license header after generating files
nilsreichardt 5276989
Use `format` property instead of running `dart format .`
nilsreichardt 9a4161c
Fix language typo
nilsreichardt 20e863a
Apply default language in SharezoneLocalizations
nilsreichardt ad73eaa
Renamed `context.sl` to `context.l10n`
nilsreichardt 80cb441
Better error handle for context.l10n
nilsreichardt 3585edc
Add mock of l10n feature flag to settings page
nilsreichardt 16da52f
Fix golden test
nilsreichardt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
// 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", | ||
// Additionally, we add the license header again (the "flutter | ||
// gen-l10n" always removes the license header). | ||
"command": "fvm flutter gen-l10n && addlicense -c \"Sharezone UG (haftungsbeschränkt)\" -f ../../header_template.txt .", | ||
"options": { | ||
"cwd": "${workspaceFolder}/lib/sharezone_localizations" | ||
}, | ||
"problemMatcher": [] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (c) 2024 Sharezone UG (haftungsbeschränkt) | ||
// Licensed under the EUPL-1.2-or-later. | ||
// | ||
// You may obtain a copy of the Licence at: | ||
// https://joinup.ec.europa.eu/software/page/eupl | ||
// | ||
// SPDX-License-Identifier: EUPL-1.2 | ||
|
||
import 'dart:async'; | ||
|
||
import 'package:flutter/foundation.dart'; | ||
import 'package:sharezone/util/cache/streaming_key_value_store.dart'; | ||
|
||
class FeatureFlagl10n extends ChangeNotifier { | ||
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (c) 2024 Sharezone UG (haftungsbeschränkt) | ||
// Licensed under the EUPL-1.2-or-later. | ||
// | ||
// You may obtain a copy of the Licence at: | ||
// https://joinup.ec.europa.eu/software/page/eupl | ||
// | ||
// SPDX-License-Identifier: EUPL-1.2 | ||
|
||
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 { | ||
const FlutterAppLocaleProviderGateway({ | ||
required this.keyValueStore, | ||
required this.featureFlagl10n, | ||
}); | ||
|
||
final FeatureFlagl10n featureFlagl10n; | ||
final StreamingKeyValueStore keyValueStore; | ||
|
||
@override | ||
Stream<AppLocale> getLocale() { | ||
final defaultValue = jsonEncode(featureFlagl10n.isl10nEnabled | ||
? AppLocale.system.toMap() | ||
: AppLocale.en.toMap()); | ||
return keyValueStore | ||
.getString('locale', defaultValue: defaultValue) | ||
.map((event) => AppLocale.fromMap(jsonDecode(event))); | ||
} | ||
nilsreichardt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@override | ||
Future<void> setLocale(AppLocale locale) async { | ||
final value = jsonEncode(locale.toMap()); | ||
keyValueStore.setString( | ||
'locale', | ||
value, | ||
); | ||
} | ||
nilsreichardt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Just a temporary class. Will be removed when we're done with translating.