-
-
Notifications
You must be signed in to change notification settings - Fork 140
feat(i18n): merge translation branch #68
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
Open
TIANLI0
wants to merge
12
commits into
mithun50:main
Choose a base branch
from
TIANLI0:feature/translation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,354
−483
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1796d30
feat: add locale provider and storage permission service
TIANLI0 c62877c
feat: enhance AI provider configuration and localization support
TIANLI0 c022673
feat: Add localization support for Simplified and Traditional Chinese
TIANLI0 e5bf325
merge: sync feature/translation with latest main and resolve conflicts
TIANLI0 d17812d
chore(i18n): remove non-translation and authorization changes from tr…
TIANLI0 72d6ce6
merge: bring cleaned translation branch into main
TIANLI0 64a58ee
fix(flutter): make UI APIs compatible with Flutter 3.24
TIANLI0 5472c49
fix(i18n): complete locale coverage and async safety fixes
TIANLI0 81791f7
i18n: localize dashboard and node serial capability text
TIANLI0 228b62f
i18n: localize dashboard and node serial capability text
TIANLI0 a76d90e
merge: resolve l10n conflicts while keeping translation branch strings
TIANLI0 c7a96ea
fix(i18n): correct translation for save failure message in Simplified…
TIANLI0 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,97 @@ | ||
| import 'package:flutter/material.dart'; | ||
|
|
||
| import 'app_strings_en.dart'; | ||
| import 'app_strings_ja.dart'; | ||
| import 'app_strings_zh_hans.dart'; | ||
| import 'app_strings_zh_hant.dart'; | ||
|
|
||
| class AppLocalizations { | ||
| AppLocalizations(this.locale); | ||
|
|
||
| final Locale locale; | ||
|
|
||
| static const supportedLocales = [ | ||
| Locale('en'), | ||
| Locale('zh'), | ||
| Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hant'), | ||
| Locale('ja'), | ||
| ]; | ||
|
|
||
| static const LocalizationsDelegate<AppLocalizations> delegate = | ||
| _AppLocalizationsDelegate(); | ||
|
|
||
| static AppLocalizations of(BuildContext context) { | ||
| final localizations = Localizations.of<AppLocalizations>( | ||
| context, | ||
| AppLocalizations, | ||
| ); | ||
| assert(localizations != null, 'AppLocalizations not found in context'); | ||
| return localizations!; | ||
| } | ||
|
|
||
| String t(String key, [Map<String, Object?> params = const {}]) { | ||
| final localeKey = _localeToKey(locale); | ||
| final localized = _localizedValues[localeKey] ?? | ||
| _localizedValues[locale.languageCode] ?? | ||
| _localizedValues['en']!; | ||
| final fallback = _localizedValues['en']!; | ||
|
|
||
| var value = localized[key] ?? fallback[key] ?? key; | ||
| for (final entry in params.entries) { | ||
| value = value.replaceAll('{${entry.key}}', '${entry.value ?? ''}'); | ||
| } | ||
| return value; | ||
| } | ||
|
|
||
| static bool isLocaleSupported(Locale locale) { | ||
| final localeKey = _localeToKey(locale); | ||
| if (_localizedValues.containsKey(localeKey)) { | ||
| return true; | ||
| } | ||
| return _localizedValues.containsKey(locale.languageCode); | ||
| } | ||
|
|
||
| static String _localeToKey(Locale locale) { | ||
| final scriptCode = locale.scriptCode?.toLowerCase(); | ||
| final countryCode = locale.countryCode?.toUpperCase(); | ||
|
|
||
| if (locale.languageCode == 'zh') { | ||
| if (scriptCode == 'hant') { | ||
| return 'zh-Hant'; | ||
| } | ||
|
|
||
| if (countryCode == 'TW' || countryCode == 'HK' || countryCode == 'MO') { | ||
| return 'zh-Hant'; | ||
| } | ||
| } | ||
|
|
||
| return locale.languageCode; | ||
| } | ||
|
|
||
| static final Map<String, Map<String, String>> _localizedValues = { | ||
| 'en': appStringsEn, | ||
| 'zh': appStringsZhHans, | ||
| 'zh-Hant': appStringsZhHant, | ||
| 'ja': appStringsJa, | ||
| }; | ||
| } | ||
|
|
||
| class _AppLocalizationsDelegate | ||
| extends LocalizationsDelegate<AppLocalizations> { | ||
| const _AppLocalizationsDelegate(); | ||
|
|
||
| @override | ||
| bool isSupported(Locale locale) => AppLocalizations.isLocaleSupported(locale); | ||
|
|
||
| @override | ||
| Future<AppLocalizations> load(Locale locale) async { | ||
| return AppLocalizations(locale); | ||
| } | ||
|
|
||
| @override | ||
| bool shouldReload(_AppLocalizationsDelegate old) => false; | ||
| } | ||
|
|
||
| extension AppLocalizationsContextExtension on BuildContext { | ||
| AppLocalizations get l10n => AppLocalizations.of(this); | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.