Once #2920309: Add experimental module for Help Topics gets committed, and as part of making the module stable on #3027054: Help Topics module roadmap: the path to beta and stable, we need to look into internationalization:

a) Make sure topic Twig files are being scanned by POTX so the topic text gets onto localize.drupal.org.
[This is not a problem. They have the regular .html.twig extension, so POTX will find/parse them, and the text in trans tags will be extracted.]

b) Make sure that the topic title/label gets into localize.drupal.org as a translatable string (it's in a meta tag in the Twig file)
[This will not happen unless we patch POTX.]

Comments

jhodgdon created an issue. See original summary.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

jhodgdon’s picture

Title: Make sure help topics are fully internationalized » Extract template title meta-data from help topic Twig files
Project: Drupal core » Translation template extractor
Version: 8.8.x-dev » 7.x-3.x-dev
Component: help.module » Code
Issue summary: View changes

I just realized the issue summary has a link to POTX code around YAML files, and we're not using YAML, so we don't need to worry about that. The Twig files will be found and parsed. So, really the only question is about the discovery of the meta tags.

Currently our Twig files look like this:

<meta name="help_topic:label" content="Writing good help"/>
<meta name="help_topic:top_level"/>
<p>{% trans %}Here are some suggestions for how to make your help topics as useful as possible for readers:{% endtrans %}</p>
...

So once one of these Twig files is found, anything in the trans tags will be translated.

The problem is that the help topic title also needs to be translated, which is in that meta tag. So we will need to patch POTX so that this is parsed.

Twig file parsing is done in _potx_parse_twig_file(), which is here:
https://git.drupalcode.org/project/potx/blob/HEAD/potx.inc#L1766
I'm going to move this issue over to the POTX project so that we can modify that function and make sure the meta tag for the help topic label is also parsed as translatable.

jhodgdon’s picture

Assigned: Unassigned » jhodgdon
jhodgdon’s picture

Status: Active » Needs review
StatusFileSize
new828 bytes

Here is the test that we need to have pass, in order to resolve this issue. No code change yet, so I expect the test to fail.

Status: Needs review » Needs work

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

jhodgdon’s picture

Status: Needs work » Needs review
StatusFileSize
new1.63 KB

Good, that failed as expected. Here's a patch for the code... I added two more lines for testing.

jhodgdon’s picture

The patch test failed with a CI error, in this line of the test running script:

++ docker pull drupalci/php-5.6-apache:production
14:01:30 production: Pulling from drupalci/php-5.6-apache

It seems to have timed out. I added a new test. I don't think the fail is at all related to the patch.

jhodgdon’s picture

OK, the tests passed this time. It's a pretty small change. Thoughts?

herom’s picture

The patch looks good, Thanks! Committed.

8.x-1.x patch incoming ...

  • herom committed b718bea on 7.x-3.x authored by jhodgdon
    Issue #3037229 by jhodgdon: Extract template title meta-data from help...
herom’s picture

Version: 7.x-3.x-dev » 8.x-1.x-dev
StatusFileSize
new1.08 KB
new1.75 KB

Running a quick test...

The last submitted patch, 12: 3037229-drupal8-test-only.patch, failed testing. View results

  • herom committed 6e9bd50 on 8.x-1.x authored by jhodgdon
    Issue #3037229 by jhodgdon: Extract template title meta-data from help...
herom’s picture

Status: Needs review » Fixed

Committed to 8.x-1.x too. Fixed!

ricovandevin’s picture

The code added triggers an error in our project when extracting translations from a custom theme:

Warning: get_meta_tags(templates/our-template-name.html.twig): failed to open stream: No such file or directory in /var/www/html/web/modules/contrib/potx/potx.inc on line 1952

ricovandevin’s picture

Status: Fixed » Needs review

Not sure it is properly fixed.

herom’s picture

StatusFileSize
new4.01 KB

@ricovandevin, Can you try this patch? It fixes an issue when extracting the strings from the UI.
Let me know if it didn't fix your error, or if you were using drush when you encountered the error.

jhodgdon’s picture

Assigned: jhodgdon » Unassigned

Unassigning for the UI followup.

gábor hojtsy’s picture

Status: Needs review » Needs work
+++ b/potx.inc
@@ -1947,26 +1947,28 @@ function _potx_parse_js_string($string) {
+  if ($file_path !== NULL) {

This NULL not NULL distincition seems like magic. Should we condition on being in a specific directory instead, that would be a lot more self documenting.

herom’s picture

Status: Needs work » Needs review
StatusFileSize
new831 bytes
new4.49 KB

The NULL check is not for distinction between Drush or UI modes. It is for distinction between a twig file or an inline twig template.

The "get_meta_tags()" function requires a real file, and we cannot use it for inline twig templates. Unless parsing tags in inline twig templates is a real usecase. In that case, I could replace the "get_meta_tags()" call with some sort of regex.

But, for now, I have added descriptions for the function parameters. Let me know if the code is clearer now.

jhodgdon’s picture

The format for meta-data for Twig help topics has changed, so I created #3086657: Parse new front-matter format for help topic titles

This issue is still open for some UI issue I think? Should that be spun off to a separate issue?

andypost’s picture

Status: Needs review » Needs work

It still needs work for new format, and "front mater" is not available in core for all templates.
But at least current metadata needs to be translatable

jhodgdon’s picture

Status: Needs work » Needs review

The patch for the original format was already committed, and then this issue got sidetracked for an unrelated UI issue that should probably be on its own issue but isn't.

The issue to use the new format is shown in #22 #3086657: Parse new front-matter format for help topic titles, which lists this one as related, and is currently postponed until we get the Front Matter component into Core.

andypost’s picture

The last commit is not looking for front matter so no way to extract topics (titles at least)

Before 9.0 would be great to allow translation

jhodgdon’s picture

Right, but not on this issue. We should move over to #3086657: Parse new front-matter format for help topic titles. This one got derailed on some UI issue.

jhodgdon’s picture

I propose that you back out the commits that were made on this issue, and which caused problems, unless someone else needs this type of format for text.

We have a separate issue for the new front matter format for help topics, on
#3086657: Parse new front-matter format for help topic titles
which is waiting for the front matter component to be added to Drupal core.

andypost’s picture

Status: Needs review » Needs work

Proper status, as front matter is not commited

jhodgdon’s picture

Title: Extract template title meta-data from help topic Twig files » [Revert??] Extract title from meta tag in Twig files

Again, this is not the front matter issue. The front matter issue for POTX is
#3086657: Parse new front-matter format for help topic titles

I'm going to go take this issue out of the Roadmap for Help Topics, because it is no longer relevant. Also changing title.

jhodgdon’s picture

Also I am orphaning this issue. No longer related to help topics.

andypost’s picture

I think better not revert but just fix for current state as the last fix was valid at the time of commit

jhodgdon’s picture

I don't think anyone is using this code for getting meta tags as translatable from Twig templates.

Extracting data from front matter is a separate issue:
#3086657: Parse new front-matter format for help topic titles
which is currently postponed until Front Matter is committed to core as part of Twig.

andypost’s picture

Probably we should go ahead and merge this instead of related #3086657: Parse new front-matter format for help topic titles

andypost’s picture

Title: [Revert??] Extract title from meta tag in Twig files » Extract title from meta tag in Twig files
Status: Needs work » Needs review
StatusFileSize
new2.37 KB

While commit of front matter stuck, here's updated patch (new regexp) from related issue

andypost’s picture

Title: Extract title from meta tag in Twig files » Extract help topics label from meta tag in Twig files

proper title

andypost’s picture

StatusFileSize
new2.35 KB

8.x patch

Status: Needs review » Needs work

The last submitted patch, 36: 3037229-36-8.x.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new553 bytes
new2.37 KB

fix matches

andypost’s picture

StatusFileSize
new2.35 KB

Patch for 8.x

jhodgdon’s picture

This looks very straightforward and the tests pass.

There is a coding standards message on the test results page that should be fixed.

I still think this patch should be put on #3086657: Parse new front-matter format for help topic titles instead, but we can leave that up to the POTX maintainers I guess.

andypost’s picture

StatusFileSize
new433 bytes

Fix CS, 4 other issues are preexisting

andypost’s picture

StatusFileSize
new2.35 KB
new2.37 KB

Same for 7.x
PS: I find it strange... for some reason linter shows all CS issues in the module comparing to 8.x one

jhodgdon’s picture

The coding standards linter runs on any file that is patched, and shows all messages in that file. It is not aware of which lines are new and which are old. It does tell you that the file has N more coding standards messages than the previous version.

I took a more careful look at the code. One comment seems wrong:

+        if (in_array($key, $keys_to_save, TRUE)) {
+          // Only label defined translatable.

Since $keys_to_save is defined above, I think we should leave that comment out. If someone decides we need to translate additional front matter later on, they would change the array up above and not fix this comment that is not with that array.

Other than removing that one line, I think this is good.

andypost’s picture

StatusFileSize
new512 bytes
new2.31 KB
new2.33 KB

Removed useless comment

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

I took a careful look at the 7.x and 8.x patches, and I think they are both ready to go. With tests!

gábor hojtsy’s picture

Status: Reviewed & tested by the community » Fixed

@jhodgdon wrote several times above in #24, #26, #27, #29, #32 and #40 that this patch should go into #3086657: Parse new front-matter format for help topic titles where it is at for one and there are also other contributors there who would not be credited if I would commit from here. Plus there was already a previous format support committed here. Reusing issues to commit different things is not a good idea.

Yes, the usage of get_meta_tags() will be removed in #3086657: Parse new front-matter format for help topic titles and that should resolve the problem @ricovandevin seen on their use. But that does not mean that we should reuse this issue for other things than parsing the meta tags which it already fulfillled. I'll credit @ricovandevin and @herom there for their discussion here, so that credit is not lost. See you there!

Status: Fixed » Closed (fixed)

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