Questions about internal implementation of language resolution

Questions about internal implementation of language resolution

by Valery Fremaux -
Number of replies: 7

Hi,

I'm seeking the answer to both questions :

1. What was the original reason to have an evaluated expression as return of get_string_from_file(), and the call to sprintf() ?

2. I'm trying to have a language pack that could switch easily some keywords all through, allowing administrator to switch the semantics of some key concepts at configuration time. The reason is that some Moodle customisaton may introduce some new situations that would need such shifting.

Key words such as "course", "category", "theme", "section", "sudent", "teacher", etc. are defining a small set (about 40 to 50 keywords) that drives the entire application of the platform. Those keywords appear in quite every lang files, and are pretty frequent, so any change for adapting the platform to a contextual situation will require hours in langpack reworking.

There is absolutely no way to inject some recursive call to get_string in lang files, as this introduces a mad loop in the language implementation.

 If someone knows whatever genious trick to inject some globals or parametrization in lang strings expressions .... (avoiding using get_string() parm injection that would change all calls to get_string() and all string related functions !!)

Thanks guys.... !!

Average of ratings: -
In reply to Valery Fremaux

Re: Questions about internal implementation of language resolution

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
There is no good reason. I tried really hard to get to the bottom of this some months ago when I was rewriting get_string in head, and no one could remember, and there is nothing in the tracker or CVS history, nor in Martin's memory. All we can say is that it has been like that since Moodle was first checked in to CVS.

However, I strongly recommend that you don't try to substitute words like course during get_string.

Instead, build this into the administrator's translation tool, but leave the format of the language files the same. I am sure that is simpler, and it will also avoid compromising the performance of get_string, which is quite important.
In reply to Tim Hunt

Re: Questions about internal implementation of language resolution

by Robert Brenstein -
Indeed. One has to keep in mind that brute force word replacement won't work for all languages.
In reply to Tim Hunt

Re: Questions about internal implementation of language resolution

by Valery Fremaux -

Hi Tim,

I experimented a local solution that is not a full satisfaction, but works for me as a customization.

I'm not sure this is adressing really perfromance as it is not much more than inserting some variables in the string as we often do.

I added a global $GLOBSTRING array in the game, globalized in get_string(), so very global key terms could be systematically adressed.

ex : $string['createnewcourse'] = 'Create new '.$GLOBSTRING['course'];

The global $GLOBSTRING[] array is loaded once within a wellknown language string that we are sure that it be loaded soon enough (*µ$\dL£# !!)  (I used local/lang/xx_utf8/local.php, but having to adress very soon in config a get_string there to be sure.... (ugly).

Work exactly as expected, that is, allowing to have a fast, 10 minutes work shift of the overall semantics of Moodle !! Exactly what we need for our customer adaptation....

Cheers and thanks to all for your thoughts.

In reply to Valery Fremaux

Re: Questions about internal implementation of language resolution

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
IMO the support for such massive "search & replace" feature should be part of the new language translation tool, using the standard _local language pack modification as a destination.
The use case is: into a search box, you would just type "course" (or "kurz" for example) and the list of all strings where "course" appears in the English or "kurz" in the Czech variant of the string would appear. After tweaking them, the new trasnaltion would be saved into the appropriate location.
In reply to David Mudrák

Re: Questions about internal implementation of language resolution

by Nicolas Martignoni -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Agreed. But we have to think of several declinations for the same term, e.g. in english:

  • course
  • courses
  • Course (notice the uppercase)
  • Courses
and in some other languages, like russian IIRC, it's much more intricated wink
In reply to Nicolas Martignoni

Re: Questions about internal implementation of language resolution

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
And there is the old debate about whether we can change the system to nicely handle sentences like

"There is 1 quiz attempt." / "There are 7 quiz attempts."

instead of the current cop-out of "Quiz attempts: 7".

I still have not seen anything better than sam (marshall's) proposal for how to do it. (Sorry, I don't have a link handy.)
In reply to Tim Hunt

Re: Questions about internal implementation of language resolution

by Helen Foster -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Here is Sam's proposal: MDL-12433. Please vote if you'd like it to be fixed.