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

feat: support overriding i18n #550

Merged
merged 1 commit into from
Oct 24, 2023
Merged
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
1 change: 1 addition & 0 deletions lib/appflowy_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export 'src/editor/block_component/rich_text/default_selectable_mixin.dart';
// editor part, including editor component, block component, etc.
export 'src/editor/editor.dart';
export 'src/editor/find_replace_menu/find_and_replace.dart';
export 'src/editor/l10n/appflowy_editor_l10n.dart';
export 'src/editor/selection_menu/selection_menu.dart';
// editor state
export 'src/editor_state.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:flutter/material.dart';

SelectionMenuItem dividerMenuItem = SelectionMenuItem(
name: AppFlowyEditorLocalizations.current.divider,
name: AppFlowyEditorL10n.current.divider,
icon: (editorState, isSelected, style) => SelectionMenuIconWidget(
icon: Icons.horizontal_rule,
isSelected: isSelected,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ class _UploadImageMenuState extends State<UploadImageMenu> {
height: 36,
child: TabBar(
tabs: [
Tab(text: AppFlowyEditorLocalizations.current.uploadImage),
Tab(text: AppFlowyEditorLocalizations.current.urlImage),
Tab(text: AppFlowyEditorL10n.current.uploadImage),
Tab(text: AppFlowyEditorL10n.current.urlImage),
],
labelColor: widget.headerColor,
unselectedLabelColor: Colors.grey,
Expand Down Expand Up @@ -204,7 +204,7 @@ class _UploadImageMenuState extends State<UploadImageMenu> {

Widget _buildInvalidLinkText() {
return Text(
AppFlowyEditorLocalizations.current.incorrectLink,
AppFlowyEditorL10n.current.incorrectLink,
style: const TextStyle(color: Colors.red, fontSize: 12),
);
}
Expand Down Expand Up @@ -240,7 +240,7 @@ class _UploadImageMenuState extends State<UploadImageMenu> {
}
},
child: Text(
AppFlowyEditorLocalizations.current.upload,
AppFlowyEditorL10n.current.upload,
style: TextStyle(
color: Theme.of(context).colorScheme.onPrimary,
fontSize: 14.0,
Expand Down Expand Up @@ -339,7 +339,7 @@ class _UploadImageMenuState extends State<UploadImageMenu> {
),
const SizedBox(height: 8.0),
Text(
AppFlowyEditorLocalizations.current.chooseImage,
AppFlowyEditorL10n.current.chooseImage,
style: const TextStyle(
fontSize: 14.0,
color: Color(0xff00BCF0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
SizedBox.fromSize(
size: const Size(10, 10),
),
Text(AppFlowyEditorLocalizations.current.loading),
Text(AppFlowyEditorL10n.current.loading),

Check warning on line 150 in lib/src/editor/block_component/image_block_component/resizable_image.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/block_component/image_block_component/resizable_image.dart#L150

Added line #L150 was not covered by tests
],
),
);
Expand All @@ -163,7 +163,7 @@
borderRadius: const BorderRadius.all(Radius.circular(4.0)),
border: Border.all(width: 1, color: Colors.black),
),
child: Text(AppFlowyEditorLocalizations.current.imageLoadFailed),
child: Text(AppFlowyEditorL10n.current.imageLoadFailed),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ final Map<String, BlockComponentBuilder> standardBlockComponentBuilderMap = {
ParagraphBlockKeys.type: ParagraphBlockComponentBuilder(
configuration: standardBlockComponentConfiguration.copyWith(
placeholderText: (_) => PlatformExtension.isDesktopOrWeb
? AppFlowyEditorLocalizations.current.slashPlaceHolder
? AppFlowyEditorL10n.current.slashPlaceHolder
: ' ',
),
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor/src/editor/toolbar/desktop/items/utils/overlay_util.dart';
import 'package:appflowy_editor/src/editor/block_component/table_block_component/util.dart';
import 'package:appflowy_editor/src/editor/toolbar/desktop/items/utils/overlay_util.dart';
import 'package:flutter/material.dart';

void showActionMenu(
BuildContext context,
Expand Down Expand Up @@ -41,8 +41,8 @@
_menuItem(
context,
dir == TableDirection.col
? AppFlowyEditorLocalizations.current.colAddAfter
: AppFlowyEditorLocalizations.current.rowAddAfter,
? AppFlowyEditorL10n.current.colAddAfter
: AppFlowyEditorL10n.current.rowAddAfter,

Check warning on line 45 in lib/src/editor/block_component/table_block_component/table_action_menu.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/block_component/table_block_component/table_action_menu.dart#L44-L45

Added lines #L44 - L45 were not covered by tests
dir == TableDirection.col
? Icons.last_page
: Icons.vertical_align_bottom, () {
Expand All @@ -52,8 +52,8 @@
_menuItem(
context,
dir == TableDirection.col
? AppFlowyEditorLocalizations.current.colAddBefore
: AppFlowyEditorLocalizations.current.rowAddBefore,
? AppFlowyEditorL10n.current.colAddBefore
: AppFlowyEditorL10n.current.rowAddBefore,

Check warning on line 56 in lib/src/editor/block_component/table_block_component/table_action_menu.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/block_component/table_block_component/table_action_menu.dart#L55-L56

Added lines #L55 - L56 were not covered by tests
dir == TableDirection.col
? Icons.first_page
: Icons.vertical_align_top, () {
Expand All @@ -63,24 +63,24 @@
_menuItem(
context,
dir == TableDirection.col
? AppFlowyEditorLocalizations.current.colRemove
: AppFlowyEditorLocalizations.current.rowRemove,
? AppFlowyEditorL10n.current.colRemove
: AppFlowyEditorL10n.current.rowRemove,

Check warning on line 67 in lib/src/editor/block_component/table_block_component/table_action_menu.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/block_component/table_block_component/table_action_menu.dart#L66-L67

Added lines #L66 - L67 were not covered by tests
Icons.delete, () {
TableActions.delete(node, position, editorState, dir);
dismissOverlay();
}),
_menuItem(
context,
dir == TableDirection.col
? AppFlowyEditorLocalizations.current.colDuplicate
: AppFlowyEditorLocalizations.current.rowDuplicate,
? AppFlowyEditorL10n.current.colDuplicate
: AppFlowyEditorL10n.current.rowDuplicate,

Check warning on line 76 in lib/src/editor/block_component/table_block_component/table_action_menu.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/block_component/table_block_component/table_action_menu.dart#L75-L76

Added lines #L75 - L76 were not covered by tests
Icons.content_copy, () {
TableActions.duplicate(node, position, editorState, dir);
dismissOverlay();
}),
_menuItem(
context,
AppFlowyEditorLocalizations.current.backgroundColor,
AppFlowyEditorL10n.current.backgroundColor,

Check warning on line 83 in lib/src/editor/block_component/table_block_component/table_action_menu.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/block_component/table_block_component/table_action_menu.dart#L83

Added line #L83 was not covered by tests
Icons.format_color_fill,
() {
final cell = dir == TableDirection.col
Expand Down Expand Up @@ -112,8 +112,8 @@
_menuItem(
context,
dir == TableDirection.col
? AppFlowyEditorLocalizations.current.colClear
: AppFlowyEditorLocalizations.current.rowClear,
? AppFlowyEditorL10n.current.colClear
: AppFlowyEditorL10n.current.rowClear,

Check warning on line 116 in lib/src/editor/block_component/table_block_component/table_action_menu.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/block_component/table_block_component/table_action_menu.dart#L115-L116

Added lines #L115 - L116 were not covered by tests
Icons.clear, () {
TableActions.clear(node, position, editorState, dir);
dismissOverlay();
Expand Down Expand Up @@ -180,14 +180,14 @@
left: left,
builder: (context) {
return ColorPicker(
title: AppFlowyEditorLocalizations.current.highlightColor,
title: AppFlowyEditorL10n.current.highlightColor,

Check warning on line 183 in lib/src/editor/block_component/table_block_component/table_action_menu.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/block_component/table_block_component/table_action_menu.dart#L183

Added line #L183 was not covered by tests
selectedColorHex: selectedColorHex,
colorOptions: generateHighlightColorOptions(),
onSubmittedColorHex: (color) {
action(color);
dismissOverlay();
},
resetText: AppFlowyEditorLocalizations.current.clearHighlightColor,
resetText: AppFlowyEditorL10n.current.clearHighlightColor,

Check warning on line 190 in lib/src/editor/block_component/table_block_component/table_action_menu.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/block_component/table_block_component/table_action_menu.dart#L190

Added line #L190 was not covered by tests
resetIconName: 'clear_highlight_color',
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ class _TableBlockComponentWidgetState extends State<TableBlockComponentWidget>
}

SelectionMenuItem tableMenuItem = SelectionMenuItem(
name: AppFlowyEditorLocalizations.current.table,
name: AppFlowyEditorL10n.current.table,
icon: (editorState, isSelected, style) => SelectionMenuIconWidget(
icon: Icons.table_view,
isSelected: isSelected,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'dart:async';

import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:flutter/gestures.dart';

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

Expand Down Expand Up @@ -52,7 +51,7 @@ TextSpan mobileTextSpanDecoratorForAttribute(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text(AppFlowyEditorLocalizations.current.editLink),
title: Text(AppFlowyEditorL10n.current.editLink),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(4),
),
Expand Down Expand Up @@ -122,12 +121,12 @@ class _LinkEditFormState extends State<LinkEditForm> {
keyboardType: TextInputType.text,
validator: (value) {
if (value == null || value.isEmpty) {
return AppFlowyEditorLocalizations.current.linkTextHint;
return AppFlowyEditorL10n.current.linkTextHint;
}
return null;
},
decoration: InputDecoration(
hintText: AppFlowyEditorLocalizations.current.linkText,
hintText: AppFlowyEditorL10n.current.linkText,
suffixIcon: IconButton(
icon: const Icon(
Icons.clear_rounded,
Expand All @@ -143,12 +142,12 @@ class _LinkEditFormState extends State<LinkEditForm> {
keyboardType: TextInputType.url,
validator: (value) {
if (value == null || value.isEmpty) {
return AppFlowyEditorLocalizations.current.linkAddressHint;
return AppFlowyEditorL10n.current.linkAddressHint;
}
return null;
},
decoration: InputDecoration(
hintText: AppFlowyEditorLocalizations.current.urlHint,
hintText: AppFlowyEditorL10n.current.urlHint,
suffixIcon: IconButton(
icon: const Icon(
Icons.clear_rounded,
Expand All @@ -164,7 +163,7 @@ class _LinkEditFormState extends State<LinkEditForm> {
children: [
TextButton(
child: Text(
AppFlowyEditorLocalizations.current.removeLink,
AppFlowyEditorL10n.current.removeLink,
style: TextStyle(color: Theme.of(context).colorScheme.error),
),
onPressed: () async {
Expand All @@ -184,7 +183,7 @@ class _LinkEditFormState extends State<LinkEditForm> {
style: TextButton.styleFrom(
textStyle: Theme.of(context).textTheme.labelLarge,
),
child: Text(AppFlowyEditorLocalizations.current.done),
child: Text(AppFlowyEditorL10n.current.done),
onPressed: () async {
if (_formKey.currentState!.validate()) {
final bool textChanged =
Expand Down
22 changes: 11 additions & 11 deletions lib/src/editor/find_replace_menu/find_replace_widget.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import 'package:appflowy_editor/appflowy_editor.dart';
import 'find_replace_menu_icon_button.dart';
import 'package:flutter/material.dart';

import 'find_replace_menu_icon_button.dart';

const double _iconButtonSize = 30;

class FindAndReplaceMenuWidget extends StatefulWidget {
Expand Down Expand Up @@ -239,8 +240,7 @@
});
},
decoration: _buildInputDecoration(
widget.localizations?.find ??
AppFlowyEditorLocalizations.current.find,
widget.localizations?.find ?? AppFlowyEditorL10n.current.find,
),
),
),
Expand All @@ -261,22 +261,22 @@
onPressed: () => widget.searchService.navigateToMatch(moveUp: true),
icon: const Icon(Icons.arrow_upward),
tooltip: widget.localizations?.previousMatch ??
AppFlowyEditorLocalizations.current.previousMatch,
AppFlowyEditorL10n.current.previousMatch,

Check warning on line 264 in lib/src/editor/find_replace_menu/find_replace_widget.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/find_replace_menu/find_replace_widget.dart#L264

Added line #L264 was not covered by tests
),
// next match button
FindAndReplaceMenuIconButton(
iconButtonKey: const Key('nextMatchButton'),
onPressed: () => widget.searchService.navigateToMatch(),
icon: const Icon(Icons.arrow_downward),
tooltip: widget.localizations?.nextMatch ??
AppFlowyEditorLocalizations.current.nextMatch,
AppFlowyEditorL10n.current.nextMatch,

Check warning on line 272 in lib/src/editor/find_replace_menu/find_replace_widget.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/find_replace_menu/find_replace_widget.dart#L272

Added line #L272 was not covered by tests
),
FindAndReplaceMenuIconButton(
iconButtonKey: const Key('closeButton'),
onPressed: widget.onDismiss,
icon: const Icon(Icons.close),
tooltip: widget.localizations?.close ??
AppFlowyEditorLocalizations.current.closeFind,
AppFlowyEditorL10n.current.closeFind,

Check warning on line 279 in lib/src/editor/find_replace_menu/find_replace_widget.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/find_replace_menu/find_replace_widget.dart#L279

Added line #L279 was not covered by tests
),
// regex button
if (showRegexButton)
Expand All @@ -294,7 +294,7 @@
height: 20,
color: widget.searchService.regex ? Colors.black : Colors.grey,
),
tooltip: AppFlowyEditorLocalizations.current.regex,
tooltip: AppFlowyEditorL10n.current.regex,
),
// case sensitive button
if (showCaseSensitiveButton)
Expand All @@ -315,7 +315,7 @@
? Colors.black
: Colors.grey,
),
tooltip: AppFlowyEditorLocalizations.current.caseSensitive,
tooltip: AppFlowyEditorL10n.current.caseSensitive,
),
],
);
Expand Down Expand Up @@ -384,7 +384,7 @@
},
decoration: _buildInputDecoration(
widget.localizations?.replace ??
AppFlowyEditorLocalizations.current.replace,
AppFlowyEditorL10n.current.replace,

Check warning on line 387 in lib/src/editor/find_replace_menu/find_replace_widget.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/find_replace_menu/find_replace_widget.dart#L387

Added line #L387 was not covered by tests
),
),
),
Expand All @@ -393,7 +393,7 @@
onPressed: _replaceSelectedWord,
icon: const Icon(Icons.find_replace),
tooltip: widget.localizations?.replace ??
AppFlowyEditorLocalizations.current.replace,
AppFlowyEditorL10n.current.replace,

Check warning on line 396 in lib/src/editor/find_replace_menu/find_replace_widget.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/find_replace_menu/find_replace_widget.dart#L396

Added line #L396 was not covered by tests
),
FindAndReplaceMenuIconButton(
iconButtonKey: const Key('replaceAllButton'),
Expand All @@ -402,7 +402,7 @@
),
icon: const Icon(Icons.change_circle_outlined),
tooltip: widget.localizations?.replaceAll ??
AppFlowyEditorLocalizations.current.replaceAll,
AppFlowyEditorL10n.current.replaceAll,

Check warning on line 405 in lib/src/editor/find_replace_menu/find_replace_widget.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/find_replace_menu/find_replace_widget.dart#L405

Added line #L405 was not covered by tests
),
],
);
Expand Down
5 changes: 5 additions & 0 deletions lib/src/editor/l10n/appflowy_editor_l10n.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import 'package:appflowy_editor/appflowy_editor.dart';

class AppFlowyEditorL10n extends AppFlowyEditorLocalizations {
static AppFlowyEditorLocalizations current = AppFlowyEditorL10n();
}
Loading