Skip to content

Commit

Permalink
improve localizations
Browse files Browse the repository at this point in the history
  • Loading branch information
pyrossh committed Aug 26, 2023
1 parent 63f41de commit 2ce332c
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 26 deletions.
13 changes: 13 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
{
"languageTitle": "English",
"localeLanguageTitle": "English",
"oldTestamentTitle": "Old Testament",
"newTestamentTitle": "New Testament",
"bibleSelectTitle": "Please select a bible",
"settingsTitle": "Settings",
"bibleTitle": "Bible",
"themeTitle": "Theme",
"incrementFontTitle": "Increase font size",
"decrementFontTitle": "Decrease font size",
"boldFontTitle": "Bold font",
"engTitles": "Use English Titles",
"privacyPolicyTitle": "Privacy Policy",
"shareAppTitle": "Share the app",
"rateAppTitle": "Rate the app",
"aboutUsTitle": "About us",
"genesis": "Genesis",
"exodus": "Exodus",
"leviticus": "Leviticus",
Expand Down
17 changes: 15 additions & 2 deletions lib/l10n/app_hi.arb
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
{
"languageTitle": "Hindi",
"settingsTitle": "அமைப்புகள்",
"bibleTitle": "ಬೈಬಲ್",
"localeLanguageTitle": "हिंदी",
"oldTestamentTitle": "पुराना नियम",
"newTestamentTitle": "नया नियम",
"bibleSelectTitle": "कृपया एक बाइबिल चुनें",
"settingsTitle": "समायोजन",
"bibleTitle": "बाइबिल",
"themeTitle": "रंग",
"incrementFontTitle": "पढ़ने का माप बढ़ाएँ",
"decrementFontTitle": "पढ़ने का माप कम करें",
"boldFontTitle": "बोल्ड साइज़",
"engTitles": "अंग्रेजी शीर्षकों का प्रयोग करें",
"privacyPolicyTitle": "गोपनीयता नीति",
"shareAppTitle": "ऐप साझा करें",
"rateAppTitle": "एप्लिकेशन की श्रेणी बताओ",
"aboutUsTitle": "हमारे बारे में",
"genesis": "उत्पत्ति",
"exodus": "निर्गमन",
"leviticus": "लैव्यवस्था",
Expand Down
13 changes: 13 additions & 0 deletions lib/l10n/app_kn.arb
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
{
"languageTitle": "Kannada",
"localeLanguageTitle": "ಕನ್ನಡ",
"oldTestamentTitle": "ಹಳೆಯ ಒಡಂಬಡಿಕೆ",
"newTestamentTitle": "ಹೊಸ ಒಡಂಬಡಿಕೆಯು",
"bibleSelectTitle": "ದಯವಿಟ್ಟು ಬೈಬಲ್ ಆಯ್ಕೆಮಾಡಿ",
"settingsTitle": "ಸಂಯೋಜನೆಗಳು",
"bibleTitle": "ಬೈಬಲ್",
"themeTitle": "ಬಣ್ಣಗಳು",
"incrementFontTitle": "ಪಠ್ಯದ ಗಾತ್ರವನ್ನು ಹೆಚ್ಚಿಸಿ",
"decrementFontTitle": "ಪಠ್ಯದ ಗಾತ್ರವನ್ನು ಕಡಿಮೆ ಮಾಡಿ",
"boldFontTitle": "ದಪ್ಪ ಪಠ್ಯ",
"engTitles": "ಇಂಗ್ಲಿಷ್ ಶೀರ್ಷಿಕೆಗಳನ್ನು ಬಳಸಿ",
"privacyPolicyTitle": "ಗೌಪ್ಯತಾ ನೀತಿ",
"shareAppTitle": "ಅಪ್ಲಿಕೇಶನ್ ಹಂಚಿಕೊಳ್ಳಿ",
"rateAppTitle": "ಅಪ್ಲಿಕೇಶನ್ ಅನ್ನು ರೇಟ್ ಮಾಡಿ",
"aboutUsTitle": "ನಮ್ಮ ಬಗ್ಗೆ",
"genesis": "ಆದಿಕಾಂಡ",
"exodus": "ವಿಮೋಚನಕಾಂಡ",
"leviticus": "ಯಾಜಕಕಾಂಡ",
Expand Down
6 changes: 5 additions & 1 deletion lib/providers/app_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ class AppModel extends ChangeNotifier {
return Provider.of(context, listen: false);
}

static AppLocalizations getLocalizations(BuildContext context) {
return AppModel.of(context).engTitles ? lookupAppLocalizations(const Locale("en")) : AppLocalizations.of(context)!;
}

save() async {
final prefs = await SharedPreferences.getInstance();
await prefs.setString("bibleName", bible.name);
Expand Down Expand Up @@ -89,7 +93,7 @@ class AppModel extends ChangeNotifier {
}

List<String> getBookNames(BuildContext context) {
final l = engTitles ? lookupAppLocalizations(const Locale("en")) : AppLocalizations.of(context)!;
final l = getLocalizations(context);
return [
l.genesis,
l.exodus,
Expand Down
6 changes: 4 additions & 2 deletions lib/screens/bible_select_screen.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import "package:flutter/material.dart";
import "package:flutter_gen/gen_l10n/app_localizations.dart";
import "package:only_bible_app/providers/app_model.dart";
import "package:only_bible_app/utils.dart";
import "package:only_bible_app/widgets/scaffold_menu.dart";
import "package:only_bible_app/widgets/sliver_heading.dart";
import "package:only_bible_app/widgets/sliver_tile_grid.dart";
Expand All @@ -10,15 +11,16 @@ class BibleSelectScreen extends StatelessWidget {

@override
Widget build(BuildContext context) {
final locales = AppLocalizations.supportedLocales.sortedBy((e) => e.languageCode);
return ScaffoldMenu(
child: CustomScrollView(
physics: const BouncingScrollPhysics(),
slivers: [
const SliverHeading(title: "Bibles", showClose: true),
SliverHeading(title: AppLocalizations.of(context)!.bibleSelectTitle, showClose: true),
SliverTileGrid(
listType: ListType.large,
children: List.of(
AppLocalizations.supportedLocales.map((l) {
locales.map((l) {
return Localizations.override(
context: context,
locale: Locale(l.languageCode),
Expand Down
6 changes: 4 additions & 2 deletions lib/screens/book_select_screen.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "package:flutter/material.dart";
import "package:only_bible_app/providers/app_model.dart";
import "package:only_bible_app/widgets/scaffold_menu.dart";
import "package:only_bible_app/screens/chapter_select_screen.dart";
import "package:only_bible_app/widgets/sliver_heading.dart";
Expand Down Expand Up @@ -26,11 +27,12 @@ class BookSelectScreen extends StatelessWidget {

@override
Widget build(BuildContext context) {
final localizations = AppModel.getLocalizations(context);
return ScaffoldMenu(
child: CustomScrollView(
physics: const BouncingScrollPhysics(),
slivers: [
const SliverHeading(title: "Old Testament", showClose: true),
SliverHeading(title: localizations.oldTestamentTitle, showClose: true),
SliverTileGrid(
children: List.of(
bible.getOldBooks().map((book) {
Expand All @@ -41,7 +43,7 @@ class BookSelectScreen extends StatelessWidget {
}),
),
),
const SliverHeading(title: "New Testament", top: 30, bottom: 20),
SliverHeading(title: localizations.newTestamentTitle, top: 30, bottom: 20),
SliverTileGrid(
children: List.of(
bible.getNewBooks().map((book) {
Expand Down
5 changes: 5 additions & 0 deletions lib/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import "package:flutter/material.dart";
import "package:flutter/services.dart";
import "package:only_bible_app/models.dart";

extension MyIterable<E> on Iterable<E> {
Iterable<E> sortedBy(Comparable Function(E e) key) =>
toList()..sort((a, b) => key(a).compareTo(key(b)));
}

bool isDesktop() {
return defaultTargetPlatform == TargetPlatform.macOS ||
defaultTargetPlatform == TargetPlatform.windows ||
Expand Down
37 changes: 18 additions & 19 deletions lib/widgets/settings_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ import "package:flutter/material.dart";
import "package:only_bible_app/providers/app_model.dart";
import "package:only_bible_app/utils.dart";
import "package:settings_ui/settings_ui.dart";
import "package:flutter_gen/gen_l10n/app_localizations.dart";

class SettingsSheet extends StatelessWidget {
const SettingsSheet({super.key});

@override
Widget build(BuildContext context) {
final app = AppModel.of(context);
final localizations = AppLocalizations.of(context)!;
final localizations = AppModel.getLocalizations(context);
final iconColor = Theme.of(context).textTheme.bodyMedium!.color;
return SettingsList(
contentPadding: EdgeInsets.zero,
Expand All @@ -28,13 +27,13 @@ class SettingsSheet extends StatelessWidget {
tiles: [
SettingsTile.navigation(
leading: const Icon(Icons.book_outlined, color: Colors.blueAccent),
title: const Text("Bible"),
title: Text(localizations.bibleTitle),
value: Text(app.bible.name),
onPressed: app.changeBible,
),
SettingsTile.navigation(
leading: const Icon(Icons.color_lens_outlined, color: Colors.pink),
title: const Text("Theme"),
title: Text(localizations.themeTitle),
trailing: ToggleButtons(
onPressed: (int index) {
app.toggleDarkMode();
Expand All @@ -57,37 +56,37 @@ class SettingsSheet extends StatelessWidget {
],
),
),
SettingsTile.switchTile(
onToggle: (value) {
app.toggleBold();
},
initialValue: app.fontBold,
leading: Icon(Icons.format_bold, color: iconColor),
title: const Text("Font Bold"),
),
SettingsTile(
title: const Text("Increase font size"),
title: Text(localizations.incrementFontTitle),
leading: Icon(Icons.font_download, color: iconColor),
trailing: IconButton(
onPressed: app.increaseFont,
icon: const Icon(Icons.add_circle_outline, size: 32, color: Colors.redAccent),
),
),
SettingsTile(
title: const Text("Decrease font size"),
title: Text(localizations.decrementFontTitle),
leading: Icon(Icons.font_download, color: iconColor),
trailing: IconButton(
onPressed: app.decreaseFont,
icon: const Icon(Icons.remove_circle_outline, size: 32, color: Colors.blueAccent),
),
),
SettingsTile.switchTile(
onToggle: (value) {
app.toggleBold();
},
initialValue: app.fontBold,
leading: Icon(Icons.format_bold, color: iconColor),
title: Text(localizations.boldFontTitle),
),
SettingsTile.switchTile(
onToggle: (value) {
app.toggleEngBookNames();
},
initialValue: app.engTitles,
leading: Icon(Icons.abc, color: iconColor),
title: const Text("English Titles"),
title: Text(localizations.engTitles),
),
],
),
Expand All @@ -97,23 +96,23 @@ class SettingsSheet extends StatelessWidget {
tiles: [
SettingsTile.navigation(
leading: const Icon(Icons.policy_outlined, color: Colors.brown),
title: const Text("Privacy Policy"),
title: Text(localizations.privacyPolicyTitle),
onPressed: app.showPrivacyPolicy,
),
SettingsTile.navigation(
leading: const Icon(Icons.share_outlined, color: Colors.blueAccent),
title: const Text("Share the app"),
title: Text(localizations.shareAppTitle),
onPressed: app.shareAppLink,
),
if (!isDesktop()) // TODO: mabe support OSx if we release in that store
SettingsTile.navigation(
leading: Icon(Icons.star, color: Colors.yellowAccent.shade700),
title: const Text("Rate the app"),
title: Text(localizations.rateAppTitle),
onPressed: app.rateApp,
),
SettingsTile.navigation(
leading: Icon(Icons.info_outline, color: Theme.of(context).colorScheme.onBackground),
title: const Text("About us"),
title: Text(localizations.aboutUsTitle),
onPressed: app.showAboutUs,
),
],
Expand Down

0 comments on commit 2ce332c

Please sign in to comment.