I have a site (v8.4.2) with all core language modules enabled, 3 active languages, English is the default. The pager labels (e.g. "Last »") for my own Views are not translated although the string "Last »" is available in User interface translation. I can manually translate the pager labels by adding a translation for the whole View and then overriding the pager labels, but I think this is not the right way to do it because the built-in Views (e.g. /admin/content) are translated just fine, without any manual overrides.

So: How can pager labels be translated automatically by the User interface translation strings and not manually by adding a View translation? Thanks for your help!

EDIT: I have found out why it is happening this way:

  1. Yesterday I did not see it, but the built-in content View from my example (/admin/content) is indeed translated to the other two languages, with the translated pager labels being present there.
  2. The pager template (core/themes/classy/templates/navigation/pager.html.twig) is "missing" the translation filter (|trans) and that is why the User interface translation has no effect on the pager label string. I wrote "missing" in double quotes because if the translation filter was there, then it could be difficult to add a custom translation via the View translation because that translation could be modified by the User interface translation. For me this is not relevant, so I will just add the translation filter to the pager template, resulting in this line for my example of the last pager label:

    Original: {{ items.last.text|default('Last »'|t) }}

    With trans filter: {{ items.last.text|trans|default('Last »'|t) }} (I use "trans" because it is better distinguishable than just "t")


I have seen this too. Looking thru the code, it appears that the pager templates do have translations set up properly. So in theory, UI translations should work. But they don't.

I haven't tried it but you probably could do this thru the hook_preprocess_pager__page(&$variables) function (for full views pages). There seems to be a $variables['pager']['#tags'] array with the values for pagers. You might be able to do the UI string translation here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.