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.
To get translation working, I had to change the following code on line 129 from:
$extension .= l(t('@more_text', array('@more_text' => $settings['more_text'])), $uri['path'], array('html' => TRUE, 'attributes' => array('class' => array('more-link'))));
to:
$extension .= l(t('@more_text', array('@more_text' => t($settings['more_text']))), $uri['path'], array('html' => TRUE, 'attributes' => array('class' => array('more-link'))));
Comment | File | Size | Author |
---|---|---|---|
#12 | smart-trim-i1i8n-string-2533032-2.patch | 1.6 KB | Berdir |
#8 | smart_trim-translate-read-more-2533032-8-D7.patch | 1.05 KB | markie |
#1 | smart_trim-translate-read-more-2533032-2-D7.patch | 911 bytes | dragos-dumi |
Comments
Comment #1
dragos-dumi CreditAttribution: dragos-dumi commentedThis bug was introduced in the commit f7e80ade63f962f4d96337fb27bbb18ae9009b1f
The line should be restored to it's previous state because t function replaces the placeholder after locale. (see the attached patch)
Comment #2
dragos-dumi CreditAttribution: dragos-dumi commentedComment #3
rodrigoaguileraI can confirm this.
I feel that both approaches (after and before patch) need improving.
I'm using features and potx and the 'more_text' is a setting for each view mode inside the field instance settings.
Maybe it should use something like i18n_field to translate each instance and fallback to the method you are trying to use.
Comment #4
my-family CreditAttribution: my-family commentedI can confirm the issue. After the #1 patch the string is available for translation and the translation works.
Comment #5
Ahmad Abbad CreditAttribution: Ahmad Abbad at Vardot for Vardot commentedI can confirm the issue.
Patch #1 worked for me
Comment #6
akalam CreditAttribution: akalam at Atenea tech commentedWorked for me too! Let's make this RTBC. In my opinion #3 sould be a diferent issue, this one is for translatable feature
Comment #7
Khumbu CreditAttribution: Khumbu commentedworks like a charm...
Comment #8
markie CreditAttribution: markie at Mediacurrent commentedSo I really don't like the smell of a t() inside of a t(). It doesn't seem to make sense to me. Also, coding standards wants to pass a string literal where possible. (I hate the squiggly lines in phpstorm so I do as much as I can to get rid of them.
I created a new version of the patch for your review. Thanks for your help
Comment #9
rodrigoaguileraI feel we are trying too hard to avoid the use of i18n_string.
t() is supposed to be for fixed strings translation. Using t() for this seems like an abuse.
I don't see clearly how the text ends up translated in the latest patch. It is the same case as the code was before patches but with more wrapping.
Comment #10
Anonymous (not verified) CreditAttribution: Anonymous commentedI concur with @rodrigoaguilera regarding the latest patch. I think the first patch should be used. Regarding i18n_string I think that can be done later, but that requires a dependency to the i18n_module (also for users not using it). The site we are working on uses translations but doesn't use i18n_string, since that causes other problems.
Comment #11
elondaits CreditAttribution: elondaits at IMAGINARY commentedTranslation of the "read more" is really necessary and I'd say it's too little to justify installing a whole extra module even if it goes against the philosophy of t(). I do use i18_strings and wouldn't want this module to use that because importing strings from a file (for code versioning and deploying in dev, test and production) it's a real pain because it requires a file per language and context.
Comment #12
BerdirUsing t() on user-provided text is a strict no-go. Translations get lost if you edit the original, and it can even result in security issues.
In fact, this is basically what https://www.drupal.org/node/2480321 was about. That could be prevent by running it through a check_plain(), the new code is also very pointless as there's nothing to translate anymore. And it even explicitly sets html => TRUE, meaning it allows HTML. We can just drop that, and l() does a check_plain() for us, making it secure.
As a workaround, I think you could actually translate "@read_more" to whatever you want, it simply is global then and not configurable anymore per field.
This is a first patch using i18n_string(), but it's not very well tested yet. It has the opposite downside that you need to translate it per-field as it is depending on the context, and it actually can't be translated per view mode as the formatter doesn't have the view_mode string available as far as I see.
Comment #13
barraponto CreditAttribution: barraponto commentedLooks good, works for me.
Comment #14
markie CreditAttribution: markie at Mediacurrent commentedSorry folks. #12 doesn't apply for me cleanly. I have added a few commits before it. Please re-roll