grapesjs icon indicating copy to clipboard operation
grapesjs copied to clipboard

BUG: I18n functionality

Open ronaldohoch opened this issue 5 years ago • 5 comments

Version: latest

Are you able to reproduce the bug from the demo?

  • [] Yes
  • [ ] No

What is the expected behavior? to editor.I18n.setLocale("es") work in runtime.

Describe the bug detailed I don't know if it's a bug or it's not supposed to work this way, also, i don't know backbone enough to know if it's possible, but, when use editor.I18n.setLocale("es") on run time, it doesn't change the labels.

What is the current behavior? It's just set the locale internally, but not change the labels at runtime.

Describe the bug detailed

  • I created a new plugin to pass the localization files
import cookie from './cookie';

import pt from './i18n/pt';
import es from './i18n/es';

export default (editor, opts = {}) => {
  let login_language = cookie.get("login_language");
  let language = "";
  switch(login_language){
    case "en_US": language="en"; break;
    case "es_AR": language="es"; break;
    default: case "pt_BR": language="pt"; break;
  }

  const options = { ...{
    i18n: {},
    // default options
  },  ...opts };

  var I18nManager = editor.I18n;

  // Load i18n files
  I18nManager && I18nManager.addMessages({
    ...options.i18n,
    pt,
    es
  });
  
  //change editor localization
  I18nManager.setLocale(language);
};
  • On first load, got the current locale, set right on portuguese.
  • image
  • On set to spanish, it keeps the portuguese on first run:
  • image
  • If i change the tab, it set the messages to spanish:
  • image
  • And if i set it to en, we have 3 language set:
  • image
  • Here the 3 languages
  • image

Of course, the plugin works, if user is es, pt or en, it's setup properly. But when we will set up a new editor with plugins, we can't change the labels, or i don't know how 🤔 (This is why i've created this PR: https://github.com/artf/grapesjs-blocks-basic/pull/38)

ronaldohoch avatar Jul 14 '21 20:07 ronaldohoch

Yeah, unfortunately, at the moment the UI (once rendered) is not updating on locale changes, so you would need to rerender the editor.

artf avatar Jul 28 '21 12:07 artf

Well, i don't know if backbone have template binding, so i'll close for a while..

ronaldohoch avatar Jul 29 '21 20:07 ronaldohoch

Yeah, unfortunately, at the moment the UI (once rendered) is not updating on locale changes, so you would need to rerender the editor.

Has this not been solved yet? I tried to use editor.render(), it works, but it duplicates the panels...

leonardolima99 avatar May 16 '23 21:05 leonardolima99

This issue is not solved. It needs to be reopened. Setting the locale only works when initializing the editor.

padcom avatar Oct 15 '24 09:10 padcom

The problem still persists and the issue is still closed. When I use editor.render() I'm losing the custom plugins that I load during grapesjs.init(...). editor.refresh() doesn't help either. I can see that the editor gets the updated language in the browser console, but the changes are not being reflected to the UI.

The issue needs to be re-opened and I'm looking forward to a solution / or I'll try to provide one if I can

aliozinan avatar Feb 01 '26 17:02 aliozinan