From 2c1856c578bc050150642c433539ba26c8dac4e7 Mon Sep 17 00:00:00 2001
From: X Code <singerdmx@gmail.com>
Date: Thu, 3 Feb 2022 18:54:42 -0800
Subject: [PATCH] Apply locale to QuillEditor(contents)

---
 README.md                    |  1 +
 lib/src/widgets/editor.dart  | 16 ++++++++++++----
 lib/src/widgets/toolbar.dart |  7 +------
 3 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/README.md b/README.md
index 371c23ef..5c1520cf 100644
--- a/README.md
+++ b/README.md
@@ -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:
 ```
 QuillToolbar(locale: Locale('fr'), ...)
+QuillEditor(locale: Locale('fr'), ...)
 ```
 Currently, translations are available for these locales:
 * `Locale('en')`
diff --git a/lib/src/widgets/editor.dart b/lib/src/widgets/editor.dart
index 13766063..3e418287 100644
--- a/lib/src/widgets/editor.dart
+++ b/lib/src/widgets/editor.dart
@@ -6,6 +6,7 @@ import 'package:flutter/gestures.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter/rendering.dart';
 import 'package:flutter/services.dart';
+import 'package:i18n_extension/i18n_widget.dart';
 import 'package:tuple/tuple.dart';
 
 import '../models/documents/document.dart';
@@ -169,6 +170,7 @@ class QuillEditor extends StatefulWidget {
       this.embedBuilder = defaultEmbedBuilder,
       this.linkActionPickerDelegate = defaultLinkActionPickerDelegate,
       this.customStyleBuilder,
+      this.locale,
       this.floatingCursorDisabled = false,
       Key? key})
       : super(key: key);
@@ -339,6 +341,10 @@ class QuillEditor extends StatefulWidget {
   final EmbedBuilder embedBuilder;
   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
   /// mobile platforms (iOS, Android).
   ///
@@ -452,10 +458,12 @@ class QuillEditorState extends State<QuillEditor>
       floatingCursorDisabled: widget.floatingCursorDisabled,
     );
 
-    final editor = _selectionGestureDetectorBuilder.build(
-      behavior: HitTestBehavior.translucent,
-      child: child,
-    );
+    final editor = I18n(
+        initialLocale: widget.locale,
+        child: _selectionGestureDetectorBuilder.build(
+          behavior: HitTestBehavior.translucent,
+          child: child,
+        ));
 
     if (kIsWeb) {
       // Intercept RawKeyEvent on Web to prevent it from propagating to parents
diff --git a/lib/src/widgets/toolbar.dart b/lib/src/widgets/toolbar.dart
index 9bb93777..454fa415 100644
--- a/lib/src/widgets/toolbar.dart
+++ b/lib/src/widgets/toolbar.dart
@@ -424,12 +424,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
 
   final FilePickImpl? filePickImpl;
 
-  ///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')
+  /// 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;