Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I try to translate the system's e-mail messages. In my case order confirmations in Commerce for Drupal. But the same counts for the messages on account creation, deletion, passwords etc. And lots of other strings. I.E. the billing page states Billing information.
I can find these strings on https://localize.drupal.org/translate/languages/nl/translate.
But when I use Localization client I cant find these strings.
Do I do something wrong?
Comments
Comment #1
Gábor HojtsyLocalization client shows strings on the page that were used in translation on the page. Eg. emails were sent in the same page request. Which page do you expect these strings to show up and do you think those strings have been used in translation on that page?
Comment #2
ecvandenberg CreditAttribution: ecvandenberg commentedAttached you find a screenshot where I edit a system action to send an e-mail. The system's interface is translated to Dutch but not for 100%. I.e. the string The mail's from address. Leave it empty to use the site-wide configured address. When I enter the first few words in Localization client,it does not find this string.
When I search for this string in /admin/config/regional/translate/translate I'm able to translate is. So it is a translatable string.
I now understand that the content of the e-mail messages are not translatable strings. But I can find these e-mail messages on https://localize.drupal.org/translate/languages/nl/translate. Obviously that is a different process Where localization client can not help.
Comment #3
Gábor HojtsyHum. Even when you translate this string, it keeps appearing in English?
Also can you search for a shorter part of the text, eg. "The mail"?
Comment #4
ecvandenberg CreditAttribution: ecvandenberg commentedI tried translating the string at /admin/config/regional/translate/translate. That worked fine. In order to show you the issue, I removed the translation again.
When I search for a shorter part of text in Localization client I do get results that show green or white. So all seems to work fine. But it can't find this string. If i.e. I search for the word mail it finds a couple of strings but not the one I search for.
You are very welcome to see for yourself if you would like so. You can create an account, and I can give you the appropriate access rights. It is a test site.
Comment #5
Gábor HojtsyYeah I'm not sure why would this string not show among the strings, if when translated elsewhere on the locale UI it shows translated here. That translation itself would put it into the list for l10n_client. Retitled the issue for the problem at hand.
Comment #5.0
Gábor HojtsyMissing lots of other strings also
Comment #6
paolomainardi CreditAttribution: paolomainardi commentedYes, i guess the problem is related to drupal_static_reset('locale'), i'm facing out the same problem, a lot of strings are missing.
Comment #7
alberto56 CreditAttribution: alberto56 commentedI had the same problem in #2255047: Some strings do not appear in the l10n_client interface: how to debug?, which I set to a duplicate of this one.
Here is a possible solution:
(1) make this module heavier so its page alter hook is executed later than others (enclosed patch).
(2) if you have strings in a preprocess function (which, i think, is called after all page alter hooks), then you can also add the same t() function to a page alter hook in your module (which has a lighter weight than l10n_client), like this:
Comment #8
alberto56 CreditAttribution: alberto56 commentedOops. We also need to set the weight in the hook_install().
Also, I'm wondering if we add our strings even later in the page building process, perhaps in a preprocess function rather than a page alter?
Comment #9
alberto56 CreditAttribution: alberto56 commentedI'm setting this to a bug report because I can systematically exclude strings by placing the t() function in theme or module preprocess hooks, or anywhere else before hook_init() is called.
I have concluded that the module weight is not the issue. Rather, when
drupal_static_reset('locale')
is called in the hook_init(), it is too late for many strings.In this patch I have moved
drupal_static_reset('locale')
from hook_init() to hook_boot(), which does the trick for me: all my strings are now included on the page.Cheers,
Albert.
Comment #10
alberto56 CreditAttribution: alberto56 commentedSetting back to needs work. The above patch shows the desired string, but also shows all other translated strings, even those which are not on the page...
This would be a good candidate for an automated test.
Comment #11
alberto56 CreditAttribution: alberto56 commentedHere I added a failing test which demonstrates the problem.
I'll set to "needs review", just to make sure the testbot picks it up and sets it back to "needs work".
Comment #12
alberto56 CreditAttribution: alberto56 commentedComment #14
alberto56 CreditAttribution: alberto56 commentedFailed, that's normal.
In this patch I am remembering preprocess hooks which were called before hook_init() and calling them again at the end of hook_init(). This causes the new automated test to pass.
Comment #16
alberto56 CreditAttribution: alberto56 commentedPlease ignore the previous patches, they weren't working correctly. Here is a patch which should have two failures: it should be ignoring strings which are translated in the test module's preprocess hook.
Comment #18
Nicolas Bouteille CreditAttribution: Nicolas Bouteille commentedI also noticed that the string "Global tokens will be replaced with their respective token values (e.g. [site:name] or [current-page:title])." form the text format fieldset of any text filtered field does not appear in localization client whereas it does appear in the admin translate interface. So that can also be something to verify when testing your patch.
Comment #19
alberto56 CreditAttribution: alberto56 commentedThanks. I'm actually not sure that these are all the same problem. I could reliably reproduce the fact that strings which are translated in preprocess hook do not appear. But I imagine that the string to which you are referring is not in a preprocess hook. These might be two different issues...
Comment #20
jiv_e CreditAttribution: jiv_e as a volunteer commentedI had some problems with view titles not showing up in the Localization client, but the problem went away when I disabled the view's cache or optionally cleared the page cache.
Just noting that caching can also cause issues if someone has these problems.