Problem/Motivation

Themes define region names in their .info.yml files in Drupal 8.

These should be translated, but as far as I can tell, they are not being extracted by POTX.

For example, the Drupal core Bartik theme has this in bartik.info.yml:

regions:
  header: Header
  primary_menu: 'Primary menu'
  secondary_menu: 'Secondary menu'
  page_top: 'Page top'
  page_bottom: 'Page bottom'
  highlighted: Highlighted
  featured_top: 'Featured top'
  breadcrumb: Breadcrumb
  content: Content
  sidebar_first: 'Sidebar first'
  sidebar_second: 'Sidebar second'
  featured_bottom_first: 'Featured bottom first'
  featured_bottom_second: 'Featured bottom second'
  featured_bottom_third: 'Featured bottom third'
  footer_first: 'Footer first'
  footer_second: 'Footer second'
  footer_third: 'Footer third'
  footer_fourth: 'Footer fourth'
  footer_fifth: 'Footer fifth'

But if you look at various theme-related pages, such as the block region preview, you will see that only a few of these region names get translated (presumably the ones that are translated are done because they are in the POTX database from other sources). So for instance, "Primary menu", "Secondary menu", and "Sidebar first" are not in the POTX database on localize.drupal.org for the Drupal Core project (after Drupal 8.0.0-rc2 anyway -- they seem to be in there for early beta versions of Drupal). They should be.

Screenshot of what this page looks like in Catalan (from the User Guide):
Block regions preview in Catalan

Proposed resolution

Parse region name human-readable strings in POTX.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jhodgdon created an issue. See original summary.

Gábor Hojtsy’s picture

Status: Active » Needs review
FileSize
780 bytes

Good find! Theoretically the rules in yaml_translation_patterns.yml would make potx find them, but there is no test coverage. Let's see what would expanded tests say.

Status: Needs review » Needs work

The last submitted patch, 2: 3043258-test.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jhodgdon’s picture

Realized I created this issue long ago in the wrong project, so I'll be closing #2806065: Theme region names are not making it into PO database as a duplicate of this one. Doh!

jhodgdon’s picture

That looks like a good test!

jhodgdon’s picture

Hm. Regions is not like the other keys in that translation patterns file, in that it is an array.

So, looking at what happens in _potx_find_yaml_translatables() in potx.inc, for arrays in YAML... let's see. In either the test info.yml file or in the Bartik yml file, we have something like this:

regions:
  header: Header
  primary_menu: 'Primary menu'
  secondary_menu: 'Secondary menu'

So in the code, it does this, basically [my comments added and a bunch of code removed for simplicity]:

foreach ($yaml as $key => $value) {
  // See if $key is in the translatable list -- which is TRUE for 'regions'. 
    if (in_array($key, $trans_list['keys'], TRUE)) {
       // Figure out the context [code omitted]
       // Save the value as translatable if it's not an array.
      if (!is_array($value)) {
        $save_callback(addcslashes($value, "\0..\37\\\""), $context, $file_name);
      }
   }
...

And then there is a recursive call to the same function if $value is an array, but at that level, the keys are things like 'sidebar_first' and those will not match the keys in the translatable list.

In other words... What we want here is "Extract values for all the keys underneath regions". But that is not what the code does.

jhodgdon’s picture

Status: Needs work » Needs review
FileSize
3.59 KB
2.83 KB

Here's a proposed fix... It is already possible in a yaml_translation_patterns.yml file to specify

    top_level_translatables: true

at the file level, and also it is possible to specify a context for each translatable key.

So what I've done is to add the possibility of specifying something similar to top_level_translatables for each key.

Let's see what happens...

Status: Needs review » Needs work

The last submitted patch, 7: 3043258-test-plus-code-7.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jhodgdon’s picture

Status: Needs work » Needs review
FileSize
3.42 KB
1.56 KB

Invalid YAML, whoops. How about this? Should also probably fix the coding standards warning.

jhodgdon’s picture

Status: Needs review » Needs work

whoops, that's not quite right either. Need to think about the logic a bit more.

jhodgdon’s picture

Status: Needs work » Needs review
FileSize
3.56 KB
712 bytes

OK, I think this even simplifies the logic a bit. I canceled the other test.

Status: Needs review » Needs work

The last submitted patch, 11: 3043258-test-plus-code-10.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jhodgdon’s picture

Status: Needs work » Needs review
FileSize
4 KB
2.04 KB

One more fix. Should hopefully take care of the coding standards warnings in the lines touched by this patch, plus fix the test fail maybe/hopefully.

Status: Needs review » Needs work

The last submitted patch, 13: 3043258-test-plus-code-12.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jhodgdon’s picture

Status: Needs work » Needs review
FileSize
4 KB
542 bytes

Sorry for all the sloppiness. This patch might fix the last test fails hopefully...

Status: Needs review » Needs work

The last submitted patch, 15: 3043258-test-plus-code-14.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jhodgdon’s picture

Status: Needs work » Needs review
FileSize
1.98 KB
4.34 KB

OK, here's a new patch that reorganizes the logic and is hopefully clearer, plus might work this time. :)

Probably I should have installed the module and run the tests on my own machine... oh well.

jhodgdon’s picture

OK, it's green, with no coding standards violations! Time for an actual review.

Joachim Namyslo’s picture

It seems this is valid for the them region names on the block layout page, too. Maybe Gabor misunderstood my issue and therefore he marked it as a duplicate of this one.

As long as the region names are English we aren't able to make user guide screenshots. It is at least a blocking Issue for de

Joachim Namyslo’s picture

jhodgdon’s picture

Yes, the problem is that the region names for the theme, which are used on the Block Layout page as well as the Regions Preview page that you can see in the screenshot on this issue... Those region names are not being extracted by the POTX string extractor, so they are not on localize.drupal.org to be translated. Some of them are on there because they have been used in PHP code elsewhere in Drupal Core, but not all. This patch should fix the problem, so that the translation teams can translate those terms.

jhodgdon’s picture

Bump... I added a patch about 6 weeks ago. What can we do to move this forward?

Joachim Namyslo’s picture

Yep Great question just before Amsterdam. Putting it on the list for Drupal Con would be a great Idea.

Joachim Namyslo’s picture

Any Updates on this. I'd like to translate the User Manual from scratch on Global contribution Weekend 2020 in Berlin Maybe this one could be reviewd so we can work on as long the Help topics Module is in experimental state, still.

jhodgdon’s picture

I don't see why this issue would prevent you from translating the User Guide into German. It's only affecting one screenshot.

Joachim Namyslo’s picture

I thought there is a problem to extract template region names correctly. But If we can motivate people to translate the guide again in it's current version the screenshots will be the last step. So youre absolutely right. Hope we can do this untill the Help topics module is stabele.

Thank you Jennifer

jhodgdon’s picture

True, this is a problem for translating the user interface, but I think it only affects a few pages of the User Guide where blocks are being placed in regions.

Gábor Hojtsy’s picture

Title: Region names do not seem to be extracted from theme info files » Region names are not extracted from theme info files

  • Gábor Hojtsy committed 04ae620 on 7.x-3.x
    Issue #3043258 by jhodgdon, Gábor Hojtsy, Joachim Namyslo: Region names...
Gábor Hojtsy’s picture

Version: 7.x-3.x-dev » 8.x-1.x-dev
Status: Needs review » Patch (to be ported)

Thanks all. Committed to 7.x-3.x. Sorry for making this linger. Should be ported to 8.x too. Now on 7.x though @drumm can roll this out to l.d.o.

jhodgdon’s picture

Status: Patch (to be ported) » Needs review
FileSize
4.17 KB

Here's an attempt at porting the patch. The code for D7 and D8 looks pretty similar, so I basically just copy/pasted stuff from the D7 patch and put it in the equivalent spot in D8... let's see what the bot says (I'm not on my D8 dev machine so I didn't run the test) -- I included the test changes in the patch.

Gábor Hojtsy’s picture

We do try to keep potx.inc identical between major Drupal versions, so backporting and forward porting is easier. At one point we'll need to stop doing that, but so far it served us well.

jhodgdon’s picture

It was close, but not identical. The patch didn't apply, even with "fuzz". But it was easy to figure out where to copy/paste things and how to change one variable name.

jhodgdon’s picture

The tests pass on the d8 port.

  • Gábor Hojtsy committed 3becb8c on 8.x-1.x
    Issue #3043258 by jhodgdon, Gábor Hojtsy, Joachim Namyslo: Region names...
Gábor Hojtsy’s picture

Status: Needs review » Fixed

Great, pushed that too, thanks!

Status: Fixed » Closed (fixed)

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