There have been a few issues with the current format for Yaml translation patterns since it was proposed and committed. So, I have decided to propose a more sensible format for defining these patterns.
There are two main issues with the current format:
- Using special symbols for Yaml (e.g.
*and%) in the format. Potx is currently only using Yaml's Lexer, so it doesn't cause an issue now. But Potx will eventually be ported to drupal 8, and Yaml's Parser will trip over these symbols. This had already caused an issue when mixing Potx with drush 8.x in #2371771: Default translation pattern keys considered as references by the Yaml parser. - There is no point of extension in the current format. This forced a hack to define a special value (
'%top-level-key') to fix #2311935: Add support for .permissions.yml files, and is going to cause issue for defining a way to import/inherit translation patterns between modules.
Here is a sample of the new format, based on the core translatable Yaml files:
translation_patterns:
- matches: '*.info.yml'
translatable_keys:
- name
- description
- package
- regions
- matches: '*.routing.yml'
translatable_keys:
- key: _title
context: _title_context
- matches: '*.links.*.yml'
translatable_keys:
- key: title
context: title_context
- matches: '*.links.menu.yml'
translatable_keys:
- description
- matches: '*.breakpoints.yml'
translatable_keys:
- label
- group
- matches: '*.permissions.yml'
top_level_translatables: true
translatable_keys:
- title
- description
- matches: 'config/schema/*.yml'
translatable_keys:
- label
inherits:
- module_x
- module_y
The format is more verbose now. The list of patterns have been moved into the "translation_patterns:" key, which allows extending the format at top-level, like the current "inherits:" key. The list of translatable keys has also moved into "translatable_keys:", which adds another point of extension, that allowed replacing the mentioned '%top-level-keys' hack with a more appropriate fix, using the 'top_level_translatables' key in the proposed format.
The amount of verbosity, and the namings can be discussed here, but I think this format is a lot easier to maintain and extend in the long run.
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | interdiff-2484061-0-6.txt | 504 bytes | herom |
| #6 | use_a_more_sensible-2484061-6.patch | 5.42 KB | herom |
Comments
Comment #1
herom commentedComment #3
gábor hojtsyWhat would the inherits key do? If you depend on the core patterns, you would need to define you inherit from core? The project dependencies should already have that information and we need that for parsing contrib config files already, no?
Comment #4
herom commentedCore patterns and project dependencies should be automatically inherited. But, quoting @Xano from #2357365:
Comment #5
gábor hojtsyErm, shipped config will break also the same way. Its true that you can now do optional shipped config with dependencies that are not requirements of the module. Hm. This may indeed be somewhat of an equivalent of that I guess for plugin YAML.
Comment #6
herom commentedForgot to convert the test yaml_translation_patterns.yml
Comment #7
herom commentedJust a note that the "inherits:" part of the format can be discussed here, but it will be implemented in another issue, since it's a complex thing to handle.
Comment #8
gábor hojtsyLooks good. Good improvements IMHO.
Comment #10
herom commentedThanks @Gábor.
Also published a change record: Yaml translation patterns fomat is modified..
Comment #11
herom commentedCommitted to both 6.x-3.x and 7.x-3.x branches, and Fixed.
Comment #14
bojanz commentedSo this format doesn't support nested keys?
For example, a list of "developers" each with a translatable name.
EDIT: Actually, _potx_find_yaml_translatables() is recursive, so it should find a translatable key with the given name on any level. Could use some more documentation.