From 89b642772cd702e035359c89d46f1f35c6d883c9 Mon Sep 17 00:00:00 2001 From: Alberto Ponces Date: Sun, 7 Aug 2022 00:37:12 +0100 Subject: [PATCH] feat: add i18n --- assets/i18n/en.json | 40 +++++++++++++++++ lib/constants.dart | 6 +-- lib/main.dart | 28 +++++++++--- lib/services/github_api.dart | 35 +++------------ lib/services/manager_api.dart | 2 +- lib/ui/views/home/home_view.dart | 34 +++++++++------ lib/ui/views/patcher/patcher_view.dart | 14 +++--- lib/ui/widgets/app_selector_card.dart | 23 ++++++---- lib/ui/widgets/application_item.dart | 8 +++- lib/ui/widgets/available_updates_card.dart | 50 +++++++++++++--------- lib/ui/widgets/installed_apps_card.dart | 39 ++++++++++------- lib/ui/widgets/latest_commit_card.dart | 40 ++++++++++------- lib/ui/widgets/patch_selector_card.dart | 23 ++++++---- pubspec.lock | 38 ++++++++++++++++ pubspec.yaml | 2 + 15 files changed, 259 insertions(+), 123 deletions(-) create mode 100644 assets/i18n/en.json diff --git a/assets/i18n/en.json b/assets/i18n/en.json new file mode 100644 index 00000000..e4228e19 --- /dev/null +++ b/assets/i18n/en.json @@ -0,0 +1,40 @@ +{ + "main": { + "dashboardTab": "Dashboard", + "patcherTab": "Patcher" + }, + "homeView": { + "widgetTitle": "Dashboard", + "updatesSubtitle": "ReVanced Updates", + "patchedSubtitle": "Patched Applications" + }, + "availableUpdatesCard": { + "widgetTitle": "Updates Available", + "patchButton": "Patch All", + "changelogLabel": "Changelog" + }, + "applicationItem": { + "patchButton": "Patch" + }, + "installedAppsCard": { + "widgetTitle": "Total Installed", + "changelogLabel": "Changelog" + }, + "latestCommitCard": { + "loadingLabel": "Loading", + "patcherLabel": "Patcher: ", + "managerLabel": "Manager: ", + "updateButton": "Update Manager" + }, + "patcherView": { + "widgetTitle": "Patcher" + }, + "appSelectorCard": { + "widgetTitle": "Select application", + "widgetSubtitle": "No application selected." + }, + "patchSelectorCard": { + "widgetTitle": "Select patches", + "widgetSubtitle": "Select an application first." + } +} \ No newline at end of file diff --git a/lib/constants.dart b/lib/constants.dart index ff0011db..94e165fa 100644 --- a/lib/constants.dart +++ b/lib/constants.dart @@ -11,6 +11,6 @@ const pink40 = Color(0xFF7D5260); final interTextStyle = GoogleFonts.inter(); final robotoTextStyle = GoogleFonts.roboto(); -const ghOrg = "revanced"; -const patchesRepo = "revanced-patches"; -const integrationsRepo = "revanced-integrations"; +const ghOrg = 'revanced'; +const patchesRepo = 'revanced-patches'; +const integrationsRepo = 'revanced-integrations'; diff --git a/lib/main.dart b/lib/main.dart index a72157e6..38c12363 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,4 +1,6 @@ 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/app/app.router.dart'; import 'package:revanced_manager/main_viewmodel.dart'; @@ -27,6 +29,16 @@ class MyApp extends StatelessWidget { navigatorKey: StackedService.navigatorKey, onGenerateRoute: StackedRouter().onGenerateRoute, home: const Navigation(), + localizationsDelegates: [ + FlutterI18nDelegate( + translationLoader: FileTranslationLoader( + fallbackFile: 'en', + basePath: 'assets/i18n', + ), + ), + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate + ], ); } } @@ -43,14 +55,20 @@ class Navigation extends StatelessWidget { bottomNavigationBar: NavigationBar( onDestinationSelected: model.setIndex, selectedIndex: model.currentIndex, - destinations: const [ + destinations: [ NavigationDestination( - icon: Icon(Icons.dashboard), - label: "Dashboard", + icon: const Icon(Icons.dashboard), + label: FlutterI18n.translate( + context, + 'main.dashboardTab', + ), ), NavigationDestination( - icon: Icon(Icons.build), - label: "Patcher", + icon: const Icon(Icons.build), + label: FlutterI18n.translate( + context, + 'main.patcherTab', + ), ), ], ), diff --git a/lib/services/github_api.dart b/lib/services/github_api.dart index 0afd2ca9..9a490102 100644 --- a/lib/services/github_api.dart +++ b/lib/services/github_api.dart @@ -6,8 +6,9 @@ class GithubAPI { var github = GitHub(); Future latestRelease(String org, repoName) async { - var latestRelease = await github.repositories - .getLatestRelease(RepositorySlug(org, repoName)); + var latestRelease = await github.repositories.getLatestRelease( + RepositorySlug(org, repoName), + ); var dlurl = latestRelease.assets ?.firstWhere((asset) => asset.name != null && @@ -18,32 +19,10 @@ class GithubAPI { return dlurl; } - Future latestCommitTime(String org, repoName) async { - var repo = - await github.repositories.getRepository(RepositorySlug(org, repoName)); - - var commitTime = repo.pushedAt?.difference( - DateTime.now().toLocal(), + Future latestCommitTime(String org, repoName) async { + var repo = await github.repositories.getRepository( + RepositorySlug(org, repoName), ); - - final hours = commitTime!.inHours.abs(); - - if (hours > 24) { - var days = (commitTime.inDays).abs().toString(); - return "$days days"; - } else if (hours > 1 && hours < 24) { - var hours = (commitTime.inHours).abs().toString(); - return "$hours hours"; - } else { - var minutes = (commitTime.inMinutes).abs().toString(); - return "$minutes mins"; - } - } - - Future contributors(String org, repoName) async { - var contributors = - github.repositories.listContributors(RepositorySlug(org, repoName)); - contributors.forEach((contributor) {}); - return contributors; + return repo.pushedAt; } } diff --git a/lib/services/manager_api.dart b/lib/services/manager_api.dart index b28747a4..22bdbf15 100644 --- a/lib/services/manager_api.dart +++ b/lib/services/manager_api.dart @@ -14,7 +14,7 @@ class ManagerAPI { Future getPath() async { final path = await p.getApplicationSupportDirectory(); final workDir = Directory('${path.path}/revanced').createSync(); - final workDirPath = "${path.path}/revanced"; + final workDirPath = '${path.path}/revanced'; return workDirPath; } diff --git a/lib/ui/views/home/home_view.dart b/lib/ui/views/home/home_view.dart index c3c34951..9009c2dc 100644 --- a/lib/ui/views/home/home_view.dart +++ b/lib/ui/views/home/home_view.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:flutter_i18n/flutter_i18n.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:revanced_manager/ui/widgets/available_updates_card.dart'; import 'package:revanced_manager/ui/widgets/installed_apps_card.dart'; @@ -33,26 +34,35 @@ class HomeView extends StatelessWidget { ), ), const SizedBox(height: 60), - Text( - "Dashboard", - style: GoogleFonts.inter( - fontSize: 28, + I18nText( + 'homeView.widgetTitle', + child: Text( + '', + style: GoogleFonts.inter( + fontSize: 28, + ), ), ), const SizedBox(height: 23), - Text( - "ReVanced Updates", - style: GoogleFonts.inter( - fontSize: 18, + I18nText( + 'homeView.updatesSubtitle', + child: Text( + '', + style: GoogleFonts.inter( + fontSize: 18, + ), ), ), const SizedBox(height: 10), const LatestCommitCard(), const SizedBox(height: 14), - Text( - "Patched Applications", - style: GoogleFonts.inter( - fontSize: 18, + I18nText( + 'homeView.patchedSubtitle', + child: Text( + '', + style: GoogleFonts.inter( + fontSize: 18, + ), ), ), const SizedBox(height: 14), diff --git a/lib/ui/views/patcher/patcher_view.dart b/lib/ui/views/patcher/patcher_view.dart index 37b06b0d..9fcaf776 100644 --- a/lib/ui/views/patcher/patcher_view.dart +++ b/lib/ui/views/patcher/patcher_view.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:flutter_i18n/flutter_i18n.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:revanced_manager/ui/views/app_selector/app_selector_view.dart'; import 'package:revanced_manager/ui/widgets/app_selector_card.dart'; @@ -29,11 +30,14 @@ class PatcherView extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, children: [ const SizedBox(height: 12), - Text( - "Patcher", - style: GoogleFonts.inter( - fontSize: 28, - fontWeight: FontWeight.w500, + I18nText( + 'patcherView.widgetTitle', + child: Text( + '', + style: GoogleFonts.inter( + fontSize: 28, + fontWeight: FontWeight.w500, + ), ), ), const SizedBox(height: 23), diff --git a/lib/ui/widgets/app_selector_card.dart b/lib/ui/widgets/app_selector_card.dart index f2cead32..b1334e1d 100644 --- a/lib/ui/widgets/app_selector_card.dart +++ b/lib/ui/widgets/app_selector_card.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:flutter_i18n/flutter_i18n.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:revanced_manager/constants.dart'; @@ -23,17 +24,23 @@ class AppSelectorCard extends StatelessWidget { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text( - "Select application", - style: GoogleFonts.roboto( - fontSize: 18, - fontWeight: FontWeight.w500, + I18nText( + 'appSelectorCard.widgetTitle', + child: Text( + '', + style: GoogleFonts.roboto( + fontSize: 18, + fontWeight: FontWeight.w500, + ), ), ), const SizedBox(height: 10), - Text( - "No application selected", - style: robotoTextStyle, + I18nText( + 'appSelectorCard.widgetSubtitle', + child: Text( + '', + style: robotoTextStyle, + ), ), ], ), diff --git a/lib/ui/widgets/application_item.dart b/lib/ui/widgets/application_item.dart index a4b3155c..1e7329ee 100644 --- a/lib/ui/widgets/application_item.dart +++ b/lib/ui/widgets/application_item.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:flutter_i18n/flutter_i18n.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:revanced_manager/constants.dart'; @@ -20,7 +21,7 @@ class ApplicationItem extends StatelessWidget { @override Widget build(BuildContext context) { - final isSVG = asset.endsWith(".svg"); + final isSVG = asset.endsWith('.svg'); return ListTile( horizontalTitleGap: 12.0, leading: isSVG @@ -45,7 +46,10 @@ class ApplicationItem extends StatelessWidget { style: robotoTextStyle, ), trailing: PatchTextButton( - text: "Patch", + text: FlutterI18n.translate( + context, + 'applicationItem.patchButton', + ), onPressed: onPressed, ), ); diff --git a/lib/ui/widgets/available_updates_card.dart b/lib/ui/widgets/available_updates_card.dart index 4eb56908..b5a5da19 100644 --- a/lib/ui/widgets/available_updates_card.dart +++ b/lib/ui/widgets/available_updates_card.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:flutter_i18n/flutter_i18n.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:revanced_manager/ui/widgets/application_item.dart'; import 'package:revanced_manager/ui/widgets/patch_text_button.dart'; @@ -21,51 +22,60 @@ class AvailableUpdatesCard extends StatelessWidget { Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text( - "Updates Available(2)", - style: GoogleFonts.inter( - fontSize: 16, - color: const Color(0xff7792BA), - fontWeight: FontWeight.w500, + I18nText( + 'availableUpdatesCard.widgetTitle', + child: Text( + '', + style: GoogleFonts.inter( + fontSize: 16, + color: const Color(0xff7792BA), + fontWeight: FontWeight.w500, + ), ), ), PatchTextButton( - text: "Patch all", + text: FlutterI18n.translate( + context, + 'availableUpdatesCard.patchButton', + ), onPressed: () {}, backgroundColor: const Color(0xff7792BA), ), ], ), ApplicationItem( - asset: "assets/images/revanced.svg", - name: "ReVanced", - releaseDate: "2 days ago", + asset: 'assets/images/revanced.svg', + name: 'ReVanced', + releaseDate: '2 days ago', onPressed: () {}, ), ApplicationItem( - asset: "assets/images/reddit.png", - name: "ReReddit", - releaseDate: "Released 1 month ago", + asset: 'assets/images/reddit.png', + name: 'ReReddit', + releaseDate: 'Released 1 month ago', onPressed: () {}, ), const SizedBox(height: 4), - Text( - "Changelog", - style: GoogleFonts.roboto( - color: const Color(0xff8691A0), - fontWeight: FontWeight.w700, + I18nText( + 'availableUpdatesCard.changelogLabel', + child: Text( + '', + style: GoogleFonts.roboto( + color: const Color(0xff8691A0), + fontWeight: FontWeight.w700, + ), ), ), const SizedBox(height: 4), Text( - "fix: we made the player even worse (you love)", + 'fix: we made the player even worse (you love)', style: GoogleFonts.roboto( color: const Color(0xff8691A0), ), ), const SizedBox(height: 4), Text( - "chore: guhhughghu", + 'chore: guhhughghu', style: GoogleFonts.roboto( color: const Color(0xff8691A0), ), diff --git a/lib/ui/widgets/installed_apps_card.dart b/lib/ui/widgets/installed_apps_card.dart index 33c838e9..ad5fa4ae 100644 --- a/lib/ui/widgets/installed_apps_card.dart +++ b/lib/ui/widgets/installed_apps_card.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:flutter_i18n/flutter_i18n.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:revanced_manager/ui/widgets/application_item.dart'; @@ -17,37 +18,43 @@ class InstalledAppsCard extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start, children: [ - Text( - "Total Installed(3)", - style: GoogleFonts.inter( - fontSize: 16, - color: const Color(0xff7792BA), - fontWeight: FontWeight.w500, + I18nText( + 'installedAppsCard.widgetTitle', + child: Text( + '', + style: GoogleFonts.inter( + fontSize: 16, + color: const Color(0xff7792BA), + fontWeight: FontWeight.w500, + ), ), ), ApplicationItem( - asset: "assets/images/revanced.svg", - name: "ReVanced", - releaseDate: "2 days ago", + asset: 'assets/images/revanced.svg', + name: 'ReVanced', + releaseDate: '2 days ago', onPressed: () {}, ), - Text( - "Changelog", - style: GoogleFonts.roboto( - color: const Color(0xff8691A0), - fontWeight: FontWeight.w700, + I18nText( + 'installedAppsCard.changelogLabel', + child: Text( + '', + style: GoogleFonts.roboto( + color: const Color(0xff8691A0), + fontWeight: FontWeight.w700, + ), ), ), const SizedBox(height: 4), Text( - "fix: we made the player even worse (you love)", + 'fix: we made the player even worse (you love)', style: GoogleFonts.roboto( color: const Color(0xff8691A0), ), ), const SizedBox(height: 4), Text( - "chore: guhhughghu", + 'chore: guhhughghu', style: GoogleFonts.roboto( color: const Color(0xff8691A0), ), diff --git a/lib/ui/widgets/latest_commit_card.dart b/lib/ui/widgets/latest_commit_card.dart index 7a0aeb72..88220360 100644 --- a/lib/ui/widgets/latest_commit_card.dart +++ b/lib/ui/widgets/latest_commit_card.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:flutter_i18n/flutter_i18n.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:revanced_manager/services/github_api.dart'; import 'package:revanced_manager/constants.dart'; @@ -13,14 +14,14 @@ class LatestCommitCard extends StatefulWidget { class _LatestCommitCardState extends State { GithubAPI githubAPI = GithubAPI(); - String lastPatcherCommit = "Loading..."; - String lastManagerCommit = "Loading..."; + String lastPatcherCommit = 'Loading...'; + String lastManagerCommit = 'Loading...'; void latestCommit() async { // lastPatcherCommit = - // await githubAPI.latestCommitTime("revanced", "revanced-patcher"); + // await githubAPI.latestCommitTime('revanced', 'revanced-patcher'); // lastManagerCommit = - // await githubAPI.latestCommitTime("revanced", "revanced-manager"); + // await githubAPI.latestCommitTime('revanced', 'revanced-manager'); } @override @@ -47,28 +48,34 @@ class _LatestCommitCardState extends State { children: [ Row( children: [ - Text( - "Patcher: ", - style: GoogleFonts.roboto( - fontWeight: FontWeight.w700, + I18nText( + 'latestCommitCard.patcherLabel', + child: Text( + '', + style: GoogleFonts.roboto( + fontWeight: FontWeight.w700, + ), ), ), Text( - "$lastPatcherCommit ago", + '$lastPatcherCommit ago', style: robotoTextStyle, ) ], ), Row( children: [ - Text( - "Manager: ", - style: GoogleFonts.roboto( - fontWeight: FontWeight.w700, + I18nText( + 'latestCommitCard.managerLabel', + child: Text( + '', + style: GoogleFonts.roboto( + fontWeight: FontWeight.w700, + ), ), ), Text( - "$lastManagerCommit ago", + '$lastManagerCommit ago', style: robotoTextStyle, ) ], @@ -76,7 +83,10 @@ class _LatestCommitCardState extends State { ], ), PatchTextButton( - text: "Update Manager", + text: FlutterI18n.translate( + context, + 'latestCommitCard.updateButton', + ), onPressed: () {}, backgroundColor: const Color(0xff7792BA), ), diff --git a/lib/ui/widgets/patch_selector_card.dart b/lib/ui/widgets/patch_selector_card.dart index 5ee936f6..ee3f6acb 100644 --- a/lib/ui/widgets/patch_selector_card.dart +++ b/lib/ui/widgets/patch_selector_card.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:flutter_i18n/flutter_i18n.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:revanced_manager/constants.dart'; @@ -23,17 +24,23 @@ class PatchSelectorCard extends StatelessWidget { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text( - "Select patches", - style: GoogleFonts.roboto( - fontSize: 18, - fontWeight: FontWeight.w500, + I18nText( + 'patchSelectorCard.widgetTitle', + child: Text( + '', + style: GoogleFonts.roboto( + fontSize: 18, + fontWeight: FontWeight.w500, + ), ), ), const SizedBox(height: 10), - Text( - "Select an application first.", - style: robotoTextStyle, + I18nText( + 'patchSelectorCard.widgetSubtitle', + child: Text( + '', + style: robotoTextStyle, + ), ), ], ), diff --git a/pubspec.lock b/pubspec.lock index af3a996a..c89012a6 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -216,6 +216,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "3.3.0" + flutter_i18n: + dependency: "direct main" + description: + name: flutter_i18n + url: "https://pub.dartlang.org" + source: hosted + version: "0.32.4" flutter_lints: dependency: "direct dev" description: @@ -223,6 +230,11 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.1" + flutter_localizations: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" flutter_svg: dependency: "direct main" description: @@ -235,6 +247,11 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_web_plugins: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" frontend_server_client: dependency: transitive description: @@ -326,6 +343,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.3.1" + intl: + dependency: transitive + description: + name: intl + url: "https://pub.dartlang.org" + source: hosted + version: "0.17.0" io: dependency: transitive description: @@ -702,6 +726,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.0" + toml: + dependency: transitive + description: + name: toml + url: "https://pub.dartlang.org" + source: hosted + version: "0.13.1" typed_data: dependency: transitive description: @@ -765,6 +796,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "6.1.0" + xml2json: + dependency: transitive + description: + name: xml2json + url: "https://pub.dartlang.org" + source: hosted + version: "5.3.4" yaml: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 57d5def2..313d433c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,6 +16,7 @@ dependencies: flutter: sdk: flutter flutter_cache_manager: ^3.3.0 + flutter_i18n: ^0.32.4 flutter_svg: ^1.1.1+1 get_it: ^7.2.0 github: ^9.4.0 @@ -41,3 +42,4 @@ flutter: uses-material-design: true assets: - assets/images/ + - assets/i18n/