Skip to content

Commit

Permalink
Make strings localized for files in the settings folder (#337)
Browse files Browse the repository at this point in the history
I eventually want to comb through the whole app, but this is what I had
energy for at the moment.
  • Loading branch information
swmarks authored Jul 9, 2023
1 parent 4274e2b commit a6eb51d
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 33 deletions.
27 changes: 25 additions & 2 deletions assets/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,24 @@
"@post_style": {},
"comment_style": "Comment Style",
"@comment_style": {},
"add_account": "Add account",
"@add_account": {},
"password": "Password",
"@password": {},
"email_or_username": "Email or Username",
"@email_or_username": {},
"totp_2fa_token": "TOTP 2FA Token (if enabled)",
"@totp_2fa_token": {},
"verification_email_sent": "Verification email sent",
"@verification_email_sent": {},
"registration_application_sent": "Registration application sent",
"@registration_application_sent": {},
"select_instance": "select_instance",
"@select_instance": {},
"sign_in": "Sign in",
"@sign_in": {},
"register": "Register",
"@register": {},
"posts": "Posts",
"@posts": {},
"comments": "Comments",
Expand Down Expand Up @@ -138,6 +150,8 @@
"@show_everything_feed_explanation": {},
"use_in_app_browser": "Use in-app browser",
"@use_in_app_browser": {},
"convert_webp_to_png": "Convert webp images to png",
"@convert_webp_to_png": {},
"other_settings": "Other",
"@other_settings": {},
"disable_animations": "Disable animations",
Expand Down Expand Up @@ -385,7 +399,6 @@
"@messages": {},
"banned_users": "Banned users",
"@banned_users": {},

"add_user_or_instance": "Add a user account or an instance",
"@add_user_or_instance": {},
"add_user": "Add user account",
Expand All @@ -408,9 +421,12 @@
"@import_settings": {},
"import_successful" : "Import successful",
"@import_successful": {},

"instance_url": "instance url",
"@instance_url": {},
"add_instance": "Add instance",
"@add_instance": {},
"instance_not_found": "instance not found",
"@instance_not_found": {},
"instance_added": "Instance successfully added",
"@instance_added": {},
"remove_instance": "Remove instance",
Expand All @@ -430,8 +446,12 @@
"@block":{},
"block_user": "Block user",
"@block_user":{},
"no_users_blocked": "No users blocked",
"@no_users_blocked":{},
"block_community": "Block community",
"@block_community":{},
"no_communities_blocked": "No communities blocked",
"@no_communities_blocked":{},
"unblock": "Unblock",
"@unblock":{},
"unblock_user": "Unblock user",
Expand Down Expand Up @@ -674,5 +694,8 @@
},
"try_again": "Try Again",
"@try_again": {
},
"kbin_instances_not_supported": "Please note that kbin instances are not supported at present.",
"@kbin_instances_not_supported": {
}
}
64 changes: 64 additions & 0 deletions lib/l10n/l10n_from_string.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ import 'gen/l10n.dart';

abstract class L10nStrings {
static const settings = 'settings';
static const blocks = 'blocks';
static const add_account = 'add_account';
static const password = 'password';
static const email_or_username = 'email_or_username';
static const verification_email_sent = 'verification_email_sent';
static const registration_application_sent = 'registration_application_sent';
static const select_instance = 'select_instance';
static const posts = 'posts';
static const comments = 'comments';
static const modlog = 'modlog';
Expand Down Expand Up @@ -52,6 +57,15 @@ abstract class L10nStrings {
static const users = 'users';
static const theme = 'theme';
static const language = 'language';
static const show_everything_feed = 'show_everything_feed';
static const show_everything_feed_explanation =
'show_everything_feed_explanation';
static const use_in_app_browser = 'use_in_app_browser';
static const convert_webp_to_png = 'convert_webp_to_png';
static const other_settings = 'other_settings';
static const disable_animations = 'disable_animations';
static const hide_nsfw = 'hide_nsfw';
static const hide_nsfw_explanation = 'hide_nsfw_explanation';
static const hot = 'hot';
static const new_ = 'new_';
static const old = 'old';
Expand Down Expand Up @@ -159,22 +173,40 @@ abstract class L10nStrings {
static const week = 'week';
static const month = 'month';
static const six_months = 'six_months';
static const instance_url = 'instance_url';
static const add_instance = 'add_instance';
static const instance_not_found = 'instance_not_found';
static const instance_added = 'instance_added';
static const required_field = 'required_field';
static const no_communities_found = 'no_communities_found';
static const network_error = 'network_error';
static const kbin_instances_not_supported = 'kbin_instances_not_supported';
static const block_user = 'block_user';
static const no_users_blocked = 'no_users_blocked';
static const block_community = 'block_community';
static const no_communities_blocked = 'no_communities_blocked';
static const unblock = 'unblock';
}

extension L10nFromString on String {
String tr(BuildContext context) {
switch (this) {
case L10nStrings.settings:
return L10n.of(context).settings;
case L10nStrings.blocks:
return L10n.of(context).blocks;
case L10nStrings.add_account:
return L10n.of(context).add_account;
case L10nStrings.password:
return L10n.of(context).password;
case L10nStrings.email_or_username:
return L10n.of(context).email_or_username;
case L10nStrings.verification_email_sent:
return L10n.of(context).verification_email_sent;
case L10nStrings.registration_application_sent:
return L10n.of(context).registration_application_sent;
case L10nStrings.select_instance:
return L10n.of(context).select_instance;
case L10nStrings.posts:
return L10n.of(context).posts;
case L10nStrings.comments:
Expand Down Expand Up @@ -261,6 +293,22 @@ extension L10nFromString on String {
return L10n.of(context).theme;
case L10nStrings.language:
return L10n.of(context).language;
case L10nStrings.show_everything_feed:
return L10n.of(context).show_everything_feed;
case L10nStrings.show_everything_feed_explanation:
return L10n.of(context).show_everything_feed_explanation;
case L10nStrings.use_in_app_browser:
return L10n.of(context).use_in_app_browser;
case L10nStrings.convert_webp_to_png:
return L10n.of(context).convert_webp_to_png;
case L10nStrings.other_settings:
return L10n.of(context).other_settings;
case L10nStrings.disable_animations:
return L10n.of(context).disable_animations;
case L10nStrings.hide_nsfw:
return L10n.of(context).hide_nsfw;
case L10nStrings.hide_nsfw_explanation:
return L10n.of(context).hide_nsfw_explanation;
case L10nStrings.hot:
return L10n.of(context).hot;
case L10nStrings.new_:
Expand Down Expand Up @@ -449,8 +497,12 @@ extension L10nFromString on String {
return L10n.of(context).month;
case L10nStrings.six_months:
return L10n.of(context).six_months;
case L10nStrings.instance_url:
return L10n.of(context).instance_url;
case L10nStrings.add_instance:
return L10n.of(context).add_instance;
case L10nStrings.instance_not_found:
return L10n.of(context).instance_not_found;
case L10nStrings.instance_added:
return L10n.of(context).instance_added;
case L10nStrings.required_field:
Expand All @@ -459,6 +511,18 @@ extension L10nFromString on String {
return L10n.of(context).no_communities_found;
case L10nStrings.network_error:
return L10n.of(context).network_error;
case L10nStrings.kbin_instances_not_supported:
return L10n.of(context).kbin_instances_not_supported;
case L10nStrings.block_user:
return L10n.of(context).block_user;
case L10nStrings.no_users_blocked:
return L10n.of(context).no_users_blocked;
case L10nStrings.block_community:
return L10n.of(context).block_community;
case L10nStrings.no_communities_blocked:
return L10n.of(context).no_communities_blocked;
case L10nStrings.unblock:
return L10n.of(context).unblock;

default:
return this;
Expand Down
18 changes: 9 additions & 9 deletions lib/pages/settings/add_account_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ class AddAccountPage extends HookWidget {

Navigator.of(context).pop();
} on VerifyEmailException {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
content: Text('Verification email sent'),
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(L10n.of(context).verification_email_sent),
));
} on RegistrationApplicationSentException {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
content: Text('Registration application sent'),
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(L10n.of(context).registration_application_sent),
));
} on Exception catch (err) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
Expand All @@ -107,7 +107,7 @@ class AddAccountPage extends HookWidget {
return Scaffold(
appBar: AppBar(
leading: const CloseButton(),
title: const Text('Add account'),
title: Text(L10n.of(context).add_account),
),
body: AutofillGroup(
child: ListView(
Expand All @@ -127,7 +127,7 @@ class AddAccountPage extends HookWidget {
),
),
RadioPicker<String>(
title: 'select instance',
title: L10n.of(context).select_instance,
values: accountsStore.instances.toList(),
groupValue: selectedInstance.value,
onChanged: (value) => selectedInstance.value = value,
Expand All @@ -146,7 +146,7 @@ class AddAccountPage extends HookWidget {
padding: EdgeInsets.all(8),
child: Icon(Icons.add),
),
title: const Text('Add instance'),
title: Text(L10n.of(context).select_instance),
onTap: () async {
final value =
await Navigator.of(context).push(AddInstancePage.route());
Expand Down Expand Up @@ -194,7 +194,7 @@ class AddAccountPage extends HookWidget {
ElevatedButton(
onPressed: handleSubmit,
child: !loading.loading
? const Text('Sign in')
? Text(L10n.of(context).sign_in)
: SizedBox(
width: 20,
height: 20,
Expand All @@ -213,7 +213,7 @@ class AddAccountPage extends HookWidget {
context: context,
);
},
child: const Text('Register'),
child: Text(L10n.of(context).register),
),
],
),
Expand Down
20 changes: 10 additions & 10 deletions lib/pages/settings/add_instance_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:lemmy_api_client/v3.dart';

import '../../hooks/debounce.dart';
import '../../hooks/stores.dart';
import '../../l10n/gen/l10n.dart';
import '../../util/cleanup_url.dart';
import '../../widgets/cached_network_image.dart';
import '../../widgets/fullscreenable_image.dart';
Expand Down Expand Up @@ -64,14 +65,13 @@ class AddInstancePage extends HookWidget {
return Scaffold(
appBar: AppBar(
leading: const CloseButton(),
title: const Text('Add instance'),
title: Text(L10n.of(context).add_instance),
),
body: Column(
children: [
const Padding(
padding: EdgeInsets.all(8),
child: Text('Please note that kbin instances are '
'not supported at present.'),
Padding(
padding: const EdgeInsets.all(8),
child: Text(L10n.of(context).kbin_instances_not_supported),
),
ListView(
shrinkWrap: true,
Expand All @@ -87,13 +87,13 @@ class AddInstancePage extends HookWidget {
),
))
else if (isSite.value == false)
const SizedBox(
SizedBox(
height: 150,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.close, color: Colors.red),
Text('instance not found')
const Icon(Icons.close, color: Colors.red),
Text(L10n.of(context).instance_not_found)
],
),
)
Expand All @@ -111,8 +111,8 @@ class AddInstancePage extends HookWidget {
keyboardType: TextInputType.url,
onSubmitted: (_) => handleAdd?.call(),
autocorrect: false,
decoration:
const InputDecoration(labelText: 'instance url'),
decoration: InputDecoration(
labelText: L10n.of(context).instance_url),
),
),
),
Expand Down
5 changes: 3 additions & 2 deletions lib/pages/settings/blocks/block_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter_typeahead/flutter_typeahead.dart';
import 'package:lemmy_api_client/v3.dart';
import 'package:provider/provider.dart';

import '../../../l10n/gen/l10n.dart';
import '../../../util/extensions/api.dart';
import '../../../widgets/avatar.dart';
import 'blocks_store.dart';
Expand All @@ -15,7 +16,7 @@ class BlockPersonDialog extends StatelessWidget {
@override
Widget build(BuildContext context) {
return AlertDialog(
title: const Text('Block User'),
title: Text(L10n.of(context).block_user),
content: TypeAheadField<PersonViewSafe>(
suggestionsCallback: (pattern) async {
if (pattern.trim().isEmpty) return const Iterable.empty();
Expand Down Expand Up @@ -73,7 +74,7 @@ class BlockCommunityDialog extends StatelessWidget {
@override
Widget build(BuildContext context) {
return AlertDialog(
title: const Text('Block Community'),
title: Text(L10n.of(context).block_community),
content: TypeAheadField<CommunityView>(
suggestionsCallback: (pattern) async {
if (pattern.trim().isEmpty) return const Iterable.empty();
Expand Down
5 changes: 3 additions & 2 deletions lib/pages/settings/blocks/block_tile.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';

import '../../../l10n/gen/l10n.dart';
import '../../../util/async_store_listener.dart';
import '../../../util/extensions/api.dart';
import '../../../util/goto.dart';
Expand All @@ -25,7 +26,7 @@ class BlockPersonTile extends StatelessWidget {
icon: store.unblockingState.isLoading
? const CircularProgressIndicator.adaptive()
: const Icon(Icons.cancel),
tooltip: 'unblock',
tooltip: L10n.of(context).unblock,
onPressed: store.unblock,
),
onTap: () {
Expand Down Expand Up @@ -55,7 +56,7 @@ class BlockCommunityTile extends HookWidget {
icon: store.unblockingState.isLoading
? const CircularProgressIndicator.adaptive()
: const Icon(Icons.cancel),
tooltip: 'unblock',
tooltip: L10n.of(context).unblock,
onPressed: store.unblock,
),
onTap: () {
Expand Down
Loading

0 comments on commit a6eb51d

Please sign in to comment.