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:

  1. 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.
  2. 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.

Comments

herom’s picture

Issue summary: View changes
Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, update-yaml-translation-patterns-0.patch, failed testing.

gábor hojtsy’s picture

What 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?

herom’s picture

Core patterns and project dependencies should be automatically inherited. But, quoting @Xano from #2357365:

That will break as soon as I integrate my module with another one that is not a dependency, which is a fairly common pattern in contrib.

gábor hojtsy’s picture

Erm, 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.

herom’s picture

Status: Needs work » Needs review
StatusFileSize
new5.42 KB
new504 bytes

Forgot to convert the test yaml_translation_patterns.yml

herom’s picture

Just 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.

gábor hojtsy’s picture

Status: Needs review » Reviewed & tested by the community

Looks good. Good improvements IMHO.

  • herom committed 53d6246 on 7.x-3.x
    Issue #2484061 by herom: Use a more sensible format for Yaml translation...
herom’s picture

Thanks @Gábor.
Also published a change record: Yaml translation patterns fomat is modified..

herom’s picture

Status: Reviewed & tested by the community » Fixed

Committed to both 6.x-3.x and 7.x-3.x branches, and Fixed.

  • herom committed 64eafba on 6.x-3.x
    Issue #2484061 by herom: Use a more sensible format for Yaml translation...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

bojanz’s picture

So 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.