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

Using Gutenberg outside of WP #32790

Closed
alanps opened this issue Jun 17, 2021 · 5 comments
Closed

Using Gutenberg outside of WP #32790

alanps opened this issue Jun 17, 2021 · 5 comments
Labels
[Type] Help Request Help with setup, implementation, or "How do I?" questions.

Comments

@alanps
Copy link

alanps commented Jun 17, 2021

I have the Gutenberg library that I got from Github and would like to know how to select Gutenberg language outside of Wordpress ? I saw that the translation files exist, I just didn't find a way to select them...

@gziolo gziolo added the [Type] Help Request Help with setup, implementation, or "How do I?" questions. label Jun 18, 2021
@hideokamoto
Copy link
Contributor

Gutenberg is using this package to provide a text translation.
https://github.com/WordPress/gutenberg/tree/trunk/packages/i18n

And it's using tannin and gettext libraries in nodejs.
Probably you can create a translation instance by using this method.
https://github.com/WordPress/gutenberg/blob/trunk/packages/i18n/src/create-i18n.js#L113-L142

Would you try this package and method?
Thanks.

@ntucakovic
Copy link

ntucakovic commented Jul 6, 2021

I'm trying to do the same; to use block-editor with custom blocks and a few gutenberg blocks from block-library package.

I'm struggling to figure out how localization is working with exposed gutenberg blocks outside of WP scope, specifically:

  • How does the i18n decide which locale is active and should be used
  • I suppose we need to have a singleton instance of i18n so we can add locale data to it. I'm unsure how gutenberg blocks from block-library can use those translations?
  • How can I provide locale data for blocks within block-library, as well as block inspector, and is there a JSON file available with locale data for those? That part is probably handled within WP, but I'm wondering whether I can do some extra steps to provide locale data for this case

@ntucakovic
Copy link

@alanps I've managed to set locale data to be consumed by both core blocks, block inspector, and custom blocks. It ended up being very trivial, I just wasn't aware that localization can't be changed after blocks are mounted.

setLocaleData({
    'No block selected.': ['Select something'],
    'Type / to choose a block': ['Type "/" to choose a block'],
    'Block inspector': ['Block editor'],
});

This needs to be executed before components are mounted. Otherwise, once mounted, default localization, defined in the brackets, will be consumed, as locale data will be empty.

Did you manage to find translation files for core blocks and components we could use to with setLocaleData?

@tellthemachines
Copy link
Contributor

@alanps @ntucakovic if your problem is solved are we good to close this issue now?

@tellthemachines
Copy link
Contributor

I'm going to go ahead and close this issue; feel free to open a new one if you have any further questions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Help Request Help with setup, implementation, or "How do I?" questions.
Projects
None yet
Development

No branches or pull requests

5 participants