can I change block title depending on locale, for module-generated blocks?
I still can't get the way how localizerblock works at all - you can select one locale and the block will be shown only in that locale? Does it mean that I need to create 5 same blocks in different languages if I have 5 locales?
Sorry for stupid questions :)

Comments

Roberto Gerola’s picture

> Does it mean that I need to create 5 same blocks in different languages if I have 5 locales?
Exactly.

It works in a similar way as for nodes.
the only difference is that it isn't a relation between the block translations.

restyler’s picture

Does it mean that I can't change the title of, for example, 'user login' block?

Roberto Gerola’s picture

This is out of my control.
Have you tried to see if the title appears in the localization strings ?
It should be possible to provide a translation for it there.

restyler’s picture

StatusFileSize
new15 KB

In Drupal5 you have an option to change block header of any block, e.g. in admin/build/block/configure/user/0 you can override default title of 'User login' block. I was wondering if there is any way to localize this type of user input.

My next question: I've ported 'site_map' to D5 yesterday, and I've installed it on my website to show all site menus. I have 'ru' and 'eng' locales. My navigation menu is translated, but sitemap shows UNtrunslated menu titles and translated menu elements. I'm not sure why it is happening so, the code to create sitemap menu is:

function _site_map_menus() {
  if ($mids = variable_get('site_map_show_menus', array())) {
    $menu = menu_get_menu();
    foreach ($mids as $mid){
      $title = $menu['visible'][$mid]['title']; // <---- this remains untranslated
      $menu_display = _site_map_menu_tree($mid, $menu); // <----- translated
      $output .= theme('box', $title, $menu_display);
    }
  }

  return $output;
}

is it a problem of localizer or of a sitemap?

Roberto Gerola’s picture

The translation of menus is done through the hook_menu.
I suspect that _site_map_menu_tree($mid, $menu)
make an indirect call to this hook somewhere.

You could simply call the translation API for the title :
$translation = localizer_translatemenuitem($mid);
$title = $translation->title.

Let me know,

restyler’s picture

Thanks for your help.
I've fixed that by

if(module_exists('localizermenu')) {
    $translation = localizermenu_translatemenuitem($mid);
    $title = $translation['title'];
    } else {
     $title = $menu['visible'][$mid]['title'];
    } 

but I've tried to find the indirect call to hook_menu and I didn't find it... I can't understand why all menu elements are _translated_, and title is not.

restyler’s picture

Title: localizerblock: can I change block title depending on locale, for module-generated blocks? » localizerblock: it just doesn't work for me...

I've created a block, changed it locale to 'english'.. but I see it on russian locale too.
I've tried to debug localizerblock_db_rewrite_sql():

  $applylocalizer = ($primary_table=='blocks');

  if ($applylocalizer) {
    var_dump($query); <---- // I never see it... so no query rewriting at all
    $nodeslocales_assql = localizer_get_nodeslocales_assql();
    if($nodeslocales_assql) {
      $blid = "CONCAT(b.module,'-',b.delta,'-',b.theme)";
      $sql['join'] = "LEFT JOIN {localizerblock} loc ON loc.blid=$blid";
      $sql['where'] = "loc.locale IN (" . $nodeslocales_assql . ",'-') OR loc.locale IS NULL";
    }
  }
Roberto Gerola’s picture

See here : http://drupal.org/node/111738
The first patch didn't work properly.

restyler’s picture

I've patched block.module, now db rewriting works but multilingual blocks still are showed on all languages...
SQL that the rewriting function gets:

string(220) "SELECT DISTINCT b.* FROM {blocks} b LEFT JOIN {blocks_roles} r ON b.module = r.module AND b.delta = r.delta WHERE b.theme = '%s' AND b.status = 1 AND (r.rid IN (%s) OR r.rid IS NULL) ORDER BY b.region, b.weight, b.module"

returns:

array(2) {
  ["join"]=>
  string(83) "LEFT JOIN {localizerblock} loc ON loc.blid=CONCAT(b.module,'-',b.delta,'-',b.theme)"
  ["where"]=>
  string(46) "loc.locale IN ('en','-') OR loc.locale IS NULL"
}
Roberto Gerola’s picture

> multilingual blocks still are showed on all languages
What are multilingual blocks for you ?

Have you can see in the SQL localizer shows also the block without
a locale. Is this the problem ?

restyler’s picture

I've tried simple blocks, menu blocks... for simple user created blocks with 'eng' or 'ru' locale the localizerblock doesn't work at all. For menu blocks it works strange, it hides my website navigation on 'eng' locale, though I've set 'any' locale in block settings.

Roberto Gerola’s picture

> for simple user created blocks with 'eng' or 'ru' locale the localizerblock doesn't work at all.
Ok, it could be. There is another function to patch to filter also user blocks.

>For menu blocks it works strange, it hides my website navigation on 'eng' locale, though I've set 'any' locale in block settings.
Ok. I make some other tests.

restyler’s picture

I've rewritten localizerblock.module to work in 'localizervars way', I mean every block have multilingual title and block of 'block.module' (box) also have multilingual body. I had to patch block.module to make it work, so I'm not sure if anyone need it :) I'll test it a bit more and upload tomorrow as a patch.

Roberto Gerola’s picture

Very good ! Thank you !
Post it here or send it to me by email, so I can integrate it.

At now we have 4 "features" that share in some way the same interface
for translation : variables, menus, taxonomy (to be modified) and blocks.

Your proposal to use the localizertranslation table to translate blocks is
a very good idea ! So we can avoid of storing multiple blocks in the database.

I'm not worried about the patch.
Taxonomy module has been patched a lot to work.

If possible we should use the same logic used in taxonomy.module to patch also block module,
with the use of the tobject method.

restyler’s picture

http://russianwebstudio.com/other/localizerblock-5.x-0.1-dev.rar

I've attached my version of block.module and patch against cvs version.

restyler’s picture

I'm not sure that this version of loc_blocks module can completely replace the old one. May be someone needs to hide some block on some locale, but I think he can use i18n_get_lang() in 'Page specific visibility settings' (Show if the following PHP code returns TRUE (PHP-mode, experts only).) + my version of loc_blocks to override titles and box bodies

Roberto Gerola’s picture

>i18n_get_lang()
You shouldn't use this function.
It is called only to determine the language on the first access.

Use instead localizer_get_nodedefaultlocale();

I need to make some changes to your patch.
We can use the tobject function.

It seems to me that the patch is reversed.
The code to add is reported to delete.
Am I wrong ?

restyler’s picture

StatusFileSize
new5.42 KB

>i18n_get_lang()
You shouldn't use this function.
It is called only to determine the language on the first access.

Use instead localizer_get_nodedefaultlocale();

Ok. In this case I need to change loc_profile and loc_vars too

It seems to me that the patch is reversed.
The code to add is reported to delete.
Am I wrong ?

Yes you are right :) I've attached correct patch

restyler’s picture

StatusFileSize
new5.42 KB

>i18n_get_lang()
You shouldn't use this function.
It is called only to determine the language on the first access.

Use instead localizer_get_nodedefaultlocale();

Ok. In this case I need to change loc_profile and loc_vars too

It seems to me that the patch is reversed.
The code to add is reported to delete.
Am I wrong ?

Yes you are right :) I've attached correct patch

restyler’s picture

oops, double post. The last post has correct patch

Roberto Gerola’s picture

> Use instead localizer_get_nodedefaultlocale();
I'm renaming this API, but don't mind, when I'll integrate your code
I'll change it.

It will become : localizer_get_contentdefaultlocale();

It is more correct, because it has to do with the content, and
not only with the nodes.
So we have uilocale and contentlocale in the methods.

Roberto Gerola’s picture

Your localizerblock implementation works for users provided blocks but not
for blocks provided by other modules as, for example, by menus.
I think I must add also this second feature,
as it was in my first implementation.

I see also the need to define a good and coherent interface user
for the translations.
Actually we have a mixed approach from you solutions, my original solution
and Ray's work.

It is correct that changing the language by the switching block is it possible
to translate the entries in variables, menu, taxonomy, block.
Probably it is the most user-friendly approach and it simplify the interface,
so I think I can remove my fieldsets and follow your example.

The only missing thing is a message to the user : "You are on the English/German/Russian/Italian version".
I'll put it in the description on the field at now.

I've decided to not change the naming scheme, at now.
The renaming is only postponed.
There is already a lot of work to do for the next release, and
naming conventions have an impact also on the db tables
names, as localizernode, localizeruser.
I prefer to be sure at 100% of the solution before changing
names everywhere.

restyler’s picture

Mm, it works for me, I've tested it on block.module boxes and my website navigation menu.

I'm not sure that this approach will be ok for menu items - pretend that you need to translate 20 menu items on 4 languages.. huge amount of page reloads.
But, if we implement some kind of 'translation console' for mass translations, it would be ok.