At the User interface translation page (/admin/config/regional/translate) the SOURCE STRING list seems to be ordered by creation date/time (it is for strings I add). Is there a "good" (non-hackish) way to change the order to alphabetical? I haven't found anything in the interface.

For those who wonder why I want this, I use interface translation in an unconventional way. Instead of putting literals like t("Choose your options") in my code, I put in a key like t('rsc-string-choose-options') [rsc is the name of my custom module]. Then as the translation, I put in "Choose your options". This allows me to use "keys" for all strings (literals, messages, titles, email body text, etc.). It's easy to look up my keys because they all begin with 'rsc-' followed by 'string', 'message', 'email', etc. depending on usage. Doing this provide a nice interface for editors to go in and change the text of the strings, since they can look them up either by translation or by key. I also wrote a nice utility that allows me to add, remove, rename, and test keys (i.e. translation strings). It's working very well, but it would make review much easier if the source strings were alphabetical.

1 Answer 1


It depends on what you want to call "good" & "non-hackish".

If you're looking for a simple configuration change, then no; there's no configuration change that you can make to modify the translation strings order.

If non-hackish includes using Drupal APIs to override routes & services in a custom module, then yes.

You can use a custom module to override the locale.translate_page route with your own custom controller & form class that will do the same work of TranslateEditForm::buildForm(), but modify the behavior of ::translateFilterLoadStrings() so it produces a different ordered list of translation strings.

The string order is the result of a method in the locale.storage service that performs the dynamic query (see StringDatabaseStorage::dbStringSelect() where the query is built). You'll probably have to override that service in some manner to provide the same structured query object, but with an orderBy method added to execute the same query but with the sorted order you're looking for.

  • Yes, I consider this non-hackish. I'll try it and report. Jun 1, 2020 at 20:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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