Closed vonloxx closed 5 years ago
Hi @vonloxx, I'm sorry that I don't have an answer to your question. but, can I ask you how you implement WordPress i18n package in gutenberg-js?, I want to change the UI to another language.
Yassine Qr, thanks.
@Qoraiche, I think this explanation by @eliocro might help you:
Gutenberg does not use .po files directly. Instead translations are loaded from json (in JED format). The i18n package provides a method to load those translations: setLocaleData(
So there is no need to override, just set the translations (before the editor is initialised but after your globals).
import { i18n } from '@frontkom/gutenberg-js'; import translations from './translations';
const { setLocaleData, __, _n, sprintf } = i18n; setLocaleData(translations);
console.log(('User')); console.log(('Action'));
const num = 3; console.log(sprintf(_n('%d result', '%d results', num), num));
The format of the JSON (./translations) file is:
{ "": { "lang": "pt", "plural_forms": "nplurals=2; plural=(n != 1)" }, "User": [ "Utilizador" ], "Action": [ "Ação" ], "%d result": [ "Um resultado", "%d resultados" ] }
These objects have to generated from whatever system the backend uses. If it's .po files (as in WP) there are several tools to convert them.
Some references: http://messageformat.github.io/Jed/ https://www.npmjs.com/package/tannin https://github.com/WordPress/gutenberg/tree/master/packages/i18n
thanks, @SofiaSousa, I will try this soon!
@SofiaSousa @Qoraiche Is there any demo to view the detail code ? I really didn't try any thing about it. Thank you very much
Hi @QiShaoXuan,
I think we don't have it yet. I've created https://github.com/front/g-editor/issues/5 suggesting the translations implementation in g-editor.
Hi @QiShaoXuan,
I think we don't have it yet. I've created front/g-editor#5 suggesting the translations implementation in g-editor.
it is so sad but thank you , and one more question, do you have any thinking to solve it?
do you have any thinking to solve it?
Sorry, I didn't understand, to solve what?
import { i18n } from '@frontkom/gutenberg-js';
import { i18n } from '@frontkom/gutenberg-js'; import translations from './translations';
const { setLocaleData, __, _n, sprintf } = i18n; setLocaleData(translations);
console.log(('User')); console.log(('Action'));
const num = 3; console.log(sprintf(_n('%d result', '%d results', num), num));
@eliocro
I'm wondering if we could replace wordpress i18n package for something custom. I'm thinking about the Drupal implementation: on browser side, Drupal uses a javascript method Drupal.t() for translations. It would be nice if we could override wp's __() translation function before the editor is initialized.