Actually is not possible to provide localization to every module without patching them.
For menu is possible, for taxonomy only partially.
So I am exploring a clean system to use for insert translation support in every module.
Three requirements :
1. the module should work seamlessly also if localizer support is not present
2. should be open to other possible translation systems / solutions (i18n, tr, translate)
3. the patch should contain no reference to localizer module and must
delegate the translation implementation to an external module

I am implementing it in taxonomy module, because the actual solution break the compatibility
with other modules.
This implementation will be used as prototype for other modules.

It should work in this manner :
- defined one function taxonomy_translate($object_type, $object)
where
object_type could be : term or vocabulary
object is the array that contains an entire term or vocabulary attributes array
- inserted the translate_taxonomy whenever necessary
- the function taxonomy_translate implements an hook call :
module_invoke_all('taxonomy', 'translate', $object_type, $object);
that should return the translated object

Suggestions ?

Comments

Roberto Gerola’s picture

Version: 4.7.x-1.0 » 4.7.x-2.x-dev
Gábor Hojtsy’s picture

Ok, so we are talking about this patch.

As far as I see, this is not too friendly an approach performance-wise. You call your taxonomy_translate() functions is SQL result handling while cycles for example one-by-one for every row. Then taxonomy_translate() calls module_invoke_all(), which searches and invokes all possible modules with that hook implemented.

Possible actual problems I see from reviewing the code:
- module_invoke_all() does not allow for by reference parameter passing, so the $object will
not get modified
- You call hook_taxonomy('translate', $object_type, $object) functions in modules... Maybe
you intended to call/define a hook_translate()?

Roberto Gerola’s picture

>You call your taxonomy_translate() functions is SQL result handling while cycles for example one-by-one for every row.
Yes. This could be a performance problem.
I have inserted a little caching in the hook implementation, but there is one call a time to the db. Not efficient, I admit.
Other options ?
I don't think that modify db_rewite_sql capabilities will work. You don't have to translate in every circumstance.

>module_invoke_all() does not allow for by reference parameter passing, so the $object will not get modified
Declaring the function that provides translation in this manner :
function taxonomy_translate($object_type, &$object) {
module_invoke_all('taxonomy', 'translate', $object_type, $object);
}
It works.

>You call hook_taxonomy('translate', $object_type, $object) functions in modules...
> Maybe you intended to call/define a hook_translate()?
Good observation.
I'll try this approach.

Roberto Gerola’s picture

>You call hook_taxonomy('translate', $object_type, $object) functions in modules...
>Maybe you intended to call/define a hook_translate()?
But ... doing so I can have only one hook to respond to for every module and every object.
It is true that I can distinguish on which I am operating through object_name.
My idea was to have a translation hook for every module.Perhaps it isn't necessary.
Nevertheless I'll try this approach to see if it can work. It is more generic of my proposed solution
and perhaps better.

Roberto Gerola’s picture

> module_invoke_all() does not allow for by reference parameter
> passing, so the $object will not get modified

I have tried on a different installation (PHP 4) and it doesn't work.
I am not sure if it depends on my particular PHP version on my
development environment (Ubuntu), but it isn't an reliable solution.
I have to find a different approach.

Roberto Gerola’s picture

I have reworked my patch (see http://drupal.org/node/104403).
I am using an hook simply to be independent of my module, otherwise
I could eliminate the hook and integrate directly the call to my translation engine.

Roberto Gerola’s picture

Status: Active » Closed (fixed)