Skip to content

Add a translate field option to leave fields out of the WPML configuration - #180

Merged
dnnsjsk merged 1 commit into
inline0:mainfrom
Contributolo:feat/wpml-translate-field
Oct 26, 2026
Merged

dnnsjsk merged 1 commit into
inline0:mainfrom
Contributolo:feat/wpml-translate-field

Conversation

@Contributolo

Copy link
Copy Markdown
Collaborator

wp bs wpml config classifies each field by its type, so every text, textarea, richtext, and wysiwyg field is declared as translatable. The WPML page says so: "Every text field is declared, including one that holds a technical value such as a CSS class." Some text fields hold values that must be the same in every language. In our theme, three blocks take the handle of a connected social account in a text field, and a contact list stores email addresses. WPML offers both for translation, and a translated handle makes the block look up an account that does not exist.

This adds a field option translate. "translate": false leaves the field out of the configuration, so WPML copies the value into the translation unchanged, the same way it treats hidden fields and value types. On a group, tabs, or repeater, it applies to every field inside. true is the default and changes nothing: the field type decides, as before. Custom field types still get the warning; whether their value holds text is something the type registration would have to say, which is out of scope here.

  • Wpml_Config::kind() treats "translate": false like hidden. Groups and tabs are flattened and add no definition of their own, so a small pass in section() copies the setting down to every field below a container that sets it. Field_Definitions is unchanged.
  • A storage key where the block field and an extension field disagree (one with "translate": false) is reported as a conflict and not declared, like any other disagreement. The message names it: note (text in the block, untranslated text in an extension).
  • On a files field, false also leaves out the attachment IDs, so the translation keeps the original attachments. The docs say so.
  • Schema: the option sits next to hidden in block.json and extend.json (three places each), with new checksums in manifest.json. src/types/block.ts is edited by hand in the generated order, because npm run types stops with s.codePointAt is not a function (on main as well). Docs: the general properties table in field types and a section "Leave a field out" on the WPML page; blockstudio-llm-full.txt rebuilt.
  • Editor: Fields spreads the field options onto the control. translate would reach the input as the HTML translate attribute, so it is removed next to type and id.

Tests: two tests in WpmlConfigTest (containers, nested groups in repeater rows, link and files fields, and the conflict), and WpmlConfigTranslateTest, which registers a block and an extension through Build::init() and checks the generated entry. All three fail on main and pass with the change. The rest of tests/unit/wpml gives the same results with and without the change, run in a local WordPress without Docker (one test needs the E2E test theme and fails there on main too). phpcs, PHPStan on wpml-config.php, and npm run check pass. I did not run the E2E suite; the only editor change is the removed prop.

@dnnsjsk

dnnsjsk commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Released in Blockstudio 7.7.9. Thanks for the contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants