feat: redefine i18n for editor (#3768)

This commit is contained in:
Lucas.Xu 2023-10-24 13:39:05 +08:00 committed by GitHub
parent 6c3d7d2079
commit 56c5d69b0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 818 additions and 27 deletions

View File

@ -1,5 +1,6 @@
import 'package:appflowy/plugins/document/application/doc_bloc.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/background_color/theme_background_color.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/i18n/editor_i18n.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/custom_image_block_component.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';
import 'package:appflowy/plugins/document/presentation/editor_style.dart';
@ -145,6 +146,7 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage> {
void initState() {
super.initState();
_initEditorL10n();
_initializeShortcuts();
indentableBlockTypes.add(ToggleListBlockKeys.type);
convertibleBlockTypes.add(ToggleListBlockKeys.type);
@ -489,7 +491,7 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage> {
List<SelectionMenuItem> _customSlashMenuItems() {
final items = [...standardSelectionMenuItems];
final imageItem = items.firstWhereOrNull(
(element) => element.name == AppFlowyEditorLocalizations.current.image,
(element) => element.name == AppFlowyEditorL10n.current.image,
);
if (imageItem != null) {
final imageItemIndex = items.indexOf(imageItem);
@ -620,4 +622,8 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage> {
return null;
};
}
void _initEditorL10n() {
AppFlowyEditorL10n.current = EditorI18n();
}
}

View File

@ -259,7 +259,7 @@ class ColorOptionAction extends PopoverActionCell {
...FlowyTint.values.map(
(e) => FlowyColorOption(
color: e.color(context),
i18n: e.tintName(AppFlowyEditorLocalizations.current),
i18n: e.tintName(AppFlowyEditorL10n.current),
id: e.id,
),
),

View File

@ -284,7 +284,7 @@ class _ChangeCoverPopoverState extends State<ChangeCoverPopover> {
.map(
(t) => ColorOption(
colorHex: t.color(context).toHex(),
name: t.tintName(AppFlowyEditorLocalizations.current),
name: t.tintName(AppFlowyEditorL10n.current),
),
)
.toList();

View File

@ -0,0 +1,673 @@
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:easy_localization/easy_localization.dart';
class EditorI18n extends AppFlowyEditorL10n {
// static AppFlowyEditorLocalizations current = EditorI18n();
EditorI18n();
@override
String get bold {
return LocaleKeys.editor_bold.tr();
}
/// `Bulleted List`
@override
String get bulletedList {
return LocaleKeys.editor_bulletedList.tr();
}
/// `Checkbox`
@override
String get checkbox {
return LocaleKeys.editor_checkbox.tr();
}
/// `Embed Code`
@override
String get embedCode {
return LocaleKeys.editor_embedCode.tr();
}
/// `H1`
@override
String get heading1 {
return LocaleKeys.editor_heading1.tr();
}
/// `H2`
@override
String get heading2 {
return LocaleKeys.editor_heading2.tr();
}
/// `H3`
@override
String get heading3 {
return LocaleKeys.editor_heading3.tr();
}
/// `Highlight`
@override
String get highlight {
return LocaleKeys.editor_highlight.tr();
}
/// `Color`
@override
String get color {
return LocaleKeys.editor_color.tr();
}
/// `Image`
@override
String get image {
return LocaleKeys.editor_image.tr();
}
/// `Italic`
@override
String get italic {
return LocaleKeys.editor_italic.tr();
}
/// `Link`
@override
String get link {
return LocaleKeys.editor_link.tr();
}
/// `Numbered List`
@override
String get numberedList {
return LocaleKeys.editor_numberedList.tr();
}
/// `Quote`
@override
String get quote {
return LocaleKeys.editor_quote.tr();
}
/// `Strikethrough`
@override
String get strikethrough {
return LocaleKeys.editor_strikethrough.tr();
}
/// `Text`
@override
String get text {
return LocaleKeys.editor_text.tr();
}
/// `Underline`
@override
String get underline {
return LocaleKeys.editor_underline.tr();
}
/// `Default`
@override
String get fontColorDefault {
return LocaleKeys.editor_fontColorDefault.tr();
}
/// `Gray`
@override
String get fontColorGray {
return LocaleKeys.editor_fontColorGray.tr();
}
/// `Brown`
@override
String get fontColorBrown {
return LocaleKeys.editor_fontColorBrown.tr();
}
/// `Orange`
@override
String get fontColorOrange {
return LocaleKeys.editor_fontColorOrange.tr();
}
/// `Yellow`
@override
String get fontColorYellow {
return LocaleKeys.editor_fontColorYellow.tr();
}
/// `Green`
@override
String get fontColorGreen {
return LocaleKeys.editor_fontColorGreen.tr();
}
/// `Blue`
@override
String get fontColorBlue {
return LocaleKeys.editor_fontColorBlue.tr();
}
/// `Purple`
@override
String get fontColorPurple {
return LocaleKeys.editor_fontColorPurple.tr();
}
/// `Pink`
@override
String get fontColorPink {
return LocaleKeys.editor_fontColorPink.tr();
}
/// `Red`
@override
String get fontColorRed {
return LocaleKeys.editor_fontColorRed.tr();
}
/// `Default background`
@override
String get backgroundColorDefault {
return LocaleKeys.editor_backgroundColorDefault.tr();
}
/// `Gray background`
@override
String get backgroundColorGray {
return LocaleKeys.editor_backgroundColorGray.tr();
}
/// `Brown background`
@override
String get backgroundColorBrown {
return LocaleKeys.editor_backgroundColorBrown.tr();
}
/// `Orange background`
@override
String get backgroundColorOrange {
return LocaleKeys.editor_backgroundColorOrange.tr();
}
/// `Yellow background`
@override
String get backgroundColorYellow {
return LocaleKeys.editor_backgroundColorYellow.tr();
}
/// `Green background`
@override
String get backgroundColorGreen {
return LocaleKeys.editor_backgroundColorGreen.tr();
}
/// `Blue background`
@override
String get backgroundColorBlue {
return LocaleKeys.editor_backgroundColorBlue.tr();
}
/// `Purple background`
@override
String get backgroundColorPurple {
return LocaleKeys.editor_backgroundColorPurple.tr();
}
/// `Pink background`
@override
String get backgroundColorPink {
return LocaleKeys.editor_backgroundColorPink.tr();
}
/// `Red background`
@override
String get backgroundColorRed {
return LocaleKeys.editor_backgroundColorRed.tr();
}
/// `Done`
@override
String get done {
return LocaleKeys.editor_done.tr();
}
/// `Cancel`
@override
String get cancel {
return LocaleKeys.editor_cancel.tr();
}
/// `Tint 1`
@override
String get tint1 {
return LocaleKeys.editor_tint1.tr();
}
/// `Tint 2`
@override
String get tint2 {
return LocaleKeys.editor_tint2.tr();
}
/// `Tint 3`
@override
String get tint3 {
return LocaleKeys.editor_tint3.tr();
}
/// `Tint 4`
@override
String get tint4 {
return LocaleKeys.editor_tint4.tr();
}
/// `Tint 5`
@override
String get tint5 {
return LocaleKeys.editor_tint5.tr();
}
/// `Tint 6`
@override
String get tint6 {
return LocaleKeys.editor_tint6.tr();
}
/// `Tint 7`
@override
String get tint7 {
return LocaleKeys.editor_tint7.tr();
}
/// `Tint 8`
@override
String get tint8 {
return LocaleKeys.editor_tint8.tr();
}
/// `Tint 9`
@override
String get tint9 {
return LocaleKeys.editor_tint9.tr();
}
/// `Purple`
@override
String get lightLightTint1 {
return LocaleKeys.editor_lightLightTint1.tr();
}
/// `Pink`
@override
String get lightLightTint2 {
return LocaleKeys.editor_lightLightTint2.tr();
}
/// `Light Pink`
@override
String get lightLightTint3 {
return LocaleKeys.editor_lightLightTint3.tr();
}
/// `Orange`
@override
String get lightLightTint4 {
return LocaleKeys.editor_lightLightTint4.tr();
}
/// `Yellow`
@override
String get lightLightTint5 {
return LocaleKeys.editor_lightLightTint5.tr();
}
/// `Lime`
@override
String get lightLightTint6 {
return LocaleKeys.editor_lightLightTint6.tr();
}
/// `Green`
@override
String get lightLightTint7 {
return LocaleKeys.editor_lightLightTint7.tr();
}
/// `Aqua`
@override
String get lightLightTint8 {
return LocaleKeys.editor_lightLightTint8.tr();
}
/// `Blue`
@override
String get lightLightTint9 {
return LocaleKeys.editor_lightLightTint9.tr();
}
/// `URL`
@override
String get urlHint {
return LocaleKeys.editor_urlHint.tr();
}
/// `Heading 1`
@override
String get mobileHeading1 {
return LocaleKeys.editor_mobileHeading1.tr();
}
/// `Heading 2`
@override
String get mobileHeading2 {
return LocaleKeys.editor_mobileHeading2.tr();
}
/// `Heading 3`
@override
String get mobileHeading3 {
return LocaleKeys.editor_mobileHeading3.tr();
}
/// `Text Color`
@override
String get textColor {
return LocaleKeys.editor_textColor.tr();
}
/// `Background Color`
@override
String get backgroundColor {
return LocaleKeys.editor_backgroundColor.tr();
}
/// `Add your link`
@override
String get addYourLink {
return LocaleKeys.editor_addYourLink.tr();
}
/// `Open link`
@override
String get openLink {
return LocaleKeys.editor_openLink.tr();
}
/// `Copy link`
@override
String get copyLink {
return LocaleKeys.editor_copyLink.tr();
}
/// `Remove link`
@override
String get removeLink {
return LocaleKeys.editor_removeLink.tr();
}
/// `Edit link`
@override
String get editLink {
return LocaleKeys.editor_editLink.tr();
}
/// `Text`
@override
String get linkText {
return LocaleKeys.editor_linkText.tr();
}
/// `Please enter text`
@override
String get linkTextHint {
return LocaleKeys.editor_linkTextHint.tr();
}
/// `Please enter URL`
@override
String get linkAddressHint {
return LocaleKeys.editor_linkAddressHint.tr();
}
/// `Highlight color`
@override
String get highlightColor {
return LocaleKeys.editor_highlightColor.tr();
}
/// `Clear highlight color`
@override
String get clearHighlightColor {
return LocaleKeys.editor_clearHighlightColor.tr();
}
/// `Custom color`
@override
String get customColor {
return LocaleKeys.editor_customColor.tr();
}
/// `Hex value`
@override
String get hexValue {
return LocaleKeys.editor_hexValue.tr();
}
/// `Opacity`
@override
String get opacity {
return LocaleKeys.editor_opacity.tr();
}
/// `Reset to default color`
@override
String get resetToDefaultColor {
return LocaleKeys.editor_resetToDefaultColor.tr();
}
/// `LTR`
@override
String get ltr {
return LocaleKeys.editor_ltr.tr();
}
/// `RTL`
@override
String get rtl {
return LocaleKeys.editor_rtl.tr();
}
/// `Auto`
@override
String get auto {
return LocaleKeys.editor_auto.tr();
}
/// `Cut`
@override
String get cut {
return LocaleKeys.editor_cut.tr();
}
/// `Copy`
@override
String get copy {
return LocaleKeys.editor_copy.tr();
}
/// `Paste`
@override
String get paste {
return LocaleKeys.editor_paste.tr();
}
/// `Find`
@override
String get find {
return LocaleKeys.editor_find.tr();
}
/// `Previous match`
@override
String get previousMatch {
return LocaleKeys.editor_previousMatch.tr();
}
/// `Next match`
@override
String get nextMatch {
return LocaleKeys.editor_nextMatch.tr();
}
/// `Close`
@override
String get closeFind {
return LocaleKeys.editor_closeFind.tr();
}
/// `Replace`
@override
String get replace {
return LocaleKeys.editor_replace.tr();
}
/// `Replace all`
@override
String get replaceAll {
return LocaleKeys.editor_replaceAll.tr();
}
/// `Regex`
@override
String get regex {
return LocaleKeys.editor_regex.tr();
}
/// `Case sensitive`
@override
String get caseSensitive {
return LocaleKeys.editor_caseSensitive.tr();
}
/// `Upload Image`
@override
String get uploadImage {
return LocaleKeys.editor_uploadImage.tr();
}
/// `URL Image`
@override
String get urlImage {
return LocaleKeys.editor_urlImage.tr();
}
/// `Incorrect Link`
@override
String get incorrectLink {
return LocaleKeys.editor_incorrectLink.tr();
}
/// `Upload`
@override
String get upload {
return LocaleKeys.editor_upload.tr();
}
/// `Choose an image`
@override
String get chooseImage {
return LocaleKeys.editor_chooseImage.tr();
}
/// `Loading`
@override
String get loading {
return LocaleKeys.editor_loading.tr();
}
/// `Could not load the image`
@override
String get imageLoadFailed {
return LocaleKeys.editor_imageLoadFailed.tr();
}
/// `Divider`
@override
String get divider {
return LocaleKeys.editor_divider.tr();
}
/// `Table`
@override
String get table {
return LocaleKeys.editor_table.tr();
}
/// `Add before`
@override
String get colAddBefore {
return LocaleKeys.editor_colAddBefore.tr();
}
/// `Add before`
@override
String get rowAddBefore {
return LocaleKeys.editor_rowAddBefore.tr();
}
/// `Add after`
@override
String get colAddAfter {
return LocaleKeys.editor_colAddAfter.tr();
}
/// `Add after`
@override
String get rowAddAfter {
return LocaleKeys.editor_rowAddAfter.tr();
}
/// `Remove`
@override
String get colRemove {
return LocaleKeys.editor_colRemove.tr();
}
/// `Remove`
@override
String get rowRemove {
return LocaleKeys.editor_rowRemove.tr();
}
/// `Duplicate`
@override
String get colDuplicate {
return LocaleKeys.editor_colDuplicate.tr();
}
/// `Duplicate`
@override
String get rowDuplicate {
return LocaleKeys.editor_rowDuplicate.tr();
}
/// `Clear Content`
@override
String get colClear {
return LocaleKeys.editor_colClear.tr();
}
/// `Clear Content`
@override
String get rowClear {
return LocaleKeys.editor_rowClear.tr();
}
/// `Enter a / to insert a block, or start typing`
@override
String get slashPlaceHolder {
return LocaleKeys.editor_slashPlaceHolder.tr();
}
}

View File

@ -4,7 +4,7 @@ import 'package:appflowy_editor/appflowy_editor.dart' hide Log;
import 'package:flutter/material.dart';
final customImageMenuItem = SelectionMenuItem(
name: AppFlowyEditorLocalizations.current.image,
name: AppFlowyEditorL10n.current.image,
icon: (editorState, isSelected, style) => SelectionMenuIconWidget(
name: 'image',
isSelected: isSelected,

View File

@ -127,7 +127,7 @@ class TableColorOptionAction extends PopoverActionCell {
...FlowyTint.values.map(
(e) => FlowyColorOption(
color: e.color(context),
i18n: e.tintName(AppFlowyEditorLocalizations.current),
i18n: e.tintName(AppFlowyEditorL10n.current),
id: e.id,
),
),

View File

@ -1,23 +1,20 @@
import 'package:appflowy/workspace/application/settings/notifications/notification_settings_cubit.dart';
import 'prelude.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:appflowy_editor/appflowy_editor.dart' hide Log;
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart';
import 'package:flowy_infra/theme.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:appflowy/plugins/document/presentation/more/cubit/document_appearance_cubit.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/user/application/user_settings_service.dart';
import 'package:appflowy/workspace/application/notifications/notification_service.dart';
import 'package:appflowy/workspace/application/settings/appearance/appearance_cubit.dart';
import 'package:appflowy/user/application/user_settings_service.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/workspace/application/settings/notifications/notification_settings_cubit.dart';
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart';
import 'package:appflowy_editor/appflowy_editor.dart' hide Log;
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra/theme.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import 'prelude.dart';
class InitAppWidgetTask extends LaunchTask {
const InitAppWidgetTask();
@ -144,8 +141,10 @@ class _ApplicationWidgetState extends State<ApplicationWidget> {
theme: state.lightTheme,
darkTheme: state.darkTheme,
themeMode: state.themeMode,
localizationsDelegates: context.localizationDelegates +
[AppFlowyEditorLocalizations.delegate],
localizationsDelegates: [
...context.localizationDelegates,
AppFlowyEditorLocalizations.delegate
],
supportedLocales: context.supportedLocales,
locale: state.locale,
routerConfig: routerConfig,

View File

@ -54,8 +54,8 @@ packages:
dependency: "direct main"
description:
path: "."
ref: "9ae85ea"
resolved-ref: "9ae85ea162606b79483c49550266c154c0cb500c"
ref: "6d163b8"
resolved-ref: "6d163b88976f6481c4eea5e91c0ed4d68378e56f"
url: "https://github.com/AppFlowy-IO/appflowy-editor.git"
source: git
version: "1.4.4"

View File

@ -47,7 +47,7 @@ dependencies:
appflowy_editor:
git:
url: https://github.com/AppFlowy-IO/appflowy-editor.git
ref: "9ae85ea"
ref: "6d163b8"
appflowy_popover:
path: packages/appflowy_popover

View File

@ -871,5 +871,118 @@
"error": {
"weAreSorry": "We're sorry",
"loadingViewError": "We're having trouble loading this view. Please check your internet connection, refresh the app, and do not hesitate to reach out to the team if the issue continues."
},
"editor": {
"bold": "Bold",
"bulletedList": "Bulleted List",
"checkbox": "Checkbox",
"embedCode": "Embed Code",
"heading1": "H1",
"heading2": "H2",
"heading3": "H3",
"highlight": "Highlight",
"color": "Color",
"image": "Image",
"italic": "Italic",
"link": "Link",
"numberedList": "Numbered List",
"quote": "Quote",
"strikethrough": "Strikethrough",
"text": "Text",
"underline": "Underline",
"fontColorDefault": "Default",
"fontColorGray": "Gray",
"fontColorBrown": "Brown",
"fontColorOrange": "Orange",
"fontColorYellow": "Yellow",
"fontColorGreen": "Green",
"fontColorBlue": "Blue",
"fontColorPurple": "Purple",
"fontColorPink": "Pink",
"fontColorRed": "Red",
"backgroundColorDefault": "Default background",
"backgroundColorGray": "Gray background",
"backgroundColorBrown": "Brown background",
"backgroundColorOrange": "Orange background",
"backgroundColorYellow": "Yellow background",
"backgroundColorGreen": "Green background",
"backgroundColorBlue": "Blue background",
"backgroundColorPurple": "Purple background",
"backgroundColorPink": "Pink background",
"backgroundColorRed": "Red background",
"done": "Done",
"cancel": "Cancel",
"tint1": "Tint 1",
"tint2": "Tint 2",
"tint3": "Tint 3",
"tint4": "Tint 4",
"tint5": "Tint 5",
"tint6": "Tint 6",
"tint7": "Tint 7",
"tint8": "Tint 8",
"tint9": "Tint 9",
"lightLightTint1": "Purple",
"lightLightTint2": "Pink",
"lightLightTint3": "Light Pink",
"lightLightTint4": "Orange",
"lightLightTint5": "Yellow",
"lightLightTint6": "Lime",
"lightLightTint7": "Green",
"lightLightTint8": "Aqua",
"lightLightTint9": "Blue",
"urlHint": "URL",
"mobileHeading1": "Heading 1",
"mobileHeading2": "Heading 2",
"mobileHeading3": "Heading 3",
"textColor": "Text Color",
"backgroundColor": "Background Color",
"addYourLink": "Add your link",
"openLink": "Open link",
"copyLink": "Copy link",
"removeLink": "Remove link",
"editLink": "Edit link",
"linkText": "Text",
"linkTextHint": "Please enter text",
"linkAddressHint": "Please enter URL",
"highlightColor": "Highlight color",
"clearHighlightColor": "Clear highlight color",
"customColor": "Custom color",
"hexValue": "Hex value",
"opacity": "Opacity",
"resetToDefaultColor": "Reset to default color",
"ltr": "LTR",
"rtl": "RTL",
"auto": "Auto",
"cut": "Cut",
"copy": "Copy",
"paste": "Paste",
"find": "Find",
"previousMatch": "Previous match",
"nextMatch": "Next match",
"closeFind": "Close",
"replace": "Replace",
"replaceAll": "Replace all",
"regex": "Regex",
"caseSensitive": "Case sensitive",
"uploadImage": "Upload Image",
"urlImage": "URL Image",
"incorrectLink": "Incorrect Link",
"upload": "Upload",
"chooseImage": "Choose an image",
"loading": "Loading",
"imageLoadFailed": "Could not load the image",
"divider": "Divider",
"table": "Table",
"colAddBefore": "Add before",
"rowAddBefore": "Add before",
"colAddAfter": "Add after",
"rowAddAfter": "Add after",
"colRemove": "Remove",
"rowRemove": "Remove",
"colDuplicate": "Duplicate",
"rowDuplicate": "Duplicate",
"colClear": "Clear Content",
"rowClear": "Clear Content",
"slashPlaceHolder": "Enter a / to insert a block, or start typing"
}
}