This is a dead simple patch to support in-place editing translation implementation in contrib modules. The idea is that we need a list of strings used on the page to provide a jQuery interface to aid people to translate stuff seen on the page. Two simple changes required:

- let locale() return the list of strings used on the page (in the internal static cache) => made $strings allow NULL, in which case we return the cache
- make locale() NOT to use the short string cache if need be, so we can have an exact list of strings used on the page => introduced locale_cache_short_strings variable with intentionally no UI

The idea is that a contrib module could do the following:

- in hook_boot() or hook_init() set the locale_cache_short_strings variable to zero
- in hook_exit(), collect the strings used by calling locale()
- output a JSON data structure of all strings used
- add a JS file to the page which implements an in-place translation interface

This way if that module is disabled (site in production), the dangerously disabled short string cache will be restored. I also made sure to add some warning messages to the documentation of the new variable.

This simple patch opens the door for a much wanted feature in contrib, which was on several people's agendas before.

CommentFileSizeAuthor
locale_return.patch1.99 KBGábor Hojtsy
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Gábor Hojtsy’s picture

István Palócz pointed it out to me that this is also useful for performance tailoring on sites. A module can also watch for often used strings and modify the locale cache to include more often used (but not short) strings and exclude short but not often used strings. This can be tailored to the actual site at hand *automatically*. The working mechanism is the same. The measurement period would see decreased performance with locale module, but after that the site could have a measurement of what is used most and can tailor the cache accordingly.

moshe weitzman’s picture

looks simple and proper to me. i think you are suggesting that modules set this variable in $GLOBALS['conf'] and not with variable_set() so it has no persistence. great idea. if you wanted to be super safe, you could add a warning on status report if that variable is disabled. thats not a requirement, IMO.

Gábor Hojtsy’s picture

Absolutely, I would not recommend setting it permanently. I also imagined using the status page, but I think this type of notification should be handled by the module implementing this setting change, not core.

Gábor Hojtsy’s picture

Status: Needs review » Fixed

OK, modified the variable to say locale_cache_strings as comment #1 indicates here that the cache could be any string set now. Committed.

Anonymous’s picture

Status: Fixed » Closed (fixed)