Problem/Motivation
The default value for the Count down message is not translatable, including the variables @limit, @remaining and @count that are available in that field. This is because you should never use t() to translate variables.
The current default value is
Content limited to @limit characters, remaining: @remaining
Steps to reproduce
- Install and enable Language and translation modules
- Configure administration pages to use a language other than English.
- Visit the User Interface Translation admin page (/admin/config/regional/translate)
- Search for "Content limited"
Resolution
The reason the count down message is not translatable is because of Drupal core bug #2546212: Entity view/form mode formatter/widget settings have no translation UI.
Until that issue is resolved, do the following to translate the count down message through the UI.
- Apply the patch from #2546212: Entity view/form mode formatter/widget settings have no translation UI. This patch will add the UI needed to add the translations.
- Clear the cache.
- Log in as admin.
- Go to Configuration > Regional and Language > Configuration translation.
- In the list, find the row that contains the "form display" configuration for the entity type that has the field you want to translate. For example if you are using nodes, find "Content form display". Click "List" in this row.
- Click "Translate" next to the bundle name that has the field you want to translate.
- Now press "Add" or "Edit" for the language you want to translate to.
- Next up look in the "Field widgets" section and find the configuration for the field you want to translate. Note that this UI is still a work in progress and might not be very intuitive.
- Expand the "Third party settings" fieldset and edit the translation.
- Press "Save translation" at the bottom of the form.

| Comment | File | Size | Author |
|---|---|---|---|
| #38 | maxlength-config-translation.png | 44.6 KB | pfrenssen |
| #31 | screenshoot-14987353.png | 172.88 KB | mukesh88 |
| #27 | interdiff_21-25.txt | 9.26 KB | mukesh88 |
| #27 | 2955352-25.patch | 9.76 KB | mukesh88 |
| #21 | interdiff_19-21.txt | 3.02 KB | mukesh88 |
Issue fork maxlength-2955352
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
rpayanmComment #3
rpayanmComment #4
eelkeblokThe t-function should never be passed a dynamic string. See the section "Translating variables" at https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/t/7.x. The original code is the "correct" way of using it. If you need to translate settings, that is the realm of the i18n suite of modules. Sorry that I can't give any more detailed guidance and basically just torpedoed your patch :( (I would like to have this translatable myself, or I would not have found the issue).
Comment #5
eelkeblokAlso see #2823995: Can't translate countdown message.
Comment #6
amneh.shawish commentedThis patch is working fine for me.
Comment #7
priyanka_b commentedUpdating Patch which supports to Drupal 9
Comment #8
priyanka_b commentedComment #9
cedeweyComment #10
cedeweyComment #11
doxigo commentedThe patch works fine, changing the status
Comment #12
hipp2bsquare commentedSorry to say that the feedback from eelkeblok in comment #4 is accurate -- as per current Drupal documentation, the t() function should only be fed a literal string, not a variable.
An alternative approach should be researched.
Comment #13
weri commentedLooks like this is solved with 2.0.0-rc3.
I think we can mark this issue as resolved?
Comment #14
cedeweyI checked and the default value of the Count down message is still not translatable.
Before investing more time into a technical solution, we should understand from multilingual site builders and owners if and to what degree this is a problem. It might be best to leave this as is rather than dive into the complexity of translating a string with variables.
If you are a multilingual site builder and/or site owner, please comment on how you currently handle this issue, if and how you would prefer the translation process to be and how important it is for you.
Comment #15
cedeweyComment #16
weri commented@cedewey, I was wrong, this particular problem is not solved. I was not checking the code enough. Sorry about that!
As I had a deeper look now, I saw, that when I let the "Count down message" empty on the field definition, the default text is used and translatable, that's a great! Currently I don't have to change the default text and this way it works for me.
Sometimes it could be interesting to have a custom count down message, but I see the security risk using a variable for the t() function.
- But I can add the "Count down message" text only when I have the proper permission. Could this be save enough to use the t() function with a variable?
- We can add a validation for the "Count down message" text with the locale_string_is_safe() function as it is handled in the UI translation?
Not sure, it there a better way.
Comment #17
cedeweyOh interesting, I've updated this issue with that known workaround.
As for possible solutions we completed #3280195: Remove the "Bypass Maxlength setting" permission in the last release and I'd rather not reintroduce a permission. However, adding validation with the locale_string_is_safe() function is worth considering.
Comment #18
cedeweyComment #19
g0blin79 commentedPatch rerolled for 2.0.0 release
Comment #20
cedeweyComment #21
mukesh88 commentedComment #22
mukesh88 commentedComment #23
cedeweyHi @mukesh88, thanks for contributing your patch. To get this work accepted we need to address the fact that we should never use t() to translate variables.
If you can update your patch to account for that, that would be great. Thanks!
Comment #24
mukesh88 commentedComment #27
mukesh88 commentedI have used TranslatableMarkup instead of t() function in #25
Comment #28
mukesh88 commentedComment #29
mukesh88 commentedComment #30
kunal_sahu commented@mukesh88 Can you please look at this issue .
Thanks
Comment #31
mukesh88 commented@kunal_sahu patch apply successfully for 2.1.x version.
Comment #32
kunal_sahu commented@mukesh88 Apologies , i was applying it to the wrong branch.
The patch looks good to me.
I think this issue can be now moved to RTBC.
Thanks
Comment #33
mukesh88 commented@kunal_sahu if you have review the issue then you can moved to RTBC
Comment #34
joevagyok commentedI think the root of the problem is in this issue. I will address the linked issue first, and let's see after if this issue can be resolved by it.
Comment #35
joevagyok commentedComment #36
cedeweyI tested this on our 2.1.x branch and I believe this is now working as expected. The tokens, @limit and @remaining and @count need to stay named as such, but I think that's ok. Otherwise, the other countdown message text if translated shows up as expected on the respective language's edit form.
Comment #37
cedeweyI misspoke. What I had done was change the countdown message to Spanish and displayed as such even in English interfaces. I went to the User Interface Translation admin page (/admin/config/regional/translate) and searched for "content limited" and the MaxLength countdown string was not available.
So, there is still work that needs to be done to make the countdown message translatable.
Comment #38
pfrenssenI can confirm that the fix from #3345225: Config schema type for maxlength_js_label and maxlength_js_label_summary should be text has also solved this issue. I can also confirm as many said before that the approach in the current patch is wrong.
The confusion about how to translate this probably arises from the fact that there is no UI for translating field widget configuration yet. But there is a WIP patch in #2546212: Entity view/form mode formatter/widget settings have no translation UI that adds this UI.
I will close this as "Works as designed" since this is already working from the perspective of the MaxLength module.
Here are instructions to make it work:
Here is how the UI looks:
Comment #39
cedeweyThanks Pieter, this is very helpful. I've updated the task description with this resolution and am crediting you as the author of this fix. Much appreciated!
Comment #40
markdcI also wish to express my thanks @pfrenssen
This solution is certainly the way forward.