Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Multilang filter: Difference between revisions

From MoodleDocs
No edit summary
No edit summary
Line 14: Line 14:
Second, base md5 key not on the filtered text but on the original text passed to format_text() function.
Second, base md5 key not on the filtered text but on the original text passed to format_text() function.


These two combined should provide unique key values and catch all text and language changes.
These two combined should provide unique key values and catch all text and language changes while allowing the cache to function as expected.


In case dual behavior needs to be maintained, for example, to bypass caching when another filter is called, or to avoid any unexpected side-effects of this change, an extra parameter to format_text() function can be added, initialized as default to NULL, for example, so if it is NULL, the current behavior remains in effect. It would be then up to the caller to activate the alternative behavior (more than one could actually be possible).
In case dual behavior needs to be maintained, for example, to bypass caching when another filter is called, or to avoid any unexpected side-effects of this change, an extra parameter to format_text() function can be added, initialized as default to NULL, for example, so if it is NULL, the current behavior remains in effect. It would be then up to the caller to activate the alternative behavior (more than one could actually be possible).


A variant of this would be to add a twin function, format_text2() or format_text_multi() or else, which would be called in place of the standard one when the modified behavior is needed.
A variant of this would be to add a twin function, format_text2() or format_text_multi() or else, which would be called in place of the standard one when the modified behavior is needed.

Revision as of 23:07, 27 March 2006

Currently the multilang filter breaks the cache system. The "lang" concept should be included in the mechanism to be able to cache contents when such filter is enabled.


Written by Robert Brenstein:

I am not a proper Moodle developer, so I may be missing something very obvious, but since I was forced to occupy myself with functioning of format_text() function recently, I have also pondered the problem of caching multilang strings.

My interpretation of current setup is that multilang disables caching because the md5 key used by in the format_text() to identify cached entries is based on the text of cached items. In the case of filtered items, the text is changed by the filter called in the middle of format_text(), so the correct key cannot be ascerned upon entry to format_text(), that is before the text was processed by the filter. Catch 22 so to speak.

An approach to change this could be:

First, add language code to md5 key calculation in addition to all the $option parms that were recently added.

Second, base md5 key not on the filtered text but on the original text passed to format_text() function.

These two combined should provide unique key values and catch all text and language changes while allowing the cache to function as expected.

In case dual behavior needs to be maintained, for example, to bypass caching when another filter is called, or to avoid any unexpected side-effects of this change, an extra parameter to format_text() function can be added, initialized as default to NULL, for example, so if it is NULL, the current behavior remains in effect. It would be then up to the caller to activate the alternative behavior (more than one could actually be possible).

A variant of this would be to add a twin function, format_text2() or format_text_multi() or else, which would be called in place of the standard one when the modified behavior is needed.