Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ノートの翻訳を追加 #500

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/l10n/app_ja.arb
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,15 @@
"openNoteInBrowsers": "ブラウザでノートを開く",
"changeFullScreen": "フルスクリーンに切り替え",
"shareNotes": "ノートを共有",
"translateNote": "ノートを翻訳",
"translatedFrom": "{lang}から翻訳",
"@translatedFrom": {
"placeholders": {
"lang": {
"type": "String"
}
}
},
"deleteFavorite": "お気に入り解除",
"notesAfterRenote": "リノート直後のノート",
"deletedRecreate": "削除してなおす",
Expand Down
2 changes: 2 additions & 0 deletions lib/router/app_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import "package:miria/view/common/color_picker_dialog.dart";
import "package:miria/view/common/misskey_notes/reaction_user_dialog.dart";
import "package:miria/view/common/misskey_notes/renote_modal_sheet.dart";
import "package:miria/view/common/misskey_notes/renote_user_dialog.dart";
import "package:miria/view/common/misskey_notes/translate_note_modal_sheet.dart";
import "package:miria/view/explore_page/explore_page.dart";
import "package:miria/view/explore_page/explore_role_users_page.dart";
import "package:miria/view/favorited_note_page/favorited_note_page.dart";
Expand Down Expand Up @@ -170,6 +171,7 @@ class AppRouter extends _$AppRouter {
AutoModalRouteSheet(page: AntennaModalRoute.page),
AutoModalRouteSheet(page: ClipModalRoute.page),
AutoModalRouteSheet(page: UsersListModalRoute.page),
AutoModalRouteSheet(page: TranslateNoteModalRoute.page),
AutoModalRouteSheet<DriveModalSheetReturnValue>(page: DriveModalRoute.page),
];
}
Expand Down
61 changes: 59 additions & 2 deletions lib/router/app_router.gr.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/state_notifier/common/download_file_notifier.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

111 changes: 111 additions & 0 deletions lib/view/common/misskey_notes/translate_note_modal_sheet.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import "package:auto_route/auto_route.dart";
import "package:flutter/material.dart";
import "package:flutter/services.dart";
import "package:flutter_gen/gen_l10n/app_localizations.dart";
import "package:hooks_riverpod/hooks_riverpod.dart";
import "package:miria/providers.dart";
import "package:miria/view/common/account_scope.dart";
import "package:miria/view/common/error_detail.dart";
import "package:miria/view/common/misskey_notes/mfm_text.dart";
import "package:misskey_dart/misskey_dart.dart";
import "package:riverpod_annotation/riverpod_annotation.dart";

poppingmoon marked this conversation as resolved.
Show resolved Hide resolved
part "translate_note_modal_sheet.g.dart";

@Riverpod(dependencies: [misskeyPostContext])
FutureOr<NotesTranslateResponse> _notesTranslate(
_NotesTranslateRef ref, {
required String noteId,
required String targetLang,
}) {
return ref.read(misskeyPostContextProvider).notes.translate(
NotesTranslateRequest(
noteId: noteId,
targetLang: targetLang,
),
);
}

@RoutePage()
class TranslateNoteModalSheet extends ConsumerWidget
implements AutoRouteWrapper {
const TranslateNoteModalSheet({
required this.accountContext,
required this.note,
super.key,
});

final AccountContext accountContext;
final Note note;

@override
Widget wrappedRoute(BuildContext context) =>
AccountContextScope(context: accountContext, child: this);

@override
Widget build(BuildContext context, WidgetRef ref) {
final translatedNote = ref.watch(
_notesTranslateProvider(
noteId: note.id,
targetLang: Localizations.localeOf(context).toLanguageTag(),
),
);

return Scaffold(
body: ListView(
children: [
...switch (translatedNote) {
AsyncValue(valueOrNull: final translatedNote?) => [
ListTile(
title: Text(
S.of(context).translatedFrom(translatedNote.sourceLang),
),
trailing: IconButton(
tooltip: S.of(context).copyContents,
onPressed: () async {
await Clipboard.setData(
ClipboardData(text: translatedNote.text),
);
if (!context.mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(S.of(context).doneCopy),
duration: const Duration(seconds: 1),
),
);
},
icon: const Icon(Icons.copy),
),
),
const Divider(height: 0.0),
SizedBox(
width: double.infinity,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: MfmText(
mfmText: translatedNote.text,
host: note.user.host,
emoji: note.emojis,
isEnableAnimatedMFM: ref
.watch(generalSettingsRepositoryProvider)
.settings
.enableAnimatedMFM,
),
),
),
],
AsyncValue(:final error?, :final stackTrace) => [
ErrorDetail(error: error, stackTrace: stackTrace),
],
_ => [
const Padding(
padding: EdgeInsets.all(8.0),
child: Center(child: CircularProgressIndicator.adaptive()),
),
],
},
],
),
);
}
}
Loading