feat(i18n): make the visitor form translatable, and stop the template rotting - #39
Merged
Merged
Conversation
… rotting Every form label, help string, section heading and form title was emitted as a raw PHP literal, so none of them reached gettext. They were absent from the POT and from translate.wordpress.org, which meant no language pack could translate them however complete it was: a site in Spanish rendered an English birth details form above a correctly translated Spanish reading. The generator now wraps visitor-facing strings in __(). TRANSLATABLE_SPEC_KEYS is a single list feeding BOTH form emitters, because the long tail and the heroes build their spec arrays in separate functions and a one sided fix would half apply. name, type and enum stay untranslated on purpose: enum values are posted verbatim to the API, so translating one would send a translated value. POT msgids go 617 to 861. The template is now regenerated on every release rather than hand maintained, and npm run i18n:pot refreshes it locally. test-form-strings-translatable.php scans the emitted source rather than calling spec(), because at runtime __() has already returned a plain string and a translated build is indistinguishable from an untranslated one. Verified to fail on the previous shape before being relied on.
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.
Every form label, help string, section heading and form title was emitted as a raw PHP literal, so none of them reached gettext. They were absent from the POT and from translate.wordpress.org, which meant no language pack could translate them however complete it was. A site set to Spanish rendered an English birth-details form above a correctly translated Spanish reading.
What changed
bin/generate.mjswraps visitor-facing strings in__().TRANSLATABLE_SPEC_KEYSis one list feeding both form emitters — the long tail and the heroes build their spec arrays in separate functions, so a one-sided fix would half-apply.name,typeandenumstay untranslated deliberately. Enum values are posted verbatim to the API andFormRendererderives their display text withucwords(), so translating one would send a translated value.npm run i18n:potrefreshes it locally.Verification
Birth date,Latitude,Birth details,Western birth chartwp i18n make-pottest-form-strings-translatable.phpscans the emitted source rather than callingspec(): at runtime__()has already returned a plain string, so a translated build is indistinguishable from an untranslated one. It was verified to fail on the previous shape before being relied on.Verification note
phpcs, phpstan level 8, prettier, lint:js, lint:css,
generate:check,check-distignore,build:allandcheck:blockspass locally. phpunit and plugin-check need wp-env, which cannot start in that environment, so CI is the gate for those two.