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

[QUESTION] Translate #69

Closed
erikmompean opened this issue Jun 18, 2021 · 3 comments
Closed

[QUESTION] Translate #69

erikmompean opened this issue Jun 18, 2021 · 3 comments
Labels
question Further information is requested

Comments

@erikmompean
Copy link

Hi, nice plugin!

There is any way to translate the text on link functionality, pictures...dialogs?

@erikmompean erikmompean added the question Further information is requested label Jun 18, 2021
@tneotia
Copy link
Owner

tneotia commented Jun 18, 2021

Not directly through the plugin at the moment, but you can use the onButtonPressed function to override what happens on insert link/image button press, and add a custom dialog. You could go into the source and copy how I created the dialog and just change the text to be translated.

If you'd like an example let me know and I can cook something up this evening.

@tneotia
Copy link
Owner

tneotia commented Jun 18, 2021

Here's an example:

HtmlEditor(
  controller: controller,
  htmlToolbarOptions: HtmlToolbarOptions(
    onButtonPressed: (ButtonType type, bool? status,
        Function()? updateStatus) async {
      if (type == ButtonType.link) {
        final text = TextEditingController();
        final url = TextEditingController();
        final textFocus = FocusNode();
        final urlFocus = FocusNode();
        final formKey = GlobalKey<FormState>();
        var openNewTab = false;
        await showDialog(
            context: context,
            builder: (BuildContext context) {
          return StatefulBuilder(builder:
              (BuildContext context, StateSetter setState) {
            return AlertDialog(
              title: Text('Insert Link'),
              scrollable: true,
              content: Form(
                key: formKey,
                child: Column(
                    mainAxisSize: MainAxisSize.min,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text('Text to display',
                          style: TextStyle(
                              fontWeight: FontWeight.bold)),
                      SizedBox(height: 10),
                      TextField(
                        controller: text,
                        focusNode: textFocus,
                        textInputAction: TextInputAction.next,
                        decoration: InputDecoration(
                          border: OutlineInputBorder(),
                          hintText: 'Text',
                        ),
                        onSubmitted: (_) {
                          urlFocus.requestFocus();
                        },
                      ),
                      SizedBox(height: 20),
                      Text('URL',
                          style: TextStyle(
                              fontWeight: FontWeight.bold)),
                      SizedBox(height: 10),
                      TextFormField(
                        controller: url,
                        focusNode: urlFocus,
                        textInputAction: TextInputAction.done,
                        decoration: InputDecoration(
                          border: OutlineInputBorder(),
                          hintText: 'URL',
                        ),
                        validator: (String? value) {
                          if (value == null || value.isEmpty) {
                            return 'Please enter a URL!';
                          }
                          return null;
                        },
                      ),
                      Row(
                        children: <Widget>[
                          SizedBox(
                            height: 48.0,
                            width: 24.0,
                            child: Checkbox(
                              value: openNewTab,
                              activeColor: Color(0xFF827250),
                              onChanged: (bool? value) {
                                setState(() {
                                  openNewTab = value!;
                                });
                              },
                            ),
                          ),
                          ElevatedButton(
                            style: ElevatedButton.styleFrom(
                                primary: Theme.of(context)
                                    .dialogBackgroundColor,
                                padding: EdgeInsets.only(
                                    left: 5, right: 5),
                                elevation: 0.0),
                            onPressed: () {
                              setState(() {
                                openNewTab = !openNewTab;
                              });
                            },
                            child: Text('Open in new window',
                                style: TextStyle(
                                    color: Theme.of(context)
                                        .textTheme
                                        .bodyText1
                                        ?.color)),
                          ),
                        ],
                      ),
                    ]),
              ),
              actions: [
                TextButton(
                  onPressed: () {
                    Navigator.of(context).pop();
                  },
                  child: Text('Cancel'),
                ),
                TextButton(
                  onPressed: () async {
                    if (formKey.currentState!.validate()) {
                      controller.insertLink(
                        text.text.isEmpty ? url.text : text.text,
                        url.text,
                        openNewTab,
                      );
                      Navigator.of(context).pop();
                    }
                  },
                  child: Text('OK'),
                )
              ],
            );
          });
        });
        return false;
      }
      return true;
    },
  ),
),

So that overrides the default dialog and then you can customize it however you want - if you just want to translate then you can edit the strings in the example.

@tneotia
Copy link
Owner

tneotia commented Jun 25, 2021

Closing for now, hope it helped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants