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.
This is a duplicate of https://www.drupal.org/project/smart_trim/issues/2782689. I'm opening this because I can't reopen that other issue. While the patch was committed in 2017, the 1.2 version release in December 2019 doesn't have it. Can we get a new release with the patch in https://www.drupal.org/project/smart_trim/issues/2782689#comment-13420851 applied? Let's get this reviewed and approved and this will go into the next release, hopefully this weekend.
Comment | File | Size | Author |
---|---|---|---|
#19 | Screen Shot 2020-05-03 at 8.58.13 PM.png | 143.27 KB | Kristen Pol |
#13 | Screen Shot 2020-04-30 at 5.20.07 PM.png | 89.05 KB | Kristen Pol |
#13 | Screen Shot 2020-04-30 at 5.19.31 PM.png | 85.51 KB | Kristen Pol |
#13 | Screen Shot 2020-04-30 at 5.19.55 PM.png | 85.38 KB | Kristen Pol |
#13 | Screen Shot 2020-04-30 at 5.19.10 PM.png | 182.45 KB | Kristen Pol |
Comments
Comment #2
markie CreditAttribution: markie at Mediacurrent commentedLooks like this was reverted with some other code in 9beaadf7. Let me review
Comment #3
markie CreditAttribution: markie at Mediacurrent commentedFigured out why that got reverted. The way the t() was used caused an PHPCS issue. I created this patch that 1) removes the unused link, and 2) uses t() in the proper vein.
Comment #4
Kristen PolTaking a look.
Comment #5
Kristen PolThanks for the patch. Quick question:
I've only seen placeholders used along with hard-coded text, not alone, in the
t()
. What was the motivation for this structure? Were you trying to make it more readable or something else?For example, from
includes/bootstrap.inc
is the structure of what I'm used to seeing with a placeholder:Comment #6
Kristen PolI did find one example in core in
lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/SelectionBase.php
:but this confuses me because, from what I remember, you don't translate the placeholders, just the hard-coded text. I guess I need to brush up on my APIs (and get a lot more sleep).
Comment #7
Kristen PolI'm going to try out the patch given that it seems fine to have that structure.
Comment #8
PapaGrande@kristen-pol, I think the structure is correct because in this case we want to translate the user's text label and not a hard-coded value.
Comment #9
Kristen Pol@PapaGrande Yeah. My brain cells aren't firing well (little sleep) but I'm about to manually test it right now. Thanks!
Comment #10
Kristen PolManually tested version 8.x-1.2 on simplytest.me as follows:
I'll try it on a different field next.
Comment #11
Kristen PolOk, I don't know what I'm doing wrong (custom field doesn't work either) but I'll give up the issue so someone else can keep this going.
Comment #12
Kristen PolFound this on the project page:
I was assuming the more would toggle the text. Whoops. I really want a nap :)
Comment #13
Kristen PolTesting the translation, I can only translate @more_text, which is what I suspected. Ideally, I'd want to translate the text that was added by the user which means then the placeholder shouldn't be used. I have the more text on the body field and a custom field with different text in English but I can only translate @more_text so all the more text ends up being the same in each language. Seen screenshots. IMO, the original patch that did not using the placeholder is the desired approach. Sorry for so many comments, my brain is kind of mush right now.
Comment #14
markie CreditAttribution: markie at Mediacurrent commentedThanks for the great work Kristen. The reason I am doing the
is that when I don't, I get a PHPCS notification "Only string literals should be passed to t() where possible". Plus this runs the text through formatting checks.
I think your tests are great but you're testing '@more_text' which really will be replaced by whatever you put in the more_text configuration of your field..
I am gonna be honest here and state that I have never actually tested this functionality in a multilingual environment, so this is some appreciated work!
Comment #15
Kristen PolThinking about it more. Seems like this should be config translation like for views text. I'll try to dig around for that approach unless someone beats me to it.
Comment #16
PapaGrandeSorry, but I just tried the patch in #3 on my multilingual site and it does not work. https://www.drupal.org/files/issues/2020-01-13/translate-more-link_0.patch still does.
Comment #17
Kristen PolI've been reviewing how configuration translation works for various modules as I think that is the correct approach for here since you want to allow translation of user-inputted information which is what configuration translation is for.
If you had a settings form for the module to configure things such as site information, then the translate tab can be provided with that and used to translate the translatable things. Smart Trim embeds the configurable text within manage display so it's trickier. It's more similar to views as there are different displays for views to configure things similar to the different display modes on the manage display tab.
I was trying to grok how views was implementing the configuration translation support but don't understand it yet. Note that views has the translation tab with the views page/form which makes sense. Since Smart Trim config isn't on a dedicated page, then I think you'd need to add a settings page for this so it can have the tab off of that.
I'm wondering if there is an issue somewhere for making manage display settings translatable. I'll search around.
Comment #18
Kristen PolI think I found the relevant issue for translating display mode configuration via configuration translation:
#2546212: Entity view/form mode formatter/widget settings have no translation UI
Comment #19
Kristen PolI tried out a couple patches from:
#2546212: Entity view/form mode formatter/widget settings have no translation UI
because I wanted to see if it would automagically handle contrib modules like Smart Trim but it wasn't working on simplytest.me so I'd have to test locally. My laptop is running out of space and generally sluggish so not sure when I'll get around to that. Maybe someone can take it for a whirl?
Comment #20
GaëlGThanks to this great todo list, I made it on simplytest.me:
https://stm5eb17f2e9107d-bfzg0xzgcu9taxwzn3euc4u4b2gpbp8f.tugboat.qa/adm...
I got a "You are not authorized to access this page." after step 8. Even after applying step 10 and a cache flush.
Comment #21
Kristen PolThanks. That was the problem I had on simplytest.me too. I commented on that issue about it. I was hoping someone would go through the steps on their local instead. (My computer is nearly out of space so hard for me to test locally at the moment.)
Comment #22
Kristen PolI was able to get the configuration translation to work for a boolean field:
https://www.drupal.org/project/drupal/issues/2546212#comment-13606763
so IMO looking how the configuration translation is set for that is the next step here.
Comment #23
Kristen PolOk, I think this might work:
1) Update
config/schema/smart_trim.schema.yml
and change:
to
2) Apply the latest patch from #2546212: Entity view/form mode formatter/widget settings have no translation UI
3) Follow instructions from #19
If someone will make the patch and add here, I can test this approach works.
Comment #24
PapaGrande@kristen-pol, thanks for your persistence. I think you're on the right track based on https://www.drupal.org/project/drupal/issues/2418481.
Comment #25
Kristen Pol@PapaGrande Woot! Indeed: https://git.drupalcode.org/project/drupal/commit/cb0e300 :) Marking "Novice" as this is a trivial patch requested in #23.
Comment #26
Kristen PolNote, in order to not hold up the D9 release of Smart Trim, IMO we could do:
1) Use the old (though not correct) approach for allowing translation of more text via Interface Translation using t(), e.g.
At least this would get rid of the regression.
2) Create a follow-up issue to implement the translation correctly using Configuration Translation per comments above. IMO, the new code should ideally also handle automatically copying or "moving" any "more text" translations from Interface Translation to Configuration Translation.
Comment #28
markie CreditAttribution: markie at Mediacurrent commentedDid some digging on this today and it's really weird that the placeholder text becomes translatable.... I went ahead and committed the old change back (and removed the unused Use command) but really need to dig into this some more. Will mark this fixed so we can get on with the D9 compatible version.
Comment #29
Kristen PolThanks @markie! Placeholders aren't translatable by design so it makes sense to me. I did get confused by the example I found in #6 but I haven't had time to look at it more closely.
Comment #30
markie CreditAttribution: markie at Mediacurrent commentedIt is weird that they show up in the translation UI though... @more_text can be translated there.. but.... why would we want to? Then again, it could be argued that @more_text would always be translated to what we want there.... /shrug
Comment #31
Kristen PolIt's because usually the placeholder would have additional text around it, e.g.
For these
@interval
,@entity_type
, and@timezone
won't be translated but you can translate the text around it and even move the placeholder relative to the text as needed (e.g. RTL).It doesn't make sense to use the placeholder just by itself with translation which is why I'm confused about #6 and I just go back and see what's up with that one at some point. :)
Comment #33
weri CreditAttribution: weri at Previon Plus AG commentedIn the newest dev version for 2.1.x (not working in the 2.1.0 release) you can use the hook "hook_smart_trim_link_modify" to modify this text or the link in general.
Example: