Compare commits

..

4 Commits

Author SHA1 Message Date
jordi fita mas 8f74a96f38 Try to localize Gutenberg to Spanish, as an i18n test
Gutenberg uses its own @wordpress/i18n for internationalization, which
is not much more than a wrapper around tannin[0], a reimplementation of
Jed[1].

It uses the same brain-damaged idea of all JavaScript applications: load
a really huge JavaScript object with the source text as key, and the
translations, if there are plurals, as values.  That is what they call
“a gettext localization library”.

The problem now becomes: how do i extract the translatable strings from
the libraries?

Isolated Block Editor’s maintainer stance is very clear: “It’s
Gutenberg, so whatever you need to do there will work the same”[2]. In
other words, “don’t know; don’t care”.

Let’s see what Gutenberg people say.

Well, Gutenberg may not require WordPress, but their developers sure
assume that you are using WordPress[3], and if you complain then their
response is “Why do you think using wp-cli is not easy enough?”[4].

Apparently, before wp-cli they used @wordpress/babel-plugin-makepot,
that creates a POT file for each JavasScript processed with WebPack,
but does not extract the strings from imported packages.  Which is kind
of logical, but then where do i get the required JSON files i need to
load to translate their fucking overly complex piece of crap?

Or, said in another way, how does WordPress do it? Apparently, they do
the same they do for every other plugin[5]: with GlotPress[6].

That _would_ work if i used the exact same versions as the plugin does,
but it would not help me translate the strings from
@automattic/isolated-block-editor because they are **not** a WordPress
plugin.  And, as we saw previously, the maintainer does not care.

Well, i have to extract them myself somehow.  Using the uglies hack i
could muster, apparently, because wp-cli i18n refuses to extract strings
from inside node_modules: create a symlink from each source directory i
need to translate into my po folder, and use their beloved wp-cli i18n
to create the po, including the strings from my source.

Then i downloaded the plugin PO file to include the official translation
to Spanish, and wrote a couple to test whether these from Isolated Block
Editor were being correctly extracted.

However, i can **not** use wp-cli i18n to generate the JSON file because
the fucking thing wants to generate a single JSON file for each
JavaScript source file, thus generates around 650 JSON files.

Are we mad?!

The author of Jed recommends po2json and at this point i do not really
care if i need yet another fucking tool for this.  Just do it, but make
sure it is Jed’s 1.x version, otherwise “modern” Gutenberg does not know
what to do with the translations.

What a shitshow.

[0]: https://github.com/aduth/tannin
[1]: https://github.com/messageformat/Jed.
[2]: https://github.com/Automattic/isolated-block-editor/issues/195#issuecomment-1359566724
[3]: https://github.com/WordPress/gutenberg/issues/14803#issuecomment-479823416
[4]: https://github.com/WordPress/gutenberg/issues/14803#issuecomment-479581903
[5]: https://github.com/WordPress/gutenberg/issues/13535#issuecomment-458678681
[6]: https://developer.wordpress.org/block-editor/contributors/localizing/
2023-06-11 03:50:35 +02:00
jordi fita mas be41b01b0c Explicitly declare @wordpress/element dependency
I am using it to create the editor element, and it is already pulled
by @automattic/isolated-block-editor, but IntelliJ complains that i do
not have it in **my** package.json.
2023-06-11 02:09:07 +02:00
jordi fita mas f612a49434 Remove @wordpress/scripts
I do not use them, as are mainly for development of block for WordPress,
and pull a huge amount of useless packages.
2023-06-11 02:03:23 +02:00
jordi fita mas 17a86bd896 Add Markdown configuration for Intellij IDEA
I do not know why this fucker decided now to add this configuration
file, but i am too tired to fight back.
2023-06-11 01:55:57 +02:00
30 changed files with 13616 additions and 23668 deletions

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
/node_modules/ /node_modules/
/po/*.pot
/web/static/editor.css /web/static/editor.css
/web/static/editor.js /web/static/editor.js
/web/static/*.json

9
.idea/markdown.xml Normal file
View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MarkdownSettings">
<enabledExtensions>
<entry key="MermaidLanguageExtension" value="false" />
<entry key="PlantUMLLanguageExtension" value="false" />
</enabledExtensions>
</component>
</project>

View File

@ -5,6 +5,7 @@
<exclude-output /> <exclude-output />
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/web" type="java-resource" /> <sourceFolder url="file://$MODULE_DIR$/web" type="java-resource" />
<excludeFolder url="file://$MODULE_DIR$/po/src" />
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />

18
Makefile Normal file
View File

@ -0,0 +1,18 @@
DEFAULT_DOMAIN = editor
POT_FILE = po/$(DEFAULT_DOMAIN).pot
LINGUAS = es
JSON_FILES = $(patsubst %,web/static/%.json,$(LINGUAS))
locales: $(JSON_FILES)
po/%.po: $(POT_FILE)
msgmerge --no-wrap --update --backup=off $@ $<
web/static/%.json: po/%.po
npx po2json --format jed1.x $< $@
$(POT_FILE):
wp i18n make-pot . $@ --ignore-domain --include=editor,po/src
.PHONY: locales

View File

@ -1,7 +1,13 @@
module.exports = (api) => { module.exports = (api) => {
api.cache(true); api.cache(true);
return { return {
plugins: [
[
"@wordpress/babel-plugin-makepot",
{"output": "po/editor.pot"}
],
],
presets: ['@wordpress/babel-preset-default'], presets: ['@wordpress/babel-preset-default'],
}; };
}; };

View File

@ -1,4 +1,5 @@
import {render} from '@wordpress/element'; import {render} from '@wordpress/element';
import {__, setLocaleData} from '@wordpress/i18n';
import './style.scss'; import './style.scss';
import IsolatedBlockEditor, {ToolbarSlot} from '@automattic/isolated-block-editor'; import IsolatedBlockEditor, {ToolbarSlot} from '@automattic/isolated-block-editor';
@ -52,16 +53,25 @@ function save() {
fetch('/edit', requestOptions); fetch('/edit', requestOptions);
} }
render( async function load(editor) {
<IsolatedBlockEditor const response = await fetch('/static/es.json');
settings={settings} const result = await response.json();
onLoad={(parser, rawHandler) => onLoad(textarea.value, parser, rawHandler)} const localeData = result.locale_data.messages;
onSaveContent={(content) => saveBlocks(content, textarea)} localeData[""].domain = "default";
onError={() => document.location.reload()} setLocaleData(localeData, 'default');
> render(
<ToolbarSlot> <IsolatedBlockEditor
<Button onClick={save} variant="primary">Beep!</Button> settings={settings}
</ToolbarSlot> onLoad={(parser, rawHandler) => onLoad(textarea.value, parser, rawHandler)}
</IsolatedBlockEditor>, onSaveContent={(content) => saveBlocks(content, textarea)}
editor onError={() => document.location.reload()}
); >
<ToolbarSlot>
<Button onClick={save} variant="primary">{__('Beep!')}</Button>
</ToolbarSlot>
</IsolatedBlockEditor>,
editor
);
}
load(editor);

23853
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -10,7 +10,9 @@
"@wordpress/block-library": "8.8.0", "@wordpress/block-library": "8.8.0",
"@wordpress/components": "23.8.0", "@wordpress/components": "23.8.0",
"@wordpress/edit-post": "7.8.0", "@wordpress/edit-post": "7.8.0",
"@wordpress/format-library": "4.8.0" "@wordpress/element": "5.8.0",
"@wordpress/format-library": "4.8.0",
"@wordpress/i18n": "4.31.0"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.21.4", "@babel/core": "^7.21.4",
@ -20,11 +22,11 @@
"@emotion/styled": "^11.10.6", "@emotion/styled": "^11.10.6",
"@shopify/polyfills": "^4.0.3", "@shopify/polyfills": "^4.0.3",
"@wordpress/babel-preset-default": "^7.15.0", "@wordpress/babel-preset-default": "^7.15.0",
"@wordpress/scripts": "^26.2.0",
"babel-loader": "^9.1.2", "babel-loader": "^9.1.2",
"babel-plugin-inline-json-import": "^0.3.2", "babel-plugin-inline-json-import": "^0.3.2",
"css-loader": "^6.7.3", "css-loader": "^6.7.3",
"mini-css-extract-plugin": "^2.7.5", "mini-css-extract-plugin": "^2.7.5",
"po2json": "^0.4.5",
"react": "^18.2.0", "react": "^18.2.0",
"react-dom": "^18.2.0", "react-dom": "^18.2.0",
"sass-loader": "^13.2.2", "sass-loader": "^13.2.2",

13326
po/es.po Normal file

File diff suppressed because it is too large Load Diff

1
po/src/a11y Symbolic link
View File

@ -0,0 +1 @@
../../node_modules/@wordpress/a11y/src

1
po/src/annotations Symbolic link
View File

@ -0,0 +1 @@
../../node_modules/@wordpress/annotations/src

1
po/src/api-fetch Symbolic link
View File

@ -0,0 +1 @@
../../node_modules/@wordpress/api-fetch/src

1
po/src/block-editor Symbolic link
View File

@ -0,0 +1 @@
../../node_modules/@wordpress/block-editor/src

1
po/src/block-library Symbolic link
View File

@ -0,0 +1 @@
../../node_modules/@wordpress/block-library/src

1
po/src/blocks Symbolic link
View File

@ -0,0 +1 @@
../../node_modules/@wordpress/blocks/src

1
po/src/components Symbolic link
View File

@ -0,0 +1 @@
../../node_modules/@wordpress/components/src

1
po/src/core-data Symbolic link
View File

@ -0,0 +1 @@
../../node_modules/@wordpress/core-data/src

1
po/src/edit-post Symbolic link
View File

@ -0,0 +1 @@
../../node_modules/@wordpress/edit-post/src

1
po/src/editor Symbolic link
View File

@ -0,0 +1 @@
../../node_modules/@wordpress/editor/src

1
po/src/format-library Symbolic link
View File

@ -0,0 +1 @@
../../node_modules/@wordpress/format-library/src

1
po/src/interface Symbolic link
View File

@ -0,0 +1 @@
../../node_modules/@wordpress/interface/src

View File

@ -0,0 +1 @@
../../node_modules/@automattic/isolated-block-editor/src/

1
po/src/keycodes Symbolic link
View File

@ -0,0 +1 @@
../../node_modules/@wordpress/keycodes/src

1
po/src/list-reusable-blocks Symbolic link
View File

@ -0,0 +1 @@
../../node_modules/@wordpress/list-reusable-blocks/src

1
po/src/media-utils Symbolic link
View File

@ -0,0 +1 @@
../../node_modules/@wordpress/media-utils/src

1
po/src/preferences Symbolic link
View File

@ -0,0 +1 @@
../../node_modules/@wordpress/preferences/src

1
po/src/reusable-blocks Symbolic link
View File

@ -0,0 +1 @@
../../node_modules/@wordpress/reusable-blocks/src

1
po/src/rich-text Symbolic link
View File

@ -0,0 +1 @@
../../node_modules/@wordpress/rich-text/src

1
po/src/server-side-render Symbolic link
View File

@ -0,0 +1 @@
../../node_modules/@wordpress/server-side-render/src

1
po/src/widgets Symbolic link
View File

@ -0,0 +1 @@
../../node_modules/@wordpress/widgets/src