Problem/Motivation
Knowing which strings in YAML files are supposed to be translatable or not can be a huge PITA, especially in standalone YAML that isn't tied to something unique and processed like in the config system.
Proposed resolution
Semi-related to #2088371: YAML discovery incompatible with translations, but more of a continuation to automatically convert strings to TranslatableMarkup
found in YAML files using a custom !translate
tag, e.g.:
label: !translate [ "Human readable and translatable title" ]
Remaining tasks
TBD
User interface changes
None
API changes
None
Data model changes
None
Release notes snippet
TBD
Comment | File | Size | Author |
---|---|---|---|
#9 | 3068483-9-test-only.patch | 6.05 KB | markhalliwell |
Issue fork drupal-3068483
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
markhalliwellBetter title.
---
From: #2088371-40: YAML discovery incompatible with translations
---
This could easily be accomplished by implementing a YAML callback:
https://www.php.net/manual/en/yaml.callbacks.parse.php
For Symfony, we can essentially do the same but will have to iterate over the YAML array after parsing it to look for
\Symfony\Component\Yaml\Tag\TaggedValue
objects.Comment #3
markhalliwellhttps://symfony.com/blog/new-in-symfony-3-3-custom-yaml-tags#comment-21048
Turns out it, for BC reasons, tags don't work with string literals (yet).
So instead, we'd need need to wrap it in an array.
This is actually good because then we can just pass the entire contents of the array to the method which allows context :D
Also, I'm thinking the tag name should be
!translate
as it reads better this way.Comment #4
markhalliwellInitial POC patch
Comment #6
markhalliwellComment #7
markhalliwellComment #8
markhalliwellComment #9
markhalliwellComment #10
markhalliwellComment #13
markhalliwellRandom test failure
Comment #14
markhalliwellPing
Comment #22
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #25
volegerRerolled against 10.1.x.
Comment #26
smustgrave CreditAttribution: smustgrave at Mobomo commentedDidn't test but the MR has a test failure which seems valid.