Closed (fixed)
Project:
Translation template extractor
Version:
7.x-3.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
12 Jun 2014 at 13:39 UTC
Updated:
27 Sep 2014 at 23:03 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
gábor hojtsyBTW found in #2228763: Create a comment-type config entity and use that as comment bundles, require selection in field settings form, not sure where was it introduced.
Comment #2
gábor hojtsyTracked down #1289536: Switch Watchdog to a PSR-3 logging framework as the source of the logger stuff. Left this comment there.
Comment #3
gábor hojtsyRetitle to be a better explanation.
Comment #4
tstoecklerSo to my knowledge the reason why we didn't/couldn't use
t()inwatchdog()in Drupal 7 was that we wanted to be able to usewatchdog()in situations where the translation system has not been set up yet.With the removal of
st()andget_t()- and instead always being able to uset()- pre-translation-system really means pre-container. Because as soon as you have a\Drupal::getContainer(),t()will work just fine in current Drupal 8.However, since
watchdog()depends on the container as well, we do not support callingwatchdog()in a pre-container state anyway: It will fatal - regardless of whether you also try to callt()or not.So unless I am missing something major I think this issue should be moved to the Drupal 8 issue queue and be re-titled as "Translate messages before sending them to watchdog()". If I am not mistaken that would also allow us to get rid of the
LogMessageParser-dance we currently have to do to support runtime translation (in a follow-up).Thoughts?
Comment #5
gábor hojtsyNonononono! No! We don't translate messages in logging because of multilingual sites. You would be totally capable of managing an e-commerce site with Hungarian, Arabic and Chinese interfaces but probably not able to debug errors with messages in Hungarian, Arabic and Chinese. So we store the messages and the placeholder values separately for translation later and then can translate it for the language of your choice, eg. German for you, Arabic for your colleague who's mother tongue is Arabic to help figure out the issue. We are doing this for several major Drupal releases starting from Drupal 6.
See http://cgit.drupalcode.org/potx/tree/potx.inc?h=6.x-3.x#n286 and http://cgit.drupalcode.org/potx/tree/potx.inc?h=6.x-3.x#n905 (both the type and message are translated when displayed so both are extracted).
So we need to reproduce this kind of approach somehow to the current logging, IF it still translates the messages on display in dblog that is. And looking at DbLogController, we do
One could say that if there are no variables that does not mean there should be no t(), that is a bug to be opened. But mostly the message and the type are translated on display definitely.
Finally, we need to figure out how this relates to the PSR log message format which uses totally different placeholder conventions.
Comment #6
ParisLiakos commentednotice(), error() and other methods are provided by
\Psr\Log\LoggerTraitwhich the core class usesTranslators should only care for
String::format(). Loggers are responsible for translating PSR style placeholders toString::formatstyle, by usingLogMessageParser, before storing themComment #7
ParisLiakos commentedOh..i might have misunderstood point 3.
PSR style is gonna be used from external libraries. Drupal code should always use the
String::format()style.So if we want to make external libraries' log messages translatable, we could support PSR style as well. Probably worth it?
Comment #8
gábor hojtsyWell, we currently do not even venture into the vendor folder(s) for extraction. I guess we may want to do that for the log messages only. Our other "standard APIs" don't really apply anywhere else. Sounds like we assume / tell module developers to keep using the Drupal scheme, so if we don't parse vendor projects then we are fine storing the string as-is found in the source code without transformation?
Comment #9
ParisLiakos commentedyes, exactly..agreed
Comment #10
gábor hojtsySo looking at how this is defined (at https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logg...) we would need to find strings in methods names the following:
I think detection of strings based on these methods will definitely run into several false positives like debug() which clashes with our own testing APIs at least. Not sure if we use the other method names at other places for non-logging things, but given the simplicity of them they very well may be.
Comment #11
gábor hojtsyHere is a start for what this looks like.
Comment #12
gábor hojtsyAdd log() support. Please review!
Comment #13
gábor hojtsyLooking at that again, the log() parser may go to an infinite loop if there is no second argument to log(), which may be with false positives.
Comment #14
gábor hojtsyThis should skip false positives. Also added to the format_plural checker with tests for both format_plural and formatPlural uses.
Comment #15
gábor hojtsyYay, works. Reviews please :)
Comment #16
gábor hojtsyOh well, then, we'll fix it in followups if needed.
Comment #20
SebCorbin commentedPorted to 7.x-3.x as it has been branched directly from 6.x-3.x