Implementing a solution for #2088371: YAML discovery incompatible with translations, #2296219: Create schema for non-config YAML files? in potx.

The proposed solution now is to specify only the translatable keys (ignoring the yaml structure) in a specific file (yaml_translation_patterns.yml?), and allow contrib modules to extend this by defining a similar file in their root folder.

This is the current proposed format, including all supported yaml types in core:

*.info.yml:
  - name
  - description
  - package
  - regions
*.routing.yml:
  - _title:
      context: _title_context
*.links.task.yml:
  - title:
      context: title_context
*.links.action.yml:
  - title:
      context: title_context
*.links.contextual.yml:
  - title:
      context: title_context
*.links.menu.yml:
  - title:
      context: title_context
  - description
*.breakpoints.yml:
  - label
  - group
*.permissions.yml:
  - title
  - description
  - %top-level-key
config/schema/*.yml:
  - label
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Status: Needs review » Needs work

The last submitted patch, potx-yaml-translation.patch, failed testing.

herom’s picture

Status: Needs work » Needs review
FileSize
7.87 KB

oops. missed that new file.

Gábor Hojtsy’s picture

This looks good as a first step, it does not yet support integration with contrib solutions though. What do you think how would we do the reading of those files? It sounds like it would be similar to how you read all the schema files first and then the parsing of the config files. Here the "schema" files are the YAML pattern files (not happy for the name but have no better idea :D).

  • Gábor Hojtsy committed 220a61e on 6.x-3.x
    Issue #2322839 by herom: Unify YAML translation extraction.
    
Gábor Hojtsy’s picture

Status: Needs review » Active
Issue tags: +Needs tests

The patch itself looks amazing, so committed this patch for now. What we need though is a translatables yaml file in the D8 module and some of our own defined YAML file eg. potx_test_8.potx_test_strings.yml or something from where to test the extraction, so we test the discovery of the translatables definition and that it works.

herom’s picture

Status: Active » Needs review
Issue tags: -Needs tests
FileSize
3.92 KB

Here comes contrib support, tests, and a bit of docs.

Status: Needs review » Needs work

The last submitted patch, 6: potx-yaml-translation-followup-2322839-6.patch, failed testing.

Gábor Hojtsy’s picture

  1. +++ b/potx.inc
    @@ -1855,10 +1855,50 @@ function _potx_find_translation_annotations($file, $save_callback) {
    + *     # a sequence of translatable keys in the matched YAML files.
    ...
    + *         # an optional key, used as context for the translatable string.
    

    Start with uppercase.

  2. +++ b/potx.inc
    @@ -1855,10 +1855,50 @@ function _potx_find_translation_annotations($file, $save_callback) {
    + * @endcode
    + * @param string $path
    

    Add newline between endcode and param.

  3. +++ b/tests/potx.test
    @@ -338,6 +338,16 @@ class PotxTestCase extends DrupalWebTestCase {
    +    $this->parseFile(drupal_get_path('module', 'potx') . '/tests/potx_test_8/potx_test_8.test.yml', POTX_API_8);
    

    Test file was not in the patch :)

herom’s picture

Status: Needs work » Needs review
FileSize
1.45 KB
4.64 KB

silly me :)

Gábor Hojtsy’s picture

Status: Needs review » Fixed

Yay, thanks, that looks great. Fixed the whitespace errors in potx_test_8.test.yml on commit.

  • Gábor Hojtsy committed 6bd1e2b on 6.x-3.x
    Issue #2322839 by herom: Unify YAML translation extraction, and allow...
Gábor Hojtsy’s picture

Version: 6.x-3.x-dev » 7.x-2.x-dev
Status: Fixed » Patch (to be ported)

  • Gábor Hojtsy committed 220a61e on 7.x-2.x
    Issue #2322839 by herom: Unify YAML translation extraction.
    
  • Gábor Hojtsy committed 6bd1e2b on 7.x-2.x
    Issue #2322839 by herom: Unify YAML translation extraction, and allow...

  • Gábor Hojtsy committed 220a61e on 7.x-3.x
    Issue #2322839 by herom: Unify YAML translation extraction.
    
  • Gábor Hojtsy committed 6bd1e2b on 7.x-3.x
    Issue #2322839 by herom: Unify YAML translation extraction, and allow...
SebCorbin’s picture

Version: 7.x-2.x-dev » 7.x-3.x-dev
Status: Patch (to be ported) » Closed (fixed)

Ported to 7.x-3.x as it has been branched directly from 6.x-3.x

Xano’s picture

The documentation is a little unclear to me. Say I have the following *.payment.status.yml YAML structure, how would I make the label and description items translatable?

payment_authorization_failed:
  label: Authorization failed
  parent_id: payment_failed
payment_authorized:
  description: The payment has been authorized by the payer, and the funds are waiting to be transferred.
  label: Authorized
  parent_id: payment_no_money_transferred

I tried this, but despite the fact that POTX scanned the YAML files, the strings did not end up in the pot file:

*.payment.status.yml:
  - label
  - description
Gábor Hojtsy’s picture

Are you sure potx considers your declaration of translatable things? I suspect that may be the problem.

Xano’s picture