diff --git a/lib/l10n/l10n.dart b/lib/l10n/l10n.dart index 4211997..197f0f6 100644 --- a/lib/l10n/l10n.dart +++ b/lib/l10n/l10n.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; export 'package:flutter_gen/gen_l10n/l10n.dart'; +export 'l10n_api.dart'; export 'l10n_from_string.dart'; abstract class LocaleSerde { diff --git a/lib/l10n/l10n_api.dart b/lib/l10n/l10n_api.dart new file mode 100644 index 0000000..5ec08f7 --- /dev/null +++ b/lib/l10n/l10n_api.dart @@ -0,0 +1,62 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_gen/gen_l10n/l10n.dart'; +import 'package:lemmy_api_client/v2.dart'; + +extension SortTypeL10n on SortType { + String tr(BuildContext context) { + switch (this) { + case SortType.hot: + return L10n.of(context).hot; + case SortType.new_: + return L10n.of(context).new_; + case SortType.topYear: + case SortType.topMonth: + case SortType.topDay: + case SortType.topAll: + case SortType.newComments: + case SortType.active: + case SortType.mostComments: + default: + // TODO: l10n string + return value; + } + } +} + +extension PostListingTypeL10n on PostListingType { + String tr(BuildContext context) { + switch (this) { + case PostListingType.all: + return L10n.of(context).all; + case PostListingType.community: + return L10n.of(context).community; + case PostListingType.local: + return L10n.of(context).local; + case PostListingType.subscribed: + return L10n.of(context).subscribed; + default: + throw Exception('unreachable'); + } + } +} + +extension SearchTypeL10n on SearchType { + String tr(BuildContext context) { + switch (this) { + case SearchType.all: + return L10n.of(context).all; + case SearchType.comments: + return L10n.of(context).comments; + case SearchType.communities: + return L10n.of(context).communities; + case SearchType.posts: + return L10n.of(context).posts; + case SearchType.url: + return L10n.of(context).url; + case SearchType.users: + return L10n.of(context).users; + default: + throw Exception('unreachable'); + } + } +} diff --git a/lib/pages/home_tab.dart b/lib/pages/home_tab.dart index 139729d..e9c5a1f 100644 --- a/lib/pages/home_tab.dart +++ b/lib/pages/home_tab.dart @@ -189,7 +189,7 @@ class HomeTab extends HookWidget { } final title = () { - final first = selectedList.value.listingType.value; + final first = selectedList.value.listingType.tr(context); final last = selectedList.value.instanceHost == null ? '' diff --git a/lib/pages/manage_account.dart b/lib/pages/manage_account.dart index 49140e0..73855a2 100644 --- a/lib/pages/manage_account.dart +++ b/lib/pages/manage_account.dart @@ -287,7 +287,7 @@ class _ManageAccount extends HookWidget { Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text(L10n.of(context).type), + Text(L10n.of(context).sort_type), const Text( 'This has currently no effect on lemmur', style: TextStyle(fontSize: 10),