Languages

Customise language strings per theme

 
 
Picture of Tim Allen
Customise language strings per theme
 

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)
Picture of David Mudrák
Re: Customise language strings per theme
Group DevelopersGroup Documentation writersGroup Moodle HQGroup Particularly helpful MoodlersGroup 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.
 
Average of ratings: -
Tim at Lone Pine Koala Sanctuary
Re: Customise language strings per theme
Group DevelopersGroup Documentation writersGroup Particularly helpful Moodlers

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 (4)
It's only an avatar...
Re: Customise language strings per theme
Group DevelopersGroup Documentation writersGroup Particularly helpful MoodlersGroup 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

 
Average of ratings: -
Picture of Robert Brenstein
Re: Customise language strings per theme
Group Particularly helpful Moodlers
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.
 
Average of ratings: -
Tim at Lone Pine Koala Sanctuary
Re: Customise language strings per theme
Group DevelopersGroup Documentation writersGroup Particularly helpful Moodlers

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 (2)
Picture of Tim Allen
Re: Customise language strings per theme
 

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

 
Average of ratings: -
Mary Cooch
Re: Customise language strings per theme
Group Documentation writersGroup Moodle Course Creator Certificate holdersGroup Moodle HQGroup Particularly helpful MoodlersGroup TestersGroup Translators

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

 
Average of ratings: -
Tim at Lone Pine Koala Sanctuary
Re: Customise language strings per theme
Group DevelopersGroup Documentation writersGroup Particularly helpful Moodlers

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)
Picture of David Mudrák
Re: Customise language strings per theme
 
Average of ratings:Useful (1)
Picture of Buddy Ethridge
Re: Customise language strings per theme
Group Testers

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

 
Average of ratings: -
Tim at Lone Pine Koala Sanctuary
Re: Customise language strings per theme
Group DevelopersGroup Documentation writersGroup Particularly helpful Moodlers

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.

 
Average of ratings: -
Picture of David Mudrák
Re: Customise language strings per theme
Group DevelopersGroup Documentation writersGroup Moodle HQGroup Particularly helpful MoodlersGroup 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.
 
Average of ratings: -
C'est moi :-)
Re: Customise language strings per theme
Group Documentation writersGroup Particularly helpful MoodlersGroup TestersGroup Translators

I suppose (not tested) that you can also use the Moodle flavours plugin to transfer language customizations from one site to another...

 
Average of ratings: -
Picture of Tim Allen
Re: Customise language strings per theme
 

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. 

 
Average of ratings: -
Tim at Lone Pine Koala Sanctuary
Re: Customise language strings per theme
Group DevelopersGroup Documentation writersGroup Particularly helpful Moodlers

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.

 
Average of ratings: -