Customise language strings per theme

Customise language strings per theme

by Tim Allen -
Number of replies: 15

Hi, I searched for this answer but couldn't find any reference to it:

Is it possible to customise language strings per theme?  We want to change some of the text for the assignment tool (because we are using it without any grading, which is inappropriate for the course we are developing), but I would prefer to override it from our custom theme only, so that this doesn't have to be changed for all courses on the server.

TIA, Tim. smile

Average of ratings: Useful (1)
In reply to Tim Allen

Re: Customise language strings per theme

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
Hi Tim

No. Strings can be locally customized but such local customizations are for the whole site only. Strings can't be customized per course or per theme.
In reply to David Mudrák

Re: Customise language strings per theme

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

However, what you can do is this:

You can define a new 'language' say en_tim, which just has a few strings that are different from the normal en lang pack. (Using the same technique that lets fr_ca (French canadian lang pack) be almost the same as fr.)

Then you can cusomise the strings in that language.

Average of ratings: Useful (5)
In reply to Tim Hunt

Re: Customise language strings per theme

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

That's interesting Tim, but where you add these strings? Or rather the pack?

You can't add them to the theme as that only caters for the strings that are generated by the theme as in custom settings pages et al.

If I was to create a theme specific language pack containing strings that I want to override that are in a course page or some other Moodle page, how would I go about that, if I was to use the same principle that you mentioned with regards 'tim_en'.

Mary

In reply to Mary Evans

Re: Customise language strings per theme

by Robert Brenstein -
I think that Tim means to create a new language with the standard language of the site as its parent. The child language would need to define only the strings that are different. The en and en_us language packs are probably the most prominent examples. That new language is then added to Moodle instalation and set as the language of a given course (forced). No specific binding to a theme.
In reply to Mary Evans

Re: Customise language strings per theme

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Sorry, I did not explian at all, did I. Sorry.

I think what you need to do is:

  1. Create a new folder lang/en_custom inside your Moodle code.
  2. In there create a file langconfig.php, but copying the one from en/langconfig.php.
  3. The key string to set in there is parentlang. In fact, the only things you need to define in there are:

$string['parentlanguage'] = 'en';
$string['thislanguage'] = 'English (customised)';
$string['thislanguageint'] = 'English (customised)';

You can delete everything else in that file.

You may then need to do purge all caches before you can select that language in the Moodle UI, and use the Language customisation tool.

Average of ratings: Useful (4)
In reply to Tim Hunt

Re: Customise language strings per theme

by Tim Allen -

Thanks a lot Tim and others for the advice on this - that sounds like a really useful workaround.  Before seeing your instructions Tim, I tried to use the Moodle "language customisation" interface, which actually created an "en_local" folder in the moodledata directory.  I guess this is different to an actual language pack which has a parent language set?  There seems to be no info on this in the Moodle docs that I could find.

Regarding your instructions, could I confirm the correct location of the custom language pack: /path_to_moodledata/lang/en_custom ?

Cheers.  smile

In reply to Tim Allen

Re: Customise language strings per theme

by Mary Cooch -
Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators

Have a look at Translation here (Although they might  still be versions of  English, new languages packs are "translations")

In reply to Tim Allen

Re: Customise language strings per theme

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Actually, en_local is different. That stores local changes to the en language pack, it does not create a new language pack called en_local.

If you create a new language pack called en_custom, as I explain above, and then edit it, you will get a folder called en_custom_local in moodledata.

Average of ratings: Useful (1)
In reply to Tim Hunt

Re: Customise language strings per theme

by Buddy Ethridge -

Tim,

Tangental to this conversation, if you create a new language pack per your instructions and then make your desired alterations, can that pack be subsequently downloaded and used in other instances?  We have four production instances running, and it would be extremely beneficial to me if I did not have to do the language customizations individually in each instance.

Buddy

In reply to Buddy Ethridge

Re: Customise language strings per theme

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Well, the strings are stored in files somewhere, so I think it is just a matter of finding those files and copying them. (You will have to work out the details on your own.)

I suppose it might be nice to have a UI for dowloading / uploading files like that. I guess it would be possible for someone to make an admin tool plugin for doing just that, if they were so minded.

In reply to Buddy Ethridge

Re: Customise language strings per theme

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
Buddy, yes. As is described at http://docs.moodle.org/24/en/Language_customization already mentioned here, your local changes are stored into moodledata/lang/ folder. After you check-in your changes in the language customization tool, they are saved into a directory moodledata/lang/xx_local/ where xx is your language code.

Just copy that xx_local folder to another server into the same location, purge all caches from the server administration and done.
In reply to Tim Allen

Re: Customise language strings per theme

by Tim Allen -

Thanks again for the help everyone.  smile  The links in the docs are definitely helpful, but I was really looking for some instructions on how to create a new "child" English language pack to be used with my custom theme and course only, rather than how to "customise" a language pack via the web interface.  More like what Tim posted above I guess.

I want to distribute one zip file that contains the language pack.  So I don't want to use the web interface because that will create an en_custom_local folder. Therefore I need to edit the files directly, yes?  

And should "defined('MOODLE_INTERNAL') || die();" be in my custom language pack files?

Thanks, Tim. 

In reply to Tim Allen

Re: Customise language strings per theme

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

If you do what I said, you do create a child English language pack. If you want to edit more strings through code rather than the admin UI, then just put more files in the lang/en_custom folder.