Skip to content

Commit

Permalink
feat: support overriding i18n (#550)
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasXu0 authored Oct 24, 2023
1 parent 522f17a commit 6d163b8
Show file tree
Hide file tree
Showing 36 changed files with 161 additions and 152 deletions.
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 @@ class _ResizableImageState extends State<ResizableImage> {
SizedBox.fromSize(
size: const Size(10, 10),
),
Text(AppFlowyEditorLocalizations.current.loading),
Text(AppFlowyEditorL10n.current.loading),
],
),
);
Expand All @@ -163,7 +163,7 @@ class _ResizableImageState extends State<ResizableImage> {
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 @@ void showActionMenu(
_menuItem(
context,
dir == TableDirection.col
? AppFlowyEditorLocalizations.current.colAddAfter
: AppFlowyEditorLocalizations.current.rowAddAfter,
? AppFlowyEditorL10n.current.colAddAfter
: AppFlowyEditorL10n.current.rowAddAfter,
dir == TableDirection.col
? Icons.last_page
: Icons.vertical_align_bottom, () {
Expand All @@ -52,8 +52,8 @@ void showActionMenu(
_menuItem(
context,
dir == TableDirection.col
? AppFlowyEditorLocalizations.current.colAddBefore
: AppFlowyEditorLocalizations.current.rowAddBefore,
? AppFlowyEditorL10n.current.colAddBefore
: AppFlowyEditorL10n.current.rowAddBefore,
dir == TableDirection.col
? Icons.first_page
: Icons.vertical_align_top, () {
Expand All @@ -63,24 +63,24 @@ void showActionMenu(
_menuItem(
context,
dir == TableDirection.col
? AppFlowyEditorLocalizations.current.colRemove
: AppFlowyEditorLocalizations.current.rowRemove,
? AppFlowyEditorL10n.current.colRemove
: AppFlowyEditorL10n.current.rowRemove,
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,
Icons.content_copy, () {
TableActions.duplicate(node, position, editorState, dir);
dismissOverlay();
}),
_menuItem(
context,
AppFlowyEditorLocalizations.current.backgroundColor,
AppFlowyEditorL10n.current.backgroundColor,
Icons.format_color_fill,
() {
final cell = dir == TableDirection.col
Expand Down Expand Up @@ -112,8 +112,8 @@ void showActionMenu(
_menuItem(
context,
dir == TableDirection.col
? AppFlowyEditorLocalizations.current.colClear
: AppFlowyEditorLocalizations.current.rowClear,
? AppFlowyEditorL10n.current.colClear
: AppFlowyEditorL10n.current.rowClear,
Icons.clear, () {
TableActions.clear(node, position, editorState, dir);
dismissOverlay();
Expand Down Expand Up @@ -180,14 +180,14 @@ void _showColorMenu(
left: left,
builder: (context) {
return ColorPicker(
title: AppFlowyEditorLocalizations.current.highlightColor,
title: AppFlowyEditorL10n.current.highlightColor,
selectedColorHex: selectedColorHex,
colorOptions: generateHighlightColorOptions(),
onSubmittedColorHex: (color) {
action(color);
dismissOverlay();
},
resetText: AppFlowyEditorLocalizations.current.clearHighlightColor,
resetText: AppFlowyEditorL10n.current.clearHighlightColor,
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 @@ class _FindMenuState extends State<FindMenu> {
});
},
decoration: _buildInputDecoration(
widget.localizations?.find ??
AppFlowyEditorLocalizations.current.find,
widget.localizations?.find ?? AppFlowyEditorL10n.current.find,
),
),
),
Expand All @@ -261,22 +261,22 @@ class _FindMenuState extends State<FindMenu> {
onPressed: () => widget.searchService.navigateToMatch(moveUp: true),
icon: const Icon(Icons.arrow_upward),
tooltip: widget.localizations?.previousMatch ??
AppFlowyEditorLocalizations.current.previousMatch,
AppFlowyEditorL10n.current.previousMatch,
),
// 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,
),
FindAndReplaceMenuIconButton(
iconButtonKey: const Key('closeButton'),
onPressed: widget.onDismiss,
icon: const Icon(Icons.close),
tooltip: widget.localizations?.close ??
AppFlowyEditorLocalizations.current.closeFind,
AppFlowyEditorL10n.current.closeFind,
),
// regex button
if (showRegexButton)
Expand All @@ -294,7 +294,7 @@ class _FindMenuState extends State<FindMenu> {
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 @@ class _FindMenuState extends State<FindMenu> {
? Colors.black
: Colors.grey,
),
tooltip: AppFlowyEditorLocalizations.current.caseSensitive,
tooltip: AppFlowyEditorL10n.current.caseSensitive,
),
],
);
Expand Down Expand Up @@ -384,7 +384,7 @@ class _ReplaceMenuState extends State<ReplaceMenu> {
},
decoration: _buildInputDecoration(
widget.localizations?.replace ??
AppFlowyEditorLocalizations.current.replace,
AppFlowyEditorL10n.current.replace,
),
),
),
Expand All @@ -393,7 +393,7 @@ class _ReplaceMenuState extends State<ReplaceMenu> {
onPressed: _replaceSelectedWord,
icon: const Icon(Icons.find_replace),
tooltip: widget.localizations?.replace ??
AppFlowyEditorLocalizations.current.replace,
AppFlowyEditorL10n.current.replace,
),
FindAndReplaceMenuIconButton(
iconButtonKey: const Key('replaceAllButton'),
Expand All @@ -402,7 +402,7 @@ class _ReplaceMenuState extends State<ReplaceMenu> {
),
icon: const Icon(Icons.change_circle_outlined),
tooltip: widget.localizations?.replaceAll ??
AppFlowyEditorLocalizations.current.replaceAll,
AppFlowyEditorL10n.current.replaceAll,
),
],
);
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

0 comments on commit 6d163b8

Please sign in to comment.