Is it possible to override core translations from a plugin?

Is it possible to override core translations from a plugin?

by Juho Jaakkola -
Number of replies: 10

I need to override a particular translation string used in the Moodle core. The language customization feature is not an option because I want the translation to change when my plugin is installed/removed.


Install the plugin -> Moodle uses the customized string

Remove the plugin -> Moodle immediately uses the original string


Example use case:

By default the login form says "Username". When a plugin is installed, the form says "Username / Email" instead.

(This is just an example. I'm aware it's already possible to sign in using email address in Moodle 2.7)


Is it possible to override strings like this?

Average of ratings: -
In reply to Juho Jaakkola

Re: Is it possible to override core translations from a plugin?

by David Mudrák -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators
It makes sense. But I don't think it's doable at the moment.
In reply to David Mudrák

Re: Is it possible to override core translations from a plugin?

by Juho Jaakkola -

Ok, I made an issue for it: https://tracker.moodle.org/browse/MDL-46582

In reply to Juho Jaakkola

Re: Is it possible to override core translations from a plugin?

by Robert Brenstein -
I am not sure that allowing a plugin to override Moodle core translations is such a good idea. Theoretically, your installer could create or amend the local language file during installation (and remove the entry when uninstalled). However, if that was a generic functionality, how are the conflicts with locally customized strings resolved? A given site might have already modified that string and your plugin would change that. A string like "login" is very visible, so the site would notice it and restore its modification (and restore again if your plugin is uninstalled) but overwriting of other strings might not be so apparent. In the case of your plugin, if it is a publicly available plugin, I'd leave the modification of strings to the admin installing your plugin. They will know better whether it is desired and how. Things get even more complicated for multilingual sites.
In reply to Robert Brenstein

Re: Is it possible to override core translations from a plugin?

by Juho Jaakkola -

The plugins where I would need this feature are not publicly available. So there is no risk of overriding anything accidentally.

But just to answer your questions, I think it would be OK if the priority for translations was:

  1. Locally customized
  2. Provided by plugins
  3. Provided by Moodle core
In reply to Juho Jaakkola

Re: Is it possible to override core translations from a plugin?

by Robert Brenstein -
As I understood your request, you want the option to change core strings by plugins as a generic Moodle feature available to all developers. As such, various implications have to be considered. Keep in mind that strings in Moodle live in various "namespaces".
In reply to Robert Brenstein

Re: Is it possible to override core translations from a plugin?

by Juho Jaakkola -

Yes, I of course acknowledge that all possible translation use cases must be taken into consideration before adding the feature.

BTW, by namespace, do you mean the second parameter:

$foo = get_string('foo', 'bar');VTW, 
In reply to Juho Jaakkola

Re: Is it possible to override core translations from a plugin?

by Robert Brenstein -
Yes, indeed. Local overwrites is the further extension.
In reply to Robert Brenstein

Re: Is it possible to override core translations from a plugin?

by Juho Jaakkola -

I have this kind of approach in my mind:

Particular strings for example in this translations file:

/auth/email/lang/en/auth_email.php

Could be overridden by another plugin (in this case a local plugin called "my_plugin")  through the file:

/local/my_plugin/lang/en/auth_email.php


This way the translation overriding would affect only a particular namespace.

In reply to Juho Jaakkola

Re: Is it possible to override core translations from a plugin?

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

If the only change is to the Login screen Username/ Email then you can add a customised Login in your theme something like this...where the login is in the top menu bar.

http://bylazydaisy.co.uk/