Skip to content

Commit

Permalink
[forum] [bulletin] i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
liplum committed Aug 27, 2024
1 parent 2740de4 commit 3f43a73
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 13 deletions.
5 changes: 5 additions & 0 deletions assets/l10n/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,9 @@ game:
toefl: TOEFL
forum:
navigation: Forum
title: SIT Forum
bulletin:
title: Bulletin
permission:
permissionDenied: Permission denied
permissionDeniedDescOf: "{} permission was not granted. Please check the app settings."
Expand Down Expand Up @@ -956,3 +959,5 @@ unspecified: Unspecified
shareQrCode: Share QR code
add: Add
rename: Rename
enter: Enter
comingSoon: COMING SOON
5 changes: 5 additions & 0 deletions assets/l10n/zh-Hans.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,9 @@ game:
toefl: 托福
forum:
navigation: 社区
title: 小应社区
bulletin:
title: 布告栏
permission:
permissionDenied: 没有权限
permissionDeniedDescOf: "{}权限未被授权,请检查应用的设置。"
Expand Down Expand Up @@ -956,3 +959,5 @@ unspecified: 未指定
shareQrCode: 分享二维码
add: 添加
rename: 重命名
enter: 进入
comingSoon: 敬请期待
5 changes: 5 additions & 0 deletions assets/l10n/zh-Hant.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,9 @@ game:
toefl: 托福
forum:
navigation: 社群
title: 小應社群
bulletin:
title: 佈告欄
permission:
permissionDenied: 沒有權限
permissionDeniedDescOf: "{}權限未授予許可,請檢查應用程式的設定。"
Expand Down Expand Up @@ -956,3 +959,5 @@ unspecified: 未指定
shareQrCode: 分享 QR 碼
add: 增加
rename: 重新命名
enter: 進入
comingSoon: 即將推出
12 changes: 12 additions & 0 deletions lib/backend/bulletin/i18n.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:easy_localization/easy_localization.dart';
import 'package:mimir/l10n/common.dart';

const i18n = _I18n();

class _I18n with CommonI18nMixin {
const _I18n();

static const ns = "bulletin";

String get title => "$ns.title".tr();
}
3 changes: 2 additions & 1 deletion lib/backend/bulletin/page/list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:mimir/widgets/markdown.dart';
import 'package:rettulf/rettulf.dart';

import '../entity/bulletin.dart';
import '../i18n.dart';

class BulletinListPage extends ConsumerStatefulWidget {
const BulletinListPage({super.key});
Expand Down Expand Up @@ -55,7 +56,7 @@ class _BulletinListPageState extends ConsumerState<BulletinListPage> {
body: CustomScrollView(
slivers: [
SliverAppBar.medium(
title: "Bulletin List".text(),
title: i18n.title.text(),
bottom: !fetching
? null
: const PreferredSize(
Expand Down
5 changes: 3 additions & 2 deletions lib/backend/bulletin/service/bulletin.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:mimir/init.dart';
import 'package:mimir/lifecycle.dart';

import 'package:mimir/session/mimir.dart';

Expand All @@ -11,7 +12,7 @@ class BulletinService {

Future<MimirBulletin?> getLatest() async {
final res = await _session.request(
"https://bulletin.mysit.life/v1/latest",
"https://bulletin.mysit.life/v1/latest?lang=${$locale}",
);
if (res.statusCode != 200) {
return null;
Expand All @@ -21,7 +22,7 @@ class BulletinService {

Future<List<MimirBulletin>> getList() async {
final res = await _session.request(
"https://bulletin.mysit.life/v1/list",
"https://bulletin.mysit.life/v1/list?lang=${$locale}",
);
if (res.statusCode != 200) {
return const [];
Expand Down
8 changes: 5 additions & 3 deletions lib/backend/forum/card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import 'package:mimir/l10n/extension.dart';
import 'package:mimir/settings/dev.dart';
import 'package:mimir/utils/guard_launch.dart';
import 'package:universal_platform/universal_platform.dart';
import "package:mimir/backend/bulletin/i18n.dart" as $bulletin;
import 'i18n.dart';

class ForumAppCard extends ConsumerStatefulWidget {
const ForumAppCard({super.key});
Expand Down Expand Up @@ -46,7 +48,7 @@ class _ForumAppCardState extends ConsumerState<ForumAppCard> {
final bulletin = ref.watch(BackendInit.bulletinStorage.$latest);
final dev = ref.watch(Dev.$on);
return AppCard(
title: "小应社区".text(),
title: i18n.title.text(),
view: bulletin == null ? null : BulletinLatestSummaryCard(bulletin),
leftActions: [
FilledButton.icon(
Expand All @@ -59,7 +61,7 @@ class _ForumAppCardState extends ConsumerState<ForumAppCard> {
await guardLaunchUrl(context, R.forumUri);
}
},
label: !dev ? "敬请期待".text() : "进入".text(),
label: !dev ? i18n.comingSoon.text() : i18n.enter.text(),
icon: Icon(context.icons.home),
),
OutlinedButton.icon(
Expand All @@ -69,7 +71,7 @@ class _ForumAppCardState extends ConsumerState<ForumAppCard> {
(ctx) => const BulletinListPage(),
);
},
label: "布告栏".text(),
label: $bulletin.i18n.title.text(),
icon: const Icon(Icons.list_alt),
),
],
Expand Down
8 changes: 1 addition & 7 deletions lib/backend/forum/i18n.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,9 @@ const i18n = _I18n();
class _I18n with CommonI18nMixin {
const _I18n();

final settings = const _Settings();

static const ns = "forum";

String get navigation => "$ns.navigation".tr();
String get title => "$ns.title".tr();
}

class _Settings {
const _Settings();

static const ns = "${_I18n.ns}.settings";
}
4 changes: 4 additions & 0 deletions lib/l10n/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ mixin class CommonI18nMixin {
String get add => "add".tr();

String get rename => "rename".tr();

String get enter => "enter".tr();

String get comingSoon => "comingSoon".tr();
}

class CommonI18n with CommonI18nMixin {
Expand Down
5 changes: 5 additions & 0 deletions lib/lifecycle.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:mimir/r.dart';

final $key = GlobalKey<NavigatorState>();

final $oaOnline = StateProvider((ref) => false);
final $campusNetworkAvailable = StateProvider((ref) => false);
final $studentRegAvailable = StateProvider((ref) => false);

Locale get $locale => $key.currentContext?.locale ?? R.defaultLocale;

0 comments on commit 3f43a73

Please sign in to comment.