Apply locale to QuillEditor(contents)

pull/650/head
X Code 3 years ago
parent 17595aa438
commit 2c1856c578
  1. 1
      README.md
  2. 16
      lib/src/widgets/editor.dart
  3. 7
      lib/src/widgets/toolbar.dart

@ -114,6 +114,7 @@ Define `mobileWidth`, `mobileHeight`, `mobileMargin`, `mobileAlignment` as follo
The package offers translations for the quill toolbar, it will follow the system locale unless you set your own locale with: The package offers translations for the quill toolbar, it will follow the system locale unless you set your own locale with:
``` ```
QuillToolbar(locale: Locale('fr'), ...) QuillToolbar(locale: Locale('fr'), ...)
QuillEditor(locale: Locale('fr'), ...)
``` ```
Currently, translations are available for these locales: Currently, translations are available for these locales:
* `Locale('en')` * `Locale('en')`

@ -6,6 +6,7 @@ import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:i18n_extension/i18n_widget.dart';
import 'package:tuple/tuple.dart'; import 'package:tuple/tuple.dart';
import '../models/documents/document.dart'; import '../models/documents/document.dart';
@ -169,6 +170,7 @@ class QuillEditor extends StatefulWidget {
this.embedBuilder = defaultEmbedBuilder, this.embedBuilder = defaultEmbedBuilder,
this.linkActionPickerDelegate = defaultLinkActionPickerDelegate, this.linkActionPickerDelegate = defaultLinkActionPickerDelegate,
this.customStyleBuilder, this.customStyleBuilder,
this.locale,
this.floatingCursorDisabled = false, this.floatingCursorDisabled = false,
Key? key}) Key? key})
: super(key: key); : super(key: key);
@ -339,6 +341,10 @@ class QuillEditor extends StatefulWidget {
final EmbedBuilder embedBuilder; final EmbedBuilder embedBuilder;
final CustomStyleBuilder? customStyleBuilder; final CustomStyleBuilder? customStyleBuilder;
/// The locale to use for the editor toolbar, defaults to system locale
/// and more https://github.com/singerdmx/flutter-quill#translation-of-toolbar
final Locale? locale;
/// Delegate function responsible for showing menu with link actions on /// Delegate function responsible for showing menu with link actions on
/// mobile platforms (iOS, Android). /// mobile platforms (iOS, Android).
/// ///
@ -452,10 +458,12 @@ class QuillEditorState extends State<QuillEditor>
floatingCursorDisabled: widget.floatingCursorDisabled, floatingCursorDisabled: widget.floatingCursorDisabled,
); );
final editor = _selectionGestureDetectorBuilder.build( final editor = I18n(
behavior: HitTestBehavior.translucent, initialLocale: widget.locale,
child: child, child: _selectionGestureDetectorBuilder.build(
); behavior: HitTestBehavior.translucent,
child: child,
));
if (kIsWeb) { if (kIsWeb) {
// Intercept RawKeyEvent on Web to prevent it from propagating to parents // Intercept RawKeyEvent on Web to prevent it from propagating to parents

@ -424,12 +424,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
final FilePickImpl? filePickImpl; final FilePickImpl? filePickImpl;
///The locale to use for the editor toolbar, defaults to system locale /// The locale to use for the editor toolbar, defaults to system locale
///Currently the supported locales are:
/// * Locale('en')
/// * Locale('de')
/// * Locale('fr')
/// * Locale('zh', 'CN')
/// and more https://github.com/singerdmx/flutter-quill#translation-of-toolbar /// and more https://github.com/singerdmx/flutter-quill#translation-of-toolbar
final Locale? locale; final Locale? locale;

Loading…
Cancel
Save