-
Notifications
You must be signed in to change notification settings - Fork 3
Migrate to Slang #344
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
base: not-working
Are you sure you want to change the base?
Migrate to Slang #344
Changes from all commits
e7b0374
1944a15
b0f613a
e52a5f8
2e12479
4bf6533
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| /// | ||
| /// Generated file. Do not edit. | ||
| /// | ||
| // coverage:ignore-file | ||
| // ignore_for_file: type=lint, unused_import | ||
| // dart format off | ||
|
|
||
| part of 'strings.g.dart'; | ||
|
|
||
| // Path: <root> | ||
| typedef TranslationsEn = Translations; // ignore: unused_element | ||
| class Translations with BaseTranslations<AppLocale, Translations> { | ||
| /// Returns the current translations of the given [context]. | ||
| /// | ||
| /// Usage: | ||
| /// final t = Translations.of(context); | ||
| static Translations of(BuildContext context) => InheritedLocaleData.of<AppLocale, Translations>(context).translations; | ||
|
|
||
| /// You can call this constructor and build your own translation instance of this locale. | ||
| /// Constructing via the enum [AppLocale.build] is preferred. | ||
| Translations({Map<String, Node>? overrides, PluralResolver? cardinalResolver, PluralResolver? ordinalResolver, TranslationMetadata<AppLocale, Translations>? meta}) | ||
| : assert(overrides == null, 'Set "translation_overrides: true" in order to enable this feature.'), | ||
| $meta = meta ?? TranslationMetadata( | ||
| locale: AppLocale.en, | ||
| overrides: overrides ?? {}, | ||
| cardinalResolver: cardinalResolver, | ||
| ordinalResolver: ordinalResolver, | ||
| ) { | ||
| $meta.setFlatMapFunction(_flatMapFunction); | ||
| } | ||
|
|
||
| /// Metadata for the translations of <en>. | ||
| @override final TranslationMetadata<AppLocale, Translations> $meta; | ||
|
|
||
| /// Access flat map | ||
| dynamic operator[](String key) => $meta.getTranslation(key); | ||
|
|
||
| late final Translations _root = this; // ignore: unused_field | ||
|
|
||
| Translations $copyWith({TranslationMetadata<AppLocale, Translations>? meta}) => Translations(meta: meta ?? this.$meta); | ||
|
|
||
| // Translations | ||
| late final TranslationsDependenciesEn dependencies = TranslationsDependenciesEn._(_root); | ||
| } | ||
|
|
||
| // Path: dependencies | ||
| class TranslationsDependenciesEn { | ||
| TranslationsDependenciesEn._(this._root); | ||
|
|
||
| final Translations _root; // ignore: unused_field | ||
|
|
||
| // Translations | ||
|
|
||
| /// en: '^3.0.1' | ||
| String get translate => '^3.0.1'; | ||
| } | ||
|
|
||
| /// The flat map containing all translations for locale <en>. | ||
| /// Only for edge cases! For simple maps, use the map function of this library. | ||
| /// | ||
| /// The Dart AOT compiler has issues with very large switch statements, | ||
| /// so the map is split into smaller functions (512 entries each). | ||
| extension on Translations { | ||
| dynamic _flatMapFunction(String path) { | ||
| return switch (path) { | ||
| 'dependencies.translate' => '^3.0.1', | ||
| _ => null, | ||
| }; | ||
| } | ||
| } | ||
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,8 @@ import 'dart:ui' as ui; | |
| import 'package:flutter/foundation.dart'; | ||
| import 'package:flutter/material.dart'; | ||
| import 'package:flutter/services.dart'; | ||
| import 'package:path/path.dart'; | ||
| import 'package:updatium/gen/strings.g.dart'; | ||
|
Comment on lines
+9
to
+10
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. 4. Conflicting t definitions lib/main.dart imports Slang generated strings.g.dart (defines top-level getter t) and
slang_converter.dart (defines top-level function t(String)), so uses like t('ok') become
ambiguous/invalid and will not compile.
Agent Prompt
|
||
| import 'package:updatium/pages/home.dart'; | ||
| import 'package:updatium/providers/apps_provider.dart'; | ||
| import 'package:updatium/providers/logs_provider.dart'; | ||
|
|
@@ -17,6 +19,8 @@ import 'package:provider/provider.dart'; | |
| import 'package:dynamic_color/dynamic_color.dart'; | ||
| import 'package:device_info_plus/device_info_plus.dart'; | ||
| import 'package:background_fetch/background_fetch.dart'; | ||
| import 'package:updatium/services/slang-converter.dart'; | ||
| import 'package:updatium/lib/gen/strings.g.dart'; | ||
|
Comment on lines
+22
to
+23
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. 3. Broken import paths lib/main.dart imports package:updatium/services/slang-converter.dart (no such file in repo) and also imports package:updatium/lib/gen/strings.g.dart (invalid package URI), both of which block compilation. Agent Prompt
|
||
| import 'package:updatium/services/slang_converter.dart'; | ||
| import 'package:simple_localization/src/simple_localization_controller.dart'; | ||
| import 'package:simple_localization/src/localization.dart'; | ||
|
|
@@ -80,33 +84,21 @@ bool isLocaleRTL(Locale locale) { | |
| } | ||
|
|
||
| Future<void> loadTranslations() async { | ||
| // See easy_localization/issues/210 | ||
| await SimpleLocalizationController.initEasyLocation(); | ||
| var s = SettingsProvider(); | ||
| try { | ||
| await s.initializeSettings(); | ||
| var forceLocale = s.forcedLocale; | ||
| final controller = SimpleLocalizationController( | ||
| saveLocale: true, | ||
| forceLocale: forceLocale, | ||
| fallbackLocale: fallbackLocale, | ||
| supportedLocales: supportedLocales.map((e) => e.key).toList(), | ||
| assetLoader: RootBundleAssetLoader.fromRootBundle(), | ||
| useOnlyLangCode: false, | ||
| useFallbackTranslations: true, | ||
| path: localeDir, | ||
| onLoadError: (FlutterError e) { | ||
| throw e; | ||
| }, | ||
| ); | ||
| await controller.loadTranslations(); | ||
| Localization.load( | ||
| controller.locale, | ||
| translations: controller.translations, | ||
| fallbackTranslations: controller.fallbackTranslations, | ||
| ); | ||
|
|
||
| if (forceLocale != null) { | ||
| final appLocale = AppLocaleUtils.parseLocaleParts( | ||
| languageCode: forceLocale.languageCode, | ||
| countryCode: forceLocale.countryCode, | ||
| ); | ||
| LocaleSettings.setLocale(appLocale); | ||
| } else { | ||
| await LocaleSettings.useDeviceLocale(); | ||
| } | ||
| } finally { | ||
| // Clean up the temporary SettingsProvider instance | ||
| s.dispose(); | ||
| } | ||
| } | ||
|
|
@@ -165,7 +157,8 @@ void main() async { | |
| } catch (e) { | ||
| // Already added, do nothing (see #375) | ||
| } | ||
| await SimpleLocalization.ensureInitialized(); | ||
|
|
||
| await loadTranslations(); | ||
|
|
||
| // Enable edge-to-edge mode for Android 10+ (API 29) | ||
| try { | ||
|
|
@@ -187,6 +180,20 @@ void main() async { | |
| await np.initialize(); | ||
| FlutterForegroundTask.initCommunicationPort(); | ||
|
|
||
| runApp( | ||
| TranslationProvider( | ||
| child: MultiProvider( | ||
| providers: [ | ||
| ChangeNotifierProvider(create: (context) => AppsProvider()), | ||
| ChangeNotifierProvider(create: (context) => SettingsProvider()), | ||
| Provider(create: (context) => np), | ||
| Provider(create: (context) => LogsProvider()), | ||
| ], | ||
| child: const Updatium(), | ||
| ), | ||
| ), | ||
| ); | ||
|
|
||
| runApp( | ||
| MultiProvider( | ||
| providers: [ | ||
|
Comment on lines
+183
to
199
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. 1. Two runapp calls main() calls runApp twice; the second call replaces the widget tree without TranslationProvider, but _UpdatiumState.build still calls TranslationProvider.of(context), which will throw at runtime. Agent Prompt
|
||
|
|
@@ -235,7 +242,7 @@ class _UpdatiumState extends State<Updatium> { | |
| WidgetsBinding.instance.platformDispatcher.onLocaleChanged; | ||
| WidgetsBinding.instance.platformDispatcher.onLocaleChanged = () { | ||
| if (_settingsProvider?.forcedLocale == null) { | ||
| _settingsProvider?.resetLocaleSafe(context); | ||
| LocaleSettings.useDeviceLocale(); | ||
| } | ||
| }; | ||
| } | ||
|
|
@@ -408,13 +415,15 @@ class _UpdatiumState extends State<Updatium> { | |
| } | ||
| } | ||
|
|
||
| // Sync local and device locale if needed | ||
| if (!supportedLocales.map((e) => e.key).contains(context.locale)) { | ||
| settingsProvider.resetLocaleSafe(context); | ||
| } else if (settingsProvider.forcedLocale != null && | ||
| context.locale != settingsProvider.forcedLocale) { | ||
| // Apply forced locale if it's set but not currently active | ||
| context.setLocale(settingsProvider.forcedLocale!); | ||
| // Sync local and device locale if needed for slang | ||
| if (settingsProvider.forcedLocale != null) { | ||
| final appLocale = AppLocaleUtils.parseLocaleParts( | ||
| languageCode: settingsProvider.forcedLocale!.languageCode, | ||
| countryCode: settingsProvider.forcedLocale!.countryCode, | ||
| ); | ||
| if (LocaleSettings.currentLocale != appLocale) { | ||
| LocaleSettings.setLocale(appLocale); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -569,15 +578,21 @@ class _UpdatiumState extends State<Updatium> { | |
| ); | ||
| } | ||
|
|
||
| final slangLocale = TranslationProvider.of(context).locale; | ||
|
|
||
| return Directionality( | ||
| textDirection: isLocaleRTL(context.locale) | ||
| textDirection: isLocaleRTL(slangLocale.flutterLocale) | ||
| ? ui.TextDirection.rtl | ||
| : ui.TextDirection.ltr, | ||
| child: MaterialApp( | ||
| title: 'Updatium', | ||
| localizationsDelegates: context.localizationDelegates, | ||
| supportedLocales: context.supportedLocales, | ||
| locale: context.locale, | ||
| localizationsDelegates: const [ | ||
| GlobalMaterialLocalizations.delegate, | ||
| GlobalWidgetsLocalizations.delegate, | ||
| GlobalCupertinoLocalizations.delegate, | ||
| ] | ||
| supportedLocales: AppLocaleUtils.supportedLocales, | ||
| locale: slangLocale.flutterLocale, | ||
|
Comment on lines
+589
to
+595
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. 2. Missing comma in materialapp The MaterialApp(...) argument list is missing a comma after the localizationsDelegates list, producing a Dart syntax error and preventing compilation. Agent Prompt
|
||
| navigatorKey: globalNavigatorKey, | ||
| debugShowCheckedModeBanner: false, | ||
| theme: createTheme(lightColorScheme), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -96,6 +96,9 @@ dependencies: | |
| progress_indicator_m3e: ^0.1.1 | ||
| loading_indicator_m3e: ^0.1.1 | ||
| dynamic_color: ^1.8.1 | ||
| slang: ^4.14.0 | ||
| slang_flutter: ^4.14.0 | ||
| slang_build_runner: ^4.14.0 | ||
|
Comment on lines
+99
to
+101
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. 5. Missing flutter_localizations dep main.dart now references GlobalMaterialLocalizations / GlobalWidgetsLocalizations / GlobalCupertinoLocalizations, but pubspec.yaml does not include the flutter_localizations SDK dependency, causing unresolved symbols/build failure. Agent Prompt
|
||
| flutter_launcher_icons: | ||
| android: "ic_launcher" | ||
| adaptive_icon_background: "#ffffff" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # slang.yaml | ||
| input_directory: assets/translations | ||
| input_file_pattern: .json | ||
|
Comment on lines
+1
to
+3
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. 1. Package.json breaks translations slang.yaml matches all .json files under assets/translations, so package.json is treated as a translation source and generates an en Translations class containing only dependencies.translate. Other locale classes still implements Translations but do not implement the generated dependencies member, so the generated localization code will not compile and real en.json keys (e.g., ok, cancel) are not available in the base type. Agent Prompt
|
||
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.
The base
Translationsclass is missing almost all the translation keys (e.g.,invalidURLForSource,noReleaseFound,primary, etc.) that are present in other locale files likestrings_ar.g.dart. SinceAppLocale.enis configured as thebaseLocaleinAppLocaleUtils, this class defines the interface that all other translations must implement. As it stands, the project will fail to compile because the other generated classes (likeTranslationsAr) are attempting to override members that do not exist in the base class.Additionally, the English locale contains a
dependencieskey that is missing from other locales, which is another source of compilation errors. It appears thatslangmight have processed an incorrect file (possibly containing dependency info) as the source for the English locale. Please ensure your base translation file (e.g.,assets/translations/strings_en.i18n.json) is correctly populated with all keys.