Repository navigation
Add a translate field option to leave fields out of the WPML configuration - #180
Merged
Merged
Conversation
Contributor
|
Released in Blockstudio 7.7.9. Thanks for the contribution. |
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.
wp bs wpml configclassifies each field by its type, so everytext,textarea,richtext, andwysiwygfield 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": falseleaves 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 agroup,tabs, orrepeater, it applies to every field inside.trueis 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": falselikehidden. Groups and tabs are flattened and add no definition of their own, so a small pass insection()copies the setting down to every field below a container that sets it.Field_Definitionsis unchanged."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).filesfield,falsealso leaves out the attachment IDs, so the translation keeps the original attachments. The docs say so.hiddeninblock.jsonandextend.json(three places each), with new checksums inmanifest.json.src/types/block.tsis edited by hand in the generated order, becausenpm run typesstops withs.codePointAt is not a function(onmainas well). Docs: the general properties table in field types and a section "Leave a field out" on the WPML page;blockstudio-llm-full.txtrebuilt.Fieldsspreads the field options onto the control.translatewould reach the input as the HTMLtranslateattribute, so it is removed next totypeandid.Tests: two tests in
WpmlConfigTest(containers, nested groups in repeater rows, link and files fields, and the conflict), andWpmlConfigTranslateTest, which registers a block and an extension throughBuild::init()and checks the generated entry. All three fail onmainand pass with the change. The rest oftests/unit/wpmlgives 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 onmaintoo).phpcs, PHPStan onwpml-config.php, andnpm run checkpass. I did not run the E2E suite; the only editor change is the removed prop.