-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Theme i18n: Add a block to allow strings in template files to be translated #33192
Conversation
Size Change: -3 B (0%) Total Size: 1.05 MB
ℹ️ View Unchanged
|
Hmmm I'm not sure we need this... <!-- wp:heading -->
<h2><!-- wp:i18n { "text": "Results:" } /--></h2>
<!-- /wp:heading --> it would look something like this: <!-- wp:heading { "translatable-text": "Results" } -->
<h2>Results</h2>
<!-- /wp:heading --> |
Agreed, while it's been an open discussion for a while, we haven't seen a lot of concrete use cases surface that would warrant a more complex system in place. Variants of localized text and content is something we do want to properly tackle for phase 4 at a site and user level, taking all those complexities into consideration, and I don't expect a block grammar solution to be in place until those requirements are made explicit. The examples I've seen so far generally fall into two groups: things that should be absorbed into blocks as defaults ("previous page / next page" on navigation, for example; or "no results" on query) and things that can be thought of as theme patterns, like the content of an opinionated 404 template. In that sense, I think patterns are a possible solution that has merit because it also addresses another current limitation — allowing a theme to design the content of a template or part while also making it available as a pattern for users. So maybe a |
For the context, my previous exploration of almost the same idea: #23268. I shared the conclusions in #23268 (comment):
Anyway, it's one year old now so things might changed 😄 |
Closing in favour of #33217 |
Description
This is a proposal for a new
i18n
block which would allow theme authors to have translated text inside template files. The premise is that a theme provides an i18n.php file which Gutenberg loads and uses to supply translations if they exist. If the translation is missing then we simply return the string.This could be expanded to allow for othe i18n options - if you pass a context attribute then we could call
_x
, if you pass a number attribute then we could call_n
. I'm posting this PR early to get feedback, but if people are on board with the approach I'm happy to add these features.How has this been tested?
To test this, you need the associated theme files, see: Automattic/themes#4164
Try changing text values in inside the
__
functions in the i18n.php in the theme, and you should see the change on the front of the site (in the search and 404 templates).Types of changes
New feature (non-breaking change which adds functionality)
Checklist:
*.native.js
files for terms that need renaming or removal).