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

  1. Install and enable Language and translation modules
  2. Configure administration pages to use a language other than English.
  3. Visit the User Interface Translation admin page (/admin/config/regional/translate)
  4. 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.

  1. 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.
  2. Clear the cache.
  3. Log in as admin.
  4. Go to Configuration > Regional and Language > Configuration translation.
  5. 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.
  6. Click "Translate" next to the bundle name that has the field you want to translate.
  7. Now press "Add" or "Edit" for the language you want to translate to.
  8. 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.
  9. Expand the "Third party settings" fieldset and edit the translation.
  10. Press "Save translation" at the bottom of the form.

Screenshot of translation interface for countdown message.

Issue fork maxlength-2955352

Command icon 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

rpayanm created an issue. See original summary.

rpayanm’s picture

Issue summary: View changes
rpayanm’s picture

eelkeblok’s picture

Status: Needs review » Needs work

The 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).

eelkeblok’s picture

amneh.shawish’s picture

This patch is working fine for me.

priyanka_b’s picture

StatusFileSize
new3.26 KB

Updating Patch which supports to Drupal 9

priyanka_b’s picture

StatusFileSize
new3.26 KB
cedewey’s picture

cedewey’s picture

Version: 8.x-1.x-dev » 2.0.x-dev
doxigo’s picture

Status: Needs work » Reviewed & tested by the community

The patch works fine, changing the status

hipp2bsquare’s picture

Status: Reviewed & tested by the community » Needs work

Sorry 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.

weri’s picture

Looks like this is solved with 2.0.0-rc3.

I think we can mark this issue as resolved?

cedewey’s picture

Title: Text is not translated » Count down message default text is not translatable
Issue summary: View changes

I 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.

cedewey’s picture

Title: Count down message default text is not translatable » Count down message text is not translatable
weri’s picture

@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.

cedewey’s picture

Issue summary: View changes

Oh 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.

cedewey’s picture

Issue summary: View changes
g0blin79’s picture

StatusFileSize
new3.26 KB

Patch rerolled for 2.0.0 release

cedewey’s picture

Version: 2.0.x-dev » 2.1.x-dev
mukesh88’s picture

StatusFileSize
new1.95 KB
new3.02 KB
mukesh88’s picture

Status: Needs work » Needs review
cedewey’s picture

Status: Needs review » Needs work

Hi @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!

mukesh88’s picture

Assigned: Unassigned » mukesh88

kunal_sahu made their first commit to this issue’s fork.

mukesh88’s picture

StatusFileSize
new9.76 KB
new9.26 KB

I have used TranslatableMarkup instead of t() function in #25

mukesh88’s picture

Status: Needs work » Needs review
mukesh88’s picture

Assigned: mukesh88 » Unassigned
kunal_sahu’s picture

Status: Needs review » Needs work

@mukesh88 Can you please look at this issue .

$ git apply -v 2955352-25.patch
Checking patch maxlength.module...
error: while searching for:
      $maxlength_js = $thirdPartySettings['maxlength']['maxlength_js_summary'];
      $element['summary']['#attributes']['data-maxlength'] = $maxlength_js;

      $maxlength_js_label = !empty($thirdPartySettings['maxlength']['maxlength_js_label_summary']) ? $thirdPartySettings['maxlength']['maxlength_js_label_summary'] : t('Content limited to @limit characters, remaining: <strong>@remaining</strong>');
      $element['summary']['#attributes']['maxlength_js_label'][] = $maxlength_js_label;

      if (isset($thirdPartySettings['maxlength']['maxlength_js_enforce']) && $thirdPartySettings['maxlength']['maxlength_js_enforce']) {

error: patch failed: maxlength.module:161
error: maxlength.module: patch does not apply

Thanks

mukesh88’s picture

Status: Needs work » Needs review
StatusFileSize
new172.88 KB

@kunal_sahu patch apply successfully for 2.1.x version. Screenshoot

kunal_sahu’s picture

@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.

/web/modules/contrib/maxlength-2955352 (2.1.x)
$ git apply -v 2955352-25.patch
Checking patch maxlength.module...
Applied patch maxlength.module cleanly.

Thanks

mukesh88’s picture

@kunal_sahu if you have review the issue then you can moved to RTBC

joevagyok’s picture

I 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.

joevagyok’s picture

Assigned: Unassigned » joevagyok
cedewey’s picture

StatusFileSize
new31.74 KB
new28.26 KB

I 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.

Translated MaxLength form.

Translated countdown message.

cedewey’s picture

Status: Needs review » Needs work

I 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.

pfrenssen’s picture

Status: Needs work » Closed (works as designed)
StatusFileSize
new44.6 KB

I 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:

  1. Apply the patch from #2546212: Entity view/form mode formatter/widget settings have no translation UI that works with your version of Drupal core. This patch will add the UI needed to add the translations.
  2. Clear the cache.
  3. Log in as admin.
  4. Go to Configuration > Regional and Language > Configuration translation.
  5. 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.
  6. Click "Translate" next to the bundle name that has the field you want to translate.
  7. Now press "Add" or "Edit" for the language you want to translate to.
  8. 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.
  9. Expand the "Third party settings" fieldset and edit the translation.
  10. Press "Save translation" at the bottom of the form.

Here is how the UI looks:

Screenshot of form display translation UI

cedewey’s picture

Title: Count down message text is not translatable » Count down message text is not translatable through the UI
Issue summary: View changes

Thanks 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!

markdc’s picture

I also wish to express my thanks @pfrenssen
This solution is certainly the way forward.