mirror of
https://github.com/ReVanced/revanced-manager.git
synced 2025-05-11 13:05:37 +02:00
feat: EXPERIMENTAL language switching.
This commit is contained in:
parent
30376c960f
commit
be77a181ec
6 changed files with 135 additions and 24 deletions
|
@ -2,16 +2,19 @@ import 'package:flutter/material.dart';
|
|||
import 'package:flutter_i18n/flutter_i18n.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:revanced_manager/app/app.locator.dart';
|
||||
import 'package:revanced_manager/services/crowdin_api.dart';
|
||||
import 'package:revanced_manager/services/github_api.dart';
|
||||
import 'package:revanced_manager/services/manager_api.dart';
|
||||
import 'package:revanced_manager/services/patcher_api.dart';
|
||||
import 'package:revanced_manager/services/revanced_api.dart';
|
||||
import 'package:revanced_manager/ui/theme/dynamic_theme_builder.dart';
|
||||
import 'package:revanced_manager/ui/views/navigation/navigation_view.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:stacked_themes/stacked_themes.dart';
|
||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
import 'package:timezone/data/latest.dart' as tz;
|
||||
|
||||
late SharedPreferences prefs;
|
||||
Future main() async {
|
||||
await ThemeManager.initialise();
|
||||
await setupLocator();
|
||||
|
@ -19,10 +22,12 @@ Future main() async {
|
|||
await locator<ManagerAPI>().initialize();
|
||||
String apiUrl = locator<ManagerAPI>().getApiUrl();
|
||||
await locator<RevancedAPI>().initialize(apiUrl);
|
||||
await locator<CrowdinAPI>().initialize();
|
||||
// bool isSentryEnabled = locator<ManagerAPI>().isSentryEnabled();
|
||||
locator<GithubAPI>().initialize();
|
||||
await locator<PatcherAPI>().initialize();
|
||||
tz.initializeTimeZones();
|
||||
prefs = await SharedPreferences.getInstance();
|
||||
|
||||
// Remove this section if you are building from source and don't have sentry configured
|
||||
// await SentryFlutter.init(
|
||||
|
@ -55,15 +60,25 @@ class MyApp extends StatelessWidget {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
String rawLocale = prefs.getString('language') ?? 'en_US';
|
||||
String replaceLocale = rawLocale.replaceAll('_', '-');
|
||||
List<String> localeList = replaceLocale.split('-');
|
||||
Locale locale = Locale(localeList[0], localeList[1]);
|
||||
|
||||
return DynamicThemeBuilder(
|
||||
title: 'ReVanced Manager',
|
||||
home: const NavigationView(),
|
||||
localizationsDelegates: [
|
||||
FlutterI18nDelegate(
|
||||
translationLoader: FileTranslationLoader(
|
||||
fallbackFile: 'en_US',
|
||||
forcedLocale: locale,
|
||||
basePath: 'assets/i18n',
|
||||
useCountryCode: true,
|
||||
),
|
||||
missingTranslationHandler: (key, locale) {
|
||||
print(
|
||||
'--> Missing translation: key: $key, languageCode: ${locale?.languageCode}');
|
||||
},
|
||||
),
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue