Problem/Motivation
First of all, we should finish the basic port to Drupal 8, which is handled in #2611298: Port potx to Drupal 8. There are some hooks and forms that need to be ported right now.
The patch to allow exporting translations from the database should be added in #2175955: Support language dependent content and translations export in Drush command, although there should be a note that the translations will be extracted from the drush Drupal installation, not from the destination.
And the missing languages table fix should be added to this issue. Although, the current code using db_table_exists() causes a big slowdown, and its results should be cached somewhere.
Proposed resolution
missing languages table fix
Remaining tasks
todo
User interface changes
none
API changes
none, probably
Data model changes
probably none
Original report by Xano
I am trying to extract strings from a Drupal 8 module. As there is no Drupal 8 version of POTX, I cannot use it from within my development site. Fortunately there is Drush support, but potx.drush.inc contains include_once drupal_get_path('module', 'potx') . '/potx.inc';, which won't work when you're not within a Drupal installation. Why I can even execute the command, I don't know, but this looks like there is no solution for Drupal 8 yet, or is there?
Comments
Comment #1
gábor hojtsyYeah it may be made to work without that with some static hackery based on file locations I guess. That may solve this for you. We *need* to maintain the 6.x branch for localize.drupal.org so it may be too painful to port the module already to D8 too and maintain 3 branches in parallel.
Comment #2
gábor hojtsyBTW the code parsing can parse D8 code fine as is happening on localize.drupal.org already :)
Comment #3
xanoIf I understand correctly, that means 7.x-3.x in its current state is useless for Drupal 8 and we should use 6.x-3.x (which still has
potx-cli.php) for the time being?Can't the actual extraction code be moved to a separate project that is independent of any Drupal installation? That way people can use CLI without a Drupal installation and use any available version of the module to do similar things from within a Drupal site's administration interface.
Comment #4
gábor hojtsyYeah theoretically potx.inc and the drush stuff may be movable out to its own project that is versioned differently. We are busy with upgrading localize.drupal.org to D7 ATM and trying to avoid *nice to have" changes to cause less disruption in the process. Also potx.inc is a very ugly pile of procedural functions and @sebcorbin was/is working on making them more modern step by step. But once again after the l.d.o update happens :) That has been dragging on for years.
Comment #5
gábor hojtsyhttps://www.drupal.org/project/issues/search?issue_tags=Localize%20D7%20...
Comment #6
xanoThanks for the detailed explanation! If you decide on OOP-ifying this and maybe converting the extraction components into something like a Symfony/Console app, let me know.
Comment #7
xanoSo 6.x-3.x no longer has
potx-cli.phpeither? How does one scan Drupal 8 modules for translatable strings then?Comment #8
gábor hojtsyOne needs to fix the code underlying the drush command then :)
Comment #9
gábor hojtsyDid #2357369: Don't use drupal_get_path() for loading server-side code from within POTX fix it then? :) With that there should be no need for an active Drupal install (or dependency on any Drupal version) for extraction anymore no?
Comment #10
penyaskito#2475163: Load default patterns from potx folder and #2371765: Fatal error on Twig_Lexer using drush potx when used from 8.x codebase are also needed. With those everything worked for me. And with https://github.com/cocomore/drush_language I can import them via drush :))
Comment #11
Anonymous (not verified) commentedSo what's the new approach for extracting translation via CLI in D8?
Comment #12
sutharsan commentedTo extract translatable string from Drupal 8 you:
drush potx single --api=8 --folder=/path/to/drupal8/rootComment #13
gábor hojtsy#2371765: Fatal error on Twig_Lexer using drush potx when used from 8.x codebase landed. We should ideally port the module to D8 too sooner or later. At least using the code in a D8 Drush environment may work given the version agnostic approach of potx itself and drush. Feedback / reports of success / failure welcome :)
Comment #14
Anonymous (not verified) commentedIs there a github repo with D8 code that I can try or do I have to follow the #12 and use D7 version?
Comment #15
gábor hojtsyIf there would be a D8 version it would be on drupal.org.
Comment #16
penyaskitoI used this not long ago, here are my notes in case they are helpful:
Comment #17
Anonymous (not verified) commented#16 works just fine! Although It will also include sub-modules which I don't want but better than nothing.
Comment #18
Anonymous (not verified) commentedMaybe last time I did something differently but now I am getting error message about the module having to be installed. D8 RC2.
---
Ok so I have commented out the install file content and transformed the info file into yml and installed the module and I can use the drush potx command now.
Comment #19
gábor hojtsySee also #2611298: Port potx to Drupal 8.
Comment #20
Anonymous (not verified) commentedI have just noticed that strings from config files were not detected, so only config/schema /*.yml is picked up but not config/install/*.yml or config/optional/*.yml
Comment #21
mpp commentedCombined #16 & #18:
Output will be stored in the Drupal root.
Comment #22
kgaut commented#21
Do you download the module globaly (within ~/.drush) or localy (on the website) ?
Comment #23
jlbellidoHi! Thanks for the previous comments on this issue. I was following the comments set in #16 and #18 (merged in #21) But I'm getting the following error :
PHP Fatal error: Call to undefined function drupal_get_path()
From the drupal root I'm running :
drush potx --include=./modules/contrib/potx/ --modules=my_module --api=8
Am I doing something wrong? Because drupal_get_path() is still in core.
Thanks!
Comment #24
kgaut commentedI did a quick'n'dirty port of the module in order to make it works out of the box with drush on drupal 8 :
composer require kgaut/potx)drush en potxdrush @ALIAS potx single --include=modules/contrib/potx/ --modules=MYMODULE_MACHINE_NAME --api=8Thanks to #16 #18 and #21.
https://github.com/kgaut/drupal-potx
Comment #25
gngn commentedFollowing what Kgaut wrote in #24:
modules/contrib/potx/drush en potx--include(and without ALIAS):drush potx single --modules=MYMODULE_MACHINE_NAME --api=8(with --include I got the "undefined function drupal_get_path()" error)
I managed to generate a
general.pot.If I remember correctly older potx-Versions where able to generate
*.pofiles, which included the existing translations (pot is the template file).How can I get the .po nowadays?
Comment #26
kgaut commented@gngn : by renaming the *.pot file to *.po, I was able to translate it and import it back.
Even-if it's not the proper way, it works.
Comment #27
gngn commented@Kgaut: thanx - but this way I do not get the already existing translations...
Comment #28
AgaPe commentedYes, any possiblity to extract existing translations?
Comment #29
damienmckennaLets standardized the efforts here.
Comment #30
damienmckennaDo the current maintainers have any plans to port the module, or might they be willing to let someone help?
Comment #31
herom commentedHelp would be really appreciated. Although, a backlog of issues have been built up that I need to look into first. So, it will probably take around one or two months before I can come up with a plan for porting to Drupal 8.
Comment #32
rodrigoaguileraI did a even-more-dirty modification to be able to include the translations from the database
https://github.com/kgaut/drupal-potx/pull/2
so now you can do
drush potx single --modules=MYMODULE_MACHINE_NAME --api=8 --language=esAnd the translations will be included. This is very valuable for our workflow.
Comment #33
kgaut commentedThanks rodrigoaguilera ! I've just merged it and updated the readme :
https://github.com/kgaut/drupal-potx
Comment #34
fgmFWIW, this crashes for me because it tries to access a nonexistent
languagestable. This is on a single language, non-english 8.x-3.x-beta1 site.The mechanism in #16 using an underlying D7 site works fine, however.
Comment #35
fmfpereira commented#33 works for me (8.2.6).
Comment #36
fgm@fmfpereira: are you on a single-language non-english site ?
Comment #37
fmfpereira commented@fgm: yes. I have portuguese as default language and english.
Comment #38
fgmSo that's probably why it works: I guess the languages table is not installed on single-language sites.
Comment #39
basvredelingI run into the same issue as #34 on 8.2.7: no languages table.
Comment #40
rodrigoaguileraI read a bit the code and I think it only uses the language table to get the number of plurals.
We can easily change that line for a call to
https://api.drupal.org/api/drupal/core%21modules%21locale%21src%21Plural...
The line is
https://github.com/kgaut/drupal-potx/blob/8.x-1.x/potx.inc#L614
Can someone confirm that is the conflicting line?
Comment #41
penyaskitoI'm updating the issue title as it's totally differently focused now.
For the port itself, per #19 we could use #2611298: Port potx to Drupal 8.
@herom, I'm quite interested on moving this forward, so if I can help let me know what's needed for shaping up the plan.
Comment #42
penyaskitoCreated https://github.com/kgaut/drupal-potx/pull/5 for the problem with monolingual English sites reported in #34 and confirmed in #39.
Comment #43
kgaut commented#42 is merged in https://github.com/kgaut/drupal-potx
Thanks
Comment #44
herom commented@penyaskito, Here is the plan right now:
First of all, we should finish the basic port to Drupal 8, which is handled in #2611298: Port potx to Drupal 8. There are some hooks and forms that need to be ported right now.
The patch to allow exporting translations from the database should be added in #2175955: Support language dependent content and translations export in Drush command, although there should be a note that the translations will be extracted from the drush Drupal installation, not from the destination.
And the missing languages table fix should be added to this issue. Although, the current code using
db_table_exists()causes a big slowdown, and its results should be cached somewhere.Comment #45
john.lee.doe commentedhow to use this command in drupal 8.6.x.
it report an error. potx is not defined.
Comment #46
john.lee.doe commentedfixed it.
Drupal 8.6.x potx not work?
1. 使用这个模块替换原有7.x版的模块代码—
git@github.com:kgaut/drupal-potx.git2. drush en -y potx
3. 使用该命令进行翻译文件导出。
./vendor/bin/drush potx single --include=modules/contrib/potx/ --folder=modules/mymodules/ --api=8Comment #47
mikran commentedI've updated issue summary with the actual problem reported in comment
#20.Comment #48
mikran commentedThe reason for missing translatables from config/install is that extracting these pots requires their schemas to be present.
so issue summary updated again to comment #44.
what is missing languages table?
Comment #49
mikran commentedoh that close was a mistake