Closed (fixed)
Project:
Translation template extractor
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
4 Mar 2019 at 00:49 UTC
Updated:
8 Sep 2020 at 18:29 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #3
jhodgdonI 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:
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.
Comment #4
jhodgdonComment #5
jhodgdonHere 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.
Comment #7
jhodgdonGood, that failed as expected. Here's a patch for the code... I added two more lines for testing.
Comment #8
jhodgdonThe patch test failed with a CI error, in this line of the test running script:
It seems to have timed out. I added a new test. I don't think the fail is at all related to the patch.
Comment #9
jhodgdonOK, the tests passed this time. It's a pretty small change. Thoughts?
Comment #10
herom commentedThe patch looks good, Thanks! Committed.
8.x-1.x patch incoming ...
Comment #12
herom commentedRunning a quick test...
Comment #15
herom commentedCommitted to 8.x-1.x too. Fixed!
Comment #16
ricovandevin commentedThe 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 1952Comment #17
ricovandevin commentedNot sure it is properly fixed.
Comment #18
herom commented@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.
Comment #19
jhodgdonUnassigning for the UI followup.
Comment #20
gábor hojtsyThis 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.
Comment #21
herom commentedThe 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.
Comment #22
jhodgdonThe 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?
Comment #23
andypostIt 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
Comment #24
jhodgdonThe 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.
Comment #25
andypostThe 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
Comment #26
jhodgdonRight, 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.
Comment #27
jhodgdonI 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.
Comment #28
andypostProper status, as front matter is not commited
Comment #29
jhodgdonAgain, 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.
Comment #30
jhodgdonAlso I am orphaning this issue. No longer related to help topics.
Comment #31
andypostI think better not revert but just fix for current state as the last fix was valid at the time of commit
Comment #32
jhodgdonI 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.
Comment #33
andypostProbably we should go ahead and merge this instead of related #3086657: Parse new front-matter format for help topic titles
Comment #34
andypostWhile commit of front matter stuck, here's updated patch (new regexp) from related issue
Comment #35
andypostproper title
Comment #36
andypost8.x patch
Comment #38
andypostfix matches
Comment #39
andypostPatch for 8.x
Comment #40
jhodgdonThis 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.
Comment #41
andypostFix CS, 4 other issues are preexisting
Comment #42
andypostSame for 7.x
PS: I find it strange... for some reason linter shows all CS issues in the module comparing to 8.x one
Comment #43
jhodgdonThe 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:
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.
Comment #44
andypostRemoved useless comment
Comment #45
jhodgdonI took a careful look at the 7.x and 8.x patches, and I think they are both ready to go. With tests!
Comment #46
gábor hojtsy@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!