Repository navigation
Conversation
…omies on init Every post type and taxonomy reaches WordPress through the entity registration service, from the callback of the init action. The factories and the configuring() support now hand it a TranslatingEntityRegistry, which calls Translator::resolve() on the arguments and names just before the adapter registers them, with the entity's text_domain (else pollora) as the default domain. Arguments without a Translatable are passed on unchanged. Adds the pollora:i18n:extract, :update and :compile commands (the commands of pollora/i18n, without their short aliases), registered in the console only. Requires pollora/i18n, added to composer.json in the next commit.
…ies on init
The discovery used to build the labels of a post type or a taxonomy while
Laravel boots, before `init`, with the singular and plural names as written
in the attribute. The domains of themes and plugins were not loaded yet, and
WordPress's translation functions were not available, so the templates
("Add New %s") were never looked up in a catalogue and the names never were.
The discovery now hands over the raw names and asks for the default labels
with TranslatingEntityRegistry::defaultLabels(). The registry, which runs in
the callback of `init`, translates the singular and plural names in the text
domain of the entity (`textDomain`, else `pollora`), translates each template,
then gives it the translated name. Labels written by the class (#[Labels],
withArgs(), configuring(), factory arguments) still win over the generated
ones, and their Translatable texts are resolved.
Without a catalogue the labels registered are the ones registered before. A
domain with no catalogue and no `gettext` filter is not asked for the names.
…take the label templates from pollora
The texts a post type or taxonomy attribute writes in the registration
arguments (#[Labels], Label, Description, TitlePlaceholder, FeaturedImage and
the titles of the admin columns) are looked up on init in the text domain of the
entity (`textDomain`, else `pollora`). A text with no translation comes back as
written, so a label written directly in the language of the site is unchanged.
The default labels already built, and the Translatable already resolved, are
not looked up again. Nothing is looked up in a domain that has no catalogue and
no `gettext` filter.
The generic templates of the default labels ("Add New %s", "All %s"...) belong
to the framework: they are always looked up in the `pollora` domain, whatever
the `textDomain` of the entity, and given the singular or plural name
translated in the domain of the entity.
The `pollora` catalogue was loaded by the service provider once WordPress was
up, which on a web request is after `init`, so the templates found no catalogue.
The registry now loads it, once per locale, before building the default labels,
and the provider reuses that call.
A test reads the fields the attributes declare translatable and checks that each
of them is translated on registration, and that nothing undeclared is.
…ollora catalogue The templates of the default labels of post types and taxonomies are looked up in the pollora domain. Five were in no catalogue: "No %s found in Trash", "%s Archives", "%s Attributes", "Insert into %s" and "Uploaded to this %s". They are added to the template and, untranslated, to each language file; the references of the other templates now point at their current place.
…tes up through __()
The check that skipped the lookup when a domain had no catalogue and nothing was
on the `gettext` filter cost about as much as the lookup it saved, and it left
out the `gettext_{domain}` and `gettext_with_context_{domain}` filters. The
singular and plural names, the explicit labels, `label`, `description`,
`title_placeholder`, `featured_image` and the titles of the admin columns now
all go through __(). The catalogue of the framework is still loaded on init.
…d no translation No %s found in Trash, %s Archives, %s Attributes, Insert into %s and Uploaded to this %s, in the seven languages the framework ships. Gender-neutral forms, as the other templates of the catalogue.
pollora/i18n resolves the Translatable markers and runs the extraction commands; pollora/attributes 0.1.2 ships resources/i18n.php, which the test that guards the translated fields reads.
…ature The stand-in took two parameters, so Rector, which only knew that declaration, read the third argument the e2e fixture passes as an extra one and wanted it removed. It takes the optional locale WordPress has, and the closure of the catalogue helper declares its return type.
…covery tests, and isolate the provider locale tests
Member
Author
|
CI was red on this branch because of three interactions with tests merged into
Full suite on this branch merged with |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The names and labels of post types and taxonomies could not be translated:
singular: 'Book'is a literal, and the default labels were computed when Laravel boots, beforeinit, from that untranslated literal. They are now built and translated in theinitcallback, where the text domains are loaded.TranslatingEntityRegistrydecorates the registry ofpollora/entityat the three places the framework creates it, and resolves the arguments just beforeregister_post_type()/register_taxonomy().TranslatableandTranslatablePlural(frompollora/i18n) written in an attribute argument, at any depth, are resolved there. This is how a text inside an array argument (admin columns, templates…) is marked: PHP does not allow__()in an attribute argument.Add New %s,Edit %s…) are built ininitfrom the translated singular and plural. Their templates are literal__('…', 'pollora')calls, sowp i18n make-potcollects them, and the framework's own catalogue supplies them whatevertextDomainthe entity declares.#[Labels],Label,Description,TitlePlaceholder,FeaturedImage, admin column titles) go through__($text, $textDomain); a text with no translation comes back unchanged. A test readsresources/i18n.phpofpollora/attributesand fails when a field declared as translatable is not translated, or the other way round.__()is always called, so everygettextfilter (Polylang, WPML…) applies.polloracatalogue is now loaded oninit. It used to be loaded betweenwpandtemplate_redirect, so on the front end the shipped.monever reached these labels, and REST requests never loaded it at all.No %s found in Trash,%s Archives,%s Attributes,Insert into %s,Uploaded to this %s). They are added to the.potand translated in the seven shipped languages, in gender-neutral forms. A native speaker's review is welcome.pollora:i18n:extract,updateandcompilewrap the ones ofpollora/i18n; the console is the only place that loads them.Behaviour that changes
$wp_post_typesand$wp_taxonomies, inen_USand in a locale with no catalogue, and on the edge cases:withArgs(),configuring(), the factories, partial#[Labels]).fr_FR:Ajouter un(e) …,Tous les …). The catalogue is the existing one; its wording is gender-neutral.polloracatalogue (two attempts, a 4.7 KB.moinfr_FR).Performance
Measured on the front end of a test site, 40 requests alternated between the base and this branch: no class or file added beyond the decorator and the resolver (+2 classes, +2 files), no
Toolingclass loaded on a web request, request time within the noise of the measurement, inen_USand infr_FR.translate()calls inen_USgo from 0 to 55 (a__()is about 2 µs). Admin without a session andwp evalare unchanged; the admin with a session was not measured.Checks
95 targeted tests and PHPStan pass on a clean install resolved from Packagist (
pollora/i18n0.1.1,pollora/attributes0.1.2), where the test that guards the translated fields runs instead of being skipped. The thirty tests that fail locally inBootstrapEnvironmentTest,DatabaseConfigTestandViteManagerTestfail the same way ondevelop.Known gap, not in this PR:
Ability,BlockBinding,CapabilitySet,MetaandRoledeclare translatable fields that are consumed elsewhere.