feat: add i18n

This commit is contained in:
Alberto Ponces 2022-08-07 00:37:12 +01:00
parent ab9b91b975
commit 89b642772c
15 changed files with 259 additions and 123 deletions

40
assets/i18n/en.json Normal file
View File

@ -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."
}
}

View File

@ -11,6 +11,6 @@ const pink40 = Color(0xFF7D5260);
final interTextStyle = GoogleFonts.inter(); final interTextStyle = GoogleFonts.inter();
final robotoTextStyle = GoogleFonts.roboto(); final robotoTextStyle = GoogleFonts.roboto();
const ghOrg = "revanced"; const ghOrg = 'revanced';
const patchesRepo = "revanced-patches"; const patchesRepo = 'revanced-patches';
const integrationsRepo = "revanced-integrations"; const integrationsRepo = 'revanced-integrations';

View File

@ -1,4 +1,6 @@
import 'package:flutter/material.dart'; 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.locator.dart';
import 'package:revanced_manager/app/app.router.dart'; import 'package:revanced_manager/app/app.router.dart';
import 'package:revanced_manager/main_viewmodel.dart'; import 'package:revanced_manager/main_viewmodel.dart';
@ -27,6 +29,16 @@ class MyApp extends StatelessWidget {
navigatorKey: StackedService.navigatorKey, navigatorKey: StackedService.navigatorKey,
onGenerateRoute: StackedRouter().onGenerateRoute, onGenerateRoute: StackedRouter().onGenerateRoute,
home: const Navigation(), 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( bottomNavigationBar: NavigationBar(
onDestinationSelected: model.setIndex, onDestinationSelected: model.setIndex,
selectedIndex: model.currentIndex, selectedIndex: model.currentIndex,
destinations: const <Widget>[ destinations: <Widget>[
NavigationDestination( NavigationDestination(
icon: Icon(Icons.dashboard), icon: const Icon(Icons.dashboard),
label: "Dashboard", label: FlutterI18n.translate(
context,
'main.dashboardTab',
),
), ),
NavigationDestination( NavigationDestination(
icon: Icon(Icons.build), icon: const Icon(Icons.build),
label: "Patcher", label: FlutterI18n.translate(
context,
'main.patcherTab',
),
), ),
], ],
), ),

View File

@ -6,8 +6,9 @@ class GithubAPI {
var github = GitHub(); var github = GitHub();
Future<String?> latestRelease(String org, repoName) async { Future<String?> latestRelease(String org, repoName) async {
var latestRelease = await github.repositories var latestRelease = await github.repositories.getLatestRelease(
.getLatestRelease(RepositorySlug(org, repoName)); RepositorySlug(org, repoName),
);
var dlurl = latestRelease.assets var dlurl = latestRelease.assets
?.firstWhere((asset) => ?.firstWhere((asset) =>
asset.name != null && asset.name != null &&
@ -18,32 +19,10 @@ class GithubAPI {
return dlurl; return dlurl;
} }
Future latestCommitTime(String org, repoName) async { Future<DateTime?> latestCommitTime(String org, repoName) async {
var repo = var repo = await github.repositories.getRepository(
await github.repositories.getRepository(RepositorySlug(org, repoName)); RepositorySlug(org, repoName),
var commitTime = repo.pushedAt?.difference(
DateTime.now().toLocal(),
); );
return repo.pushedAt;
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;
} }
} }

View File

@ -14,7 +14,7 @@ class ManagerAPI {
Future<String?> getPath() async { Future<String?> getPath() async {
final path = await p.getApplicationSupportDirectory(); final path = await p.getApplicationSupportDirectory();
final workDir = Directory('${path.path}/revanced').createSync(); final workDir = Directory('${path.path}/revanced').createSync();
final workDirPath = "${path.path}/revanced"; final workDirPath = '${path.path}/revanced';
return workDirPath; return workDirPath;
} }

View File

@ -1,4 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_i18n/flutter_i18n.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:google_fonts/google_fonts.dart';
import 'package:revanced_manager/ui/widgets/available_updates_card.dart'; import 'package:revanced_manager/ui/widgets/available_updates_card.dart';
import 'package:revanced_manager/ui/widgets/installed_apps_card.dart'; import 'package:revanced_manager/ui/widgets/installed_apps_card.dart';
@ -33,26 +34,35 @@ class HomeView extends StatelessWidget {
), ),
), ),
const SizedBox(height: 60), const SizedBox(height: 60),
Text( I18nText(
"Dashboard", 'homeView.widgetTitle',
style: GoogleFonts.inter( child: Text(
fontSize: 28, '',
style: GoogleFonts.inter(
fontSize: 28,
),
), ),
), ),
const SizedBox(height: 23), const SizedBox(height: 23),
Text( I18nText(
"ReVanced Updates", 'homeView.updatesSubtitle',
style: GoogleFonts.inter( child: Text(
fontSize: 18, '',
style: GoogleFonts.inter(
fontSize: 18,
),
), ),
), ),
const SizedBox(height: 10), const SizedBox(height: 10),
const LatestCommitCard(), const LatestCommitCard(),
const SizedBox(height: 14), const SizedBox(height: 14),
Text( I18nText(
"Patched Applications", 'homeView.patchedSubtitle',
style: GoogleFonts.inter( child: Text(
fontSize: 18, '',
style: GoogleFonts.inter(
fontSize: 18,
),
), ),
), ),
const SizedBox(height: 14), const SizedBox(height: 14),

View File

@ -1,4 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_i18n/flutter_i18n.dart';
import 'package:google_fonts/google_fonts.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/views/app_selector/app_selector_view.dart';
import 'package:revanced_manager/ui/widgets/app_selector_card.dart'; import 'package:revanced_manager/ui/widgets/app_selector_card.dart';
@ -29,11 +30,14 @@ class PatcherView extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
const SizedBox(height: 12), const SizedBox(height: 12),
Text( I18nText(
"Patcher", 'patcherView.widgetTitle',
style: GoogleFonts.inter( child: Text(
fontSize: 28, '',
fontWeight: FontWeight.w500, style: GoogleFonts.inter(
fontSize: 28,
fontWeight: FontWeight.w500,
),
), ),
), ),
const SizedBox(height: 23), const SizedBox(height: 23),

View File

@ -1,4 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_i18n/flutter_i18n.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:google_fonts/google_fonts.dart';
import 'package:revanced_manager/constants.dart'; import 'package:revanced_manager/constants.dart';
@ -23,17 +24,23 @@ class AppSelectorCard extends StatelessWidget {
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text( I18nText(
"Select application", 'appSelectorCard.widgetTitle',
style: GoogleFonts.roboto( child: Text(
fontSize: 18, '',
fontWeight: FontWeight.w500, style: GoogleFonts.roboto(
fontSize: 18,
fontWeight: FontWeight.w500,
),
), ),
), ),
const SizedBox(height: 10), const SizedBox(height: 10),
Text( I18nText(
"No application selected", 'appSelectorCard.widgetSubtitle',
style: robotoTextStyle, child: Text(
'',
style: robotoTextStyle,
),
), ),
], ],
), ),

View File

@ -1,4 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_i18n/flutter_i18n.dart';
import 'package:flutter_svg/flutter_svg.dart'; import 'package:flutter_svg/flutter_svg.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:google_fonts/google_fonts.dart';
import 'package:revanced_manager/constants.dart'; import 'package:revanced_manager/constants.dart';
@ -20,7 +21,7 @@ class ApplicationItem extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final isSVG = asset.endsWith(".svg"); final isSVG = asset.endsWith('.svg');
return ListTile( return ListTile(
horizontalTitleGap: 12.0, horizontalTitleGap: 12.0,
leading: isSVG leading: isSVG
@ -45,7 +46,10 @@ class ApplicationItem extends StatelessWidget {
style: robotoTextStyle, style: robotoTextStyle,
), ),
trailing: PatchTextButton( trailing: PatchTextButton(
text: "Patch", text: FlutterI18n.translate(
context,
'applicationItem.patchButton',
),
onPressed: onPressed, onPressed: onPressed,
), ),
); );

View File

@ -1,4 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_i18n/flutter_i18n.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:google_fonts/google_fonts.dart';
import 'package:revanced_manager/ui/widgets/application_item.dart'; import 'package:revanced_manager/ui/widgets/application_item.dart';
import 'package:revanced_manager/ui/widgets/patch_text_button.dart'; import 'package:revanced_manager/ui/widgets/patch_text_button.dart';
@ -21,51 +22,60 @@ class AvailableUpdatesCard extends StatelessWidget {
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
Text( I18nText(
"Updates Available(2)", 'availableUpdatesCard.widgetTitle',
style: GoogleFonts.inter( child: Text(
fontSize: 16, '',
color: const Color(0xff7792BA), style: GoogleFonts.inter(
fontWeight: FontWeight.w500, fontSize: 16,
color: const Color(0xff7792BA),
fontWeight: FontWeight.w500,
),
), ),
), ),
PatchTextButton( PatchTextButton(
text: "Patch all", text: FlutterI18n.translate(
context,
'availableUpdatesCard.patchButton',
),
onPressed: () {}, onPressed: () {},
backgroundColor: const Color(0xff7792BA), backgroundColor: const Color(0xff7792BA),
), ),
], ],
), ),
ApplicationItem( ApplicationItem(
asset: "assets/images/revanced.svg", asset: 'assets/images/revanced.svg',
name: "ReVanced", name: 'ReVanced',
releaseDate: "2 days ago", releaseDate: '2 days ago',
onPressed: () {}, onPressed: () {},
), ),
ApplicationItem( ApplicationItem(
asset: "assets/images/reddit.png", asset: 'assets/images/reddit.png',
name: "ReReddit", name: 'ReReddit',
releaseDate: "Released 1 month ago", releaseDate: 'Released 1 month ago',
onPressed: () {}, onPressed: () {},
), ),
const SizedBox(height: 4), const SizedBox(height: 4),
Text( I18nText(
"Changelog", 'availableUpdatesCard.changelogLabel',
style: GoogleFonts.roboto( child: Text(
color: const Color(0xff8691A0), '',
fontWeight: FontWeight.w700, style: GoogleFonts.roboto(
color: const Color(0xff8691A0),
fontWeight: FontWeight.w700,
),
), ),
), ),
const SizedBox(height: 4), const SizedBox(height: 4),
Text( Text(
"fix: we made the player even worse (you love)", 'fix: we made the player even worse (you love)',
style: GoogleFonts.roboto( style: GoogleFonts.roboto(
color: const Color(0xff8691A0), color: const Color(0xff8691A0),
), ),
), ),
const SizedBox(height: 4), const SizedBox(height: 4),
Text( Text(
"chore: guhhughghu", 'chore: guhhughghu',
style: GoogleFonts.roboto( style: GoogleFonts.roboto(
color: const Color(0xff8691A0), color: const Color(0xff8691A0),
), ),

View File

@ -1,4 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_i18n/flutter_i18n.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:google_fonts/google_fonts.dart';
import 'package:revanced_manager/ui/widgets/application_item.dart'; import 'package:revanced_manager/ui/widgets/application_item.dart';
@ -17,37 +18,43 @@ class InstalledAppsCard extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
children: [ children: [
Text( I18nText(
"Total Installed(3)", 'installedAppsCard.widgetTitle',
style: GoogleFonts.inter( child: Text(
fontSize: 16, '',
color: const Color(0xff7792BA), style: GoogleFonts.inter(
fontWeight: FontWeight.w500, fontSize: 16,
color: const Color(0xff7792BA),
fontWeight: FontWeight.w500,
),
), ),
), ),
ApplicationItem( ApplicationItem(
asset: "assets/images/revanced.svg", asset: 'assets/images/revanced.svg',
name: "ReVanced", name: 'ReVanced',
releaseDate: "2 days ago", releaseDate: '2 days ago',
onPressed: () {}, onPressed: () {},
), ),
Text( I18nText(
"Changelog", 'installedAppsCard.changelogLabel',
style: GoogleFonts.roboto( child: Text(
color: const Color(0xff8691A0), '',
fontWeight: FontWeight.w700, style: GoogleFonts.roboto(
color: const Color(0xff8691A0),
fontWeight: FontWeight.w700,
),
), ),
), ),
const SizedBox(height: 4), const SizedBox(height: 4),
Text( Text(
"fix: we made the player even worse (you love)", 'fix: we made the player even worse (you love)',
style: GoogleFonts.roboto( style: GoogleFonts.roboto(
color: const Color(0xff8691A0), color: const Color(0xff8691A0),
), ),
), ),
const SizedBox(height: 4), const SizedBox(height: 4),
Text( Text(
"chore: guhhughghu", 'chore: guhhughghu',
style: GoogleFonts.roboto( style: GoogleFonts.roboto(
color: const Color(0xff8691A0), color: const Color(0xff8691A0),
), ),

View File

@ -1,4 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_i18n/flutter_i18n.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:google_fonts/google_fonts.dart';
import 'package:revanced_manager/services/github_api.dart'; import 'package:revanced_manager/services/github_api.dart';
import 'package:revanced_manager/constants.dart'; import 'package:revanced_manager/constants.dart';
@ -13,14 +14,14 @@ class LatestCommitCard extends StatefulWidget {
class _LatestCommitCardState extends State<LatestCommitCard> { class _LatestCommitCardState extends State<LatestCommitCard> {
GithubAPI githubAPI = GithubAPI(); GithubAPI githubAPI = GithubAPI();
String lastPatcherCommit = "Loading..."; String lastPatcherCommit = 'Loading...';
String lastManagerCommit = "Loading..."; String lastManagerCommit = 'Loading...';
void latestCommit() async { void latestCommit() async {
// lastPatcherCommit = // lastPatcherCommit =
// await githubAPI.latestCommitTime("revanced", "revanced-patcher"); // await githubAPI.latestCommitTime('revanced', 'revanced-patcher');
// lastManagerCommit = // lastManagerCommit =
// await githubAPI.latestCommitTime("revanced", "revanced-manager"); // await githubAPI.latestCommitTime('revanced', 'revanced-manager');
} }
@override @override
@ -47,28 +48,34 @@ class _LatestCommitCardState extends State<LatestCommitCard> {
children: [ children: [
Row( Row(
children: [ children: [
Text( I18nText(
"Patcher: ", 'latestCommitCard.patcherLabel',
style: GoogleFonts.roboto( child: Text(
fontWeight: FontWeight.w700, '',
style: GoogleFonts.roboto(
fontWeight: FontWeight.w700,
),
), ),
), ),
Text( Text(
"$lastPatcherCommit ago", '$lastPatcherCommit ago',
style: robotoTextStyle, style: robotoTextStyle,
) )
], ],
), ),
Row( Row(
children: [ children: [
Text( I18nText(
"Manager: ", 'latestCommitCard.managerLabel',
style: GoogleFonts.roboto( child: Text(
fontWeight: FontWeight.w700, '',
style: GoogleFonts.roboto(
fontWeight: FontWeight.w700,
),
), ),
), ),
Text( Text(
"$lastManagerCommit ago", '$lastManagerCommit ago',
style: robotoTextStyle, style: robotoTextStyle,
) )
], ],
@ -76,7 +83,10 @@ class _LatestCommitCardState extends State<LatestCommitCard> {
], ],
), ),
PatchTextButton( PatchTextButton(
text: "Update Manager", text: FlutterI18n.translate(
context,
'latestCommitCard.updateButton',
),
onPressed: () {}, onPressed: () {},
backgroundColor: const Color(0xff7792BA), backgroundColor: const Color(0xff7792BA),
), ),

View File

@ -1,4 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_i18n/flutter_i18n.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:google_fonts/google_fonts.dart';
import 'package:revanced_manager/constants.dart'; import 'package:revanced_manager/constants.dart';
@ -23,17 +24,23 @@ class PatchSelectorCard extends StatelessWidget {
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text( I18nText(
"Select patches", 'patchSelectorCard.widgetTitle',
style: GoogleFonts.roboto( child: Text(
fontSize: 18, '',
fontWeight: FontWeight.w500, style: GoogleFonts.roboto(
fontSize: 18,
fontWeight: FontWeight.w500,
),
), ),
), ),
const SizedBox(height: 10), const SizedBox(height: 10),
Text( I18nText(
"Select an application first.", 'patchSelectorCard.widgetSubtitle',
style: robotoTextStyle, child: Text(
'',
style: robotoTextStyle,
),
), ),
], ],
), ),

View File

@ -216,6 +216,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "3.3.0" 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: flutter_lints:
dependency: "direct dev" dependency: "direct dev"
description: description:
@ -223,6 +230,11 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.1" version: "2.0.1"
flutter_localizations:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
flutter_svg: flutter_svg:
dependency: "direct main" dependency: "direct main"
description: description:
@ -235,6 +247,11 @@ packages:
description: flutter description: flutter
source: sdk source: sdk
version: "0.0.0" version: "0.0.0"
flutter_web_plugins:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
frontend_server_client: frontend_server_client:
dependency: transitive dependency: transitive
description: description:
@ -326,6 +343,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.3.1" version: "1.3.1"
intl:
dependency: transitive
description:
name: intl
url: "https://pub.dartlang.org"
source: hosted
version: "0.17.0"
io: io:
dependency: transitive dependency: transitive
description: description:
@ -702,6 +726,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.0.0" version: "1.0.0"
toml:
dependency: transitive
description:
name: toml
url: "https://pub.dartlang.org"
source: hosted
version: "0.13.1"
typed_data: typed_data:
dependency: transitive dependency: transitive
description: description:
@ -765,6 +796,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "6.1.0" version: "6.1.0"
xml2json:
dependency: transitive
description:
name: xml2json
url: "https://pub.dartlang.org"
source: hosted
version: "5.3.4"
yaml: yaml:
dependency: transitive dependency: transitive
description: description:

View File

@ -16,6 +16,7 @@ dependencies:
flutter: flutter:
sdk: flutter sdk: flutter
flutter_cache_manager: ^3.3.0 flutter_cache_manager: ^3.3.0
flutter_i18n: ^0.32.4
flutter_svg: ^1.1.1+1 flutter_svg: ^1.1.1+1
get_it: ^7.2.0 get_it: ^7.2.0
github: ^9.4.0 github: ^9.4.0
@ -41,3 +42,4 @@ flutter:
uses-material-design: true uses-material-design: true
assets: assets:
- assets/images/ - assets/images/
- assets/i18n/