I'm trying to "internationalize" foo.php:
foo.php
-------
.
.
print_string('bar','foo')
.
.
In the same directory, I have subdirectory lang/en_utf8 which contains my language file (also called foo.php)
./lang/en_utf8/foo.php
----------------------
<?php
$string['bar'] = 'baz';
?>
When foo.php is displayed, I see bar (it doesn't work)
However if I move the language file to $CFG->dirroot/lang/en_utf8 and display the page, I see baz (it works).
Must I do something special to get print_string() to look in a local language directory?
In reply to John Isner
Re: getting print_string() to search a local 'lang' directory
by Samuli Karevaara -
At least $CFG->dataroot/lang/en_utf8_local is for local customizations to the English strings. Maybe en_utf8_local in the "module folder" would work too?
In reply to John Isner
Re: getting print_string() to search a local 'lang' directory
by Joseph Rézeau -
John,
I suppose foo.php belongs to a new module you are trying out? If not, how do you access it? And if it does not belong to a module, no wonder moodle will not look into its subdirectory language files.
Have you tried:
./lang/fr_utf8/foo.php
----------------------
<?php
$string['bar'] = 'bazar';
?>
I suppose foo.php belongs to a new module you are trying out? If not, how do you access it? And if it does not belong to a module, no wonder moodle will not look into its subdirectory language files.
Have you tried:
./lang/fr_utf8/foo.php
----------------------
<?php
$string['bar'] = 'bazar';
?>
Login with French as your language and see what happens?
Joseph
In reply to Joseph Rézeau
Re: getting print_string() to search a local 'lang' directory
by John Isner -
I have no idea what a "module" is in Moodle terminology. Is it a directory under mod? e.g., mod/quiz? A directory under block? E.g., mod/quiz_results? Well, mine is none of the above. It is simply one of the existing files under the htmlarea editor, which is part of lib (is it a module?)
I will explain using actual details, rather than foo, bar and baz.
I call print_string from the following file:
Here is a typical call:
I created a local language file
which looks like this:
As I said before, when my page displays, I see
But when I move my "language file" to $CFG->dirroot/lang/en_utf8, it works.
I would prefer a "local" language file rather than a global one for the same reason that I prefer a local variable to a global one.
I looked at the code for get_string (the function called by print_string which does all the actual work). There is clearly a lot of flexibility built into it -- so much that I can't follow it. Surely there is a way to get it to look in a local language directory like ./lang/en_utf8 for a filename of my choosing.
I didn't try the fr_utf8 experiment.
I will explain using actual details, rather than foo, bar and baz.
I call print_string from the following file:
$CFG->dirroot/lib/editors/htmlarea/popups/dlg_ins_smile.php
Here is a typical call:
print_string('insert','dlg_ins_smile')
I created a local language file
$CFG->dirroot/lib/editors/htmlarea/popups/lang/en_utf8/dlg_ins_smile.php
which looks like this:
<?php
...
$string['insert'] = ['test insert'];
...
?>
...
$string['insert'] = ['test insert'];
...
?>
As I said before, when my page displays, I see
But when I move my "language file" to $CFG->dirroot/lang/en_utf8, it works.
I would prefer a "local" language file rather than a global one for the same reason that I prefer a local variable to a global one.
I looked at the code for get_string (the function called by print_string which does all the actual work). There is clearly a lot of flexibility built into it -- so much that I can't follow it. Surely there is a way to get it to look in a local language directory like ./lang/en_utf8 for a filename of my choosing.
I didn't try the fr_utf8 experiment.
In reply to John Isner
Re: getting print_string() to search a local 'lang' directory
by Iñaki Arenaza -
Having a look at the get_string() prototype, I see there is a fourth parameter called $extralocations that, according to the comments above, is "An array of strings with other locations to look for string files".
So I'd say calling get_string() like this:
echo get_string('insert','dlg_ins_smile','',array($CFG->dirroot."/lib/editors/htmlarea/popups/lang/"));
should do the trick.
Saludos. Iñaki.
In reply to Iñaki Arenaza
Re: getting print_string() to search a local 'lang' directory
by John Isner -
Hi Inaki,
I'm sure your method will work, and I will use it. Thanks!
My mistake was in assuming that ./lang would be the conventional location for the "local language directory." It seemed logical, but I guess it's not.
I'm sure your method will work, and I will use it. Thanks!
My mistake was in assuming that ./lang would be the conventional location for the "local language directory." It seemed logical, but I guess it's not.
In reply to John Isner
Re: getting print_string() to search a local 'lang' directory
by Martin Dougiamas -
It is, but Moodle doesn't comb the whole installation every time looking for them (imagine that for every string!) so you need to provide the hint for non-standard locations, as suggested above.