Translation support for variables like : mission, footer, and so on

Comments

restyler’s picture

Title: Support for variables » Support for variables: trying to use localizer_get_objstrs()
Version: 4.7.x-1.0 » 5.x-1.x-dev
Category: feature » bug
StatusFileSize
new898 bytes

I'm creating localizervars.module to get site variables translated.
I'm using localizer d5 v1.6
Function localizer_get_objstrs() doesn't work, and it seems to me that no modules use it.
Is it the correct function to get all 'variable' objects from `localizertranslation` by one db query ?

I've fixed the function and now I think it works like it _should_ work, though I'm not 100% sure :)

Roberto Gerola’s picture

Thank you very much.

But which version are you using ?
Can I ask you to use the latest cvs version for writing patches ?

The code in your patch has been already changed.
It seems to me that the code patched is a bit old.

Download from the cvs the sources with the tag DRUPAL-5,
if you want to contribute.

Thanks again.

Roberto Gerola’s picture

For a variable, because we have to translate only its value, it would be sufficient to use :
localizer_get_objfieldtr($object_name, $object_key, $object_field, $locale)
or
function localizer_get_currobjfieldtr($object_name, $object_key, $object_field)
to read the value in the current locale.

The variables are stored in global variable $conf.
We need also a configuration section where to specify which variables
need to be translated.

Thanks

restyler’s picture

Thank you for fast reply.
localizer_get_objfieldtr() is the function that can get only one variable. I don't want to overload the db by these unnecessary queries, so I think it will be a good idea to use simple
$result = db_query("SELECT * FROM {localizertranslation} WHERE object_name = 'variable' AND locale='%s'", $locale);

I need the localizervars.module really urgently, that's why I was going to take the i18n way of variable translation interface... do you have any other ideas?

restyler’s picture

Status: Active » Reviewed & tested by the community
StatusFileSize
new925 bytes

patch to fix localizer_get_objstrs(), against cvs version.
I'm not sure if I should change the status of the thread, but I'll do that..

restyler’s picture

Title: Support for variables: trying to use localizer_get_objstrs() » Support for variables: new module, localizervars.module

Here is the alpha version. Roberto, I hope you can check it and tell if everything is in the 'right' way :)

http://russianwebstudio.com/other/localizervars-5.x-0.1-dev.zip

Roberto Gerola’s picture

Thank you very much for your effort.

I'll take a look to you code during the next weekend and hope to be able to integrate it
very soon.

I have to check the cvs because the function you are patching it seems to me
a bit old. I'll try to download the sources again from the cvs and I'll verify
they match with my development version.

This is the last cvs version of localizer.module file for branch DRUPAL-5
http://cvs.drupal.org/viewcvs/drupal/contributions/modules/localizer/loc...

As you can see the definition of the function has been already corrected some time ago

function localizer_get_objstrs($object_name, $object_keys) {
  $translations = array();

  // skip empty requests
  if (empty($object_keys)) {
    return $translations;
  }

  $string_keys = "'" . implode("','", $object_keys) . "'";

  // get translations
  $result = db_query("SELECT * FROM {localizertranslation} WHERE object_name = '%s' AND object_key IN (%s)", $object_name, $string_keys);
  while ($tr = db_fetch_object($result)) {
    $translations[$tr->object_id][$tr->locale][$tr->object_field] = $tr->translation;
  }

  // or an array of translation sets for multiple items
  return $translations;
}
Roberto Gerola’s picture

I have taken a deeper look to your code for variables support.
It is a very good start point. Thanks.

As user I don't like to specify the variables to translate
in the settings.php.

I think that perhaps the best solution would be to prepare a translation
interface similar to that used for menus.
I mean, something like this : http://www.speedtech.it/files/images/localizer_menuitem.png
but implemented in the general settings page.

I would like also to integrate the proposal of Ray for this type of translation interfaces :
http://drupal.org/node/111773

I think we have to subsitute the init hook with the menu hook, otherwise
we could encounter some errors on some installations.
Take a look here :
http://api.drupal.org/api/4.7/function/hook_init

This hook is already present in localizermodule.
I'll add you code there, so we have an unique place
where all the initializations have effect.

Let me know what do you think !

restyler’s picture

I think that perhaps the best solution would be to prepare a translation
interface similar to that used for menus.
I mean, something like this : http://www.speedtech.it/files/images/localizer_menuitem.png
but implemented in the general settings page.

I think it will make the settings page really huge.. and you'll need to check variables size/type to generate translation fields.

I think we have to subsitute the init hook with the menu hook, otherwise
we could encounter some errors on some installations.
Take a look here :
http://api.drupal.org/api/4.7/function/hook_init

Yes, I think it's a good idea. The Drupal caching way just seems a bit vague for me.. that's why I've tried to make it simpler ;)

As user I don't like to specify the variables to translate
in the settings.php.

May be you can suggest better way? I think it's the most flexible way for now. You can't append controls to each variable to enable/disable variable translation... there is the way to let user insert variables list somewhere in localizer settings, but he needs to know variable names, at least.

Roberto Gerola’s picture

>I think it will make the settings page really huge.. and you'll need to check variables size/type to generate translation fields.

Yes the size/type would be hardcoded, but also the variable on settings page are fixed and hardcoded.
Simply a fieldset collapsed.
The best way would be to have a tabbed interfaces.

>May be you can suggest better way? I think it's the most flexible way for now.
Yes. An interface under localizer settings where the user can select which variable he/she want to translate.
And also a generic management console where the user can manage all the translations of all the variables,
menus, taxonomy and so on.

restyler’s picture

StatusFileSize
new23.08 KB

I think that this approach is a bit better than approach with collapsible fields

Roberto Gerola’s picture

Yes, absolutely.
It should work like the switching block.

I'll take a look at the Forms API to see what we can do.

Roberto Gerola’s picture

I've taken a look also to Ray patch for menu.
It goes in the same direction you propose : switch language and you can insert the translated strings.

So, I think that I'll follow this way.
It simplify the interface a lot and reduce the confusion for the user.

We can work on the menu input filed on node page in the same manner :
"overriding the input field".

Roberto Gerola’s picture

Category: bug » task
Roberto Gerola’s picture

Status: Reviewed & tested by the community » Closed (fixed)