The support of i18n taxonomy localization is broken.

When checking the code i see that you're relying on old (possibly D6) namings.

function taxonomy_menu_translated_menu_link_alter(&$item, $map) {
  if (module_exists('i18ntaxonomy')) {
    // In case of localized terms, use term translation for menu title.

Note that as a starting point, i18ntaxonomy was renamed to i18n_taxonomy. And tt() has been renamed as announced in the 6.x release.
This needs rewrite and extensive testing. This feature seems to be missed completely in the D7 port?

Comments

dstol’s picture

futurist’s picture

Subscribing

berdir’s picture

Status: Active » Needs review
StatusFileSize
new4.82 KB

The attached patch fixes this.

Note that I also fixed a related problem that caused menu links to be saved in the wrong language. Previously, it only checked the node language and fell back to the current language. Now, it first checks if there is a term language. Without this, all menu links had the current language assigned instead of the actual term language (which is 'und' when it will be localized).

miro_dietiker’s picture

Status: Needs review » Needs work

There's at leas one strange indentation.

For the TODO i don't know what would be needed. At least it seems to me the $display_num currently doesn't work anymore.

if ($item['title'] != ($term->name . $display_num)) {

I think here $display_num should not be considered... The static item should be always without numbers. Am i wrong?

if ($item['title'] != $term->name) {

Please check with childterms.

berdir’s picture

$display_num depends on helper functions that don't exist anymore. It doesn't work without i18n either I think.

That's probably why the check is currently wrong, yes.

miro_dietiker’s picture

Which helper is no more available?

I still see _taxonomy_menu_children_has_nodes() and taxonomy_term_count_nodes() is also there...

However, strange thing is to see this inside a i18n_taxonomy check. This number adding should be clearly outside i18n related alter topics...

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new4.83 KB

Improved the comment to state why the block is commented out.

That part is being worked on in #1165386: Node Count for D7 Version (patch included)

Status: Needs review » Needs work

The last submitted patch, fix_i18n_integration_2.patch, failed testing.

miro_dietiker’s picture

Status: Needs work » Reviewed & tested by the community

Looks fine to me then.

dstol’s picture

I'll get this into 7.x tonight once I'm home. It would be great if there were some tests included with this, as I don't really know much about i18n. Oh and thanks Berdir, I really appreciate your help!

miro_dietiker’s picture

great to see this proceed.

dstol, note that we're using it already in production this way.

dstol’s picture

Status: Reviewed & tested by the community » Fixed

http://drupalcode.org/project/taxonomy_menu.git/commit/b07bfc7">Committed to 7.x-1.x-dev. Thank you!

healycn’s picture

subscribe

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

summit’s picture

Hi, Sorry to have to report that I think that in 7.1-dev the i18n support is still broken, see:

Trying to get property of non-object in taxonomy_menu_translated_menu_link_alter() (regel 1064 van sites/all/modules/taxonomy_menu/taxonomy_menu.module).
Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (regel 178 van includes/entity.inc).
Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->cacheGet() (regel 354 van includes/entity.inc).
Notice: Trying to get property of non-object in i18n_taxonomy_vocabulary_mode() (regel 1048 van sites/all/modules/i18n/i18n_taxonomy/i18n_taxonomy.module).
Notice: Trying to get property of non-object in taxonomy_menu_translated_menu_link_alter() (regel 1064 van sites/all/modules/taxonomy_menu/taxonomy_menu.module).
Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (regel 178 van includes/entity.inc).
Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->cacheGet() (regel 354 van includes/entity.inc).

If I am mistaken on my part, much apologize, but I use the latest .dev version with this patch added: http://drupal.org/files/new-options-1192084-5.patch.

Greetings,
Martijn

summit’s picture

Status: Closed (fixed) » Active

Hi set this to active again.
This code doesn;t work anymore in D7:

taxonomy_term_count_nodes

See also http://drupal.org/node/603868

greetings,
Martijn

vvs’s picture

#12 - it's working! Thanks!

summit’s picture

Hi @VVS, How can it work with you when

taxonomy_term_count_nodes

is no function in D7 anymore?

greetings, Martijn

planctus’s picture

It is working for me too with the dev version.
Thanks,
D.a

summit’s picture

Hi,
I changed
for the function taxonomy_term_count_nodes to taxonomy_menu_term_count_nodes:

function taxonomy_menu_term_count_nodes ($tid, $vid, $count = 0) {
  $count += _taxonomy_menu_term_count($tid);
  $children = taxonomy_get_children($tid, $vid);
  foreach ($children as $tid => $term) {
    $count = taxonomy_menu_term_count_nodes($term->tid, $term->vid, $count);
  }
  return $count;
}

But still the errors from http://drupal.org/node/1228294#comment-5259532
Greetings, Martijn

summit’s picture

Title: i18n support broken » i18n support broken taxonomy_menu_translated_menu_link_alter errors
StatusFileSize
new8.37 KB

Attached is my taxonomy_menu module with patches: http://drupal.org/files/new-options-1192084-5.patch, and http://drupal.org/files/issues/fix_i18n_integration_2.patch and the changed function from http://drupal.org/node/1228294#comment-5464936
I also updated i18n to latest version.

But still taxonomy_menu_translated_menu_link_alter errors:

Notice: Trying to get property of non-object in taxonomy_menu_translated_menu_link_alter() (regel 1072 van /sites/all/modules/taxonomy_menu/taxonomy_menu.module).
Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (regel 179 van /includes/entity.inc).
Notice: Trying to get property of non-object in taxonomy_menu_translated_menu_link_alter() (regel 1072 van /sites/all/modules/taxonomy_menu/taxonomy_menu.module).
Notice: Trying to get property of non-object in taxonomy_menu_translated_menu_link_alter() (regel 1072 van /sites/all/modules/taxonomy_menu/taxonomy_menu.module).
Notice: Trying to get property of non-object in taxonomy_menu_translated_menu_link_alter() (regel 1072 van /sites/all/modules/taxonomy_menu/taxonomy_menu.module).
Notice: Trying to get property of non-object in taxonomy_menu_translated_menu_link_alter() (regel 1072 van /sites/all/modules/taxonomy_menu/taxonomy_menu.module).
Notice: Trying to get property of non-object in taxonomy_menu_translated_menu_link_alter() (regel 1072 van /sites/all/modules/taxonomy_menu/taxonomy_menu.module).
Notice: Trying to get property of non-object in taxonomy_menu_translated_menu_link_alter() (regel 1072 van /sites/all/modules/taxonomy_menu/taxonomy_menu.module).
Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (regel 179 van /includes/entity.inc).
Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->cacheGet() (regel 355 van /includes/entity.inc).

The error is somewhere in:

1072:   if (i18n_taxonomy_vocabulary_mode($t->vid, I18N_MODE_LOCALIZE)) {

It has to do something with an empty value or an array I think, see: http://stackoverflow.com/questions/4798047/array-flipcan-only-flip-strin...

The function call itself looks ok, see: http://drupal.org/node/1123200#comment-4356314
May be needing an condition before it?
Thanks for going into this again!

Greetings, Martijn

dgastudio’s picture

Priority: Normal » Major

the problem is still present. any solution?

pieterdc’s picture

As @Summit states, the error is somewhere in that line of code.

If I replace if (i18n_taxonomy_vocabulary_mode($t->vid, I18N_MODE_LOCALIZE)) { with if ($t !== FALSE && i18n_taxonomy_vocabulary_mode($t->vid, I18N_MODE_LOCALIZE)) { the error doesn't show any more.

But I guess the real cause lies a little deeper:
In my case, the error was related to a taxonomy term with multiple parents... or maybe I just have some legacy data hanging around?

rondev’s picture

<?php
if ($t !== FALSE && i18n_taxonomy_vocabulary_mode($t->vid, I18N_MODE_LOCALIZE)) {
?>

I would test $t before as it may be 0 for stray/invalid items as I explained here #1483010: [i18n] Localized stray item generate "array_flip() [function.array-flip]..." and "Trying to get property of non-object" errors. Else i18n_taxonomy_vocabulary_mode generate errors.

vvs’s picture

Component: Sync or Update Issues » Sync

#18 - i18n support working.

planctus’s picture

I'm pretty confused about this, i guess i've patched taxonomy_menu in the past in order to make it work with localized terms, it was working indeed.
Now i had a problem with a menu where i was missing items languages so i ran into this issue again.
I've read the last comment saying it was working, downloaded the latest dev and gave it a try..
It is not working for me, the menu items are all "language undefined", and that is pretty blocking since it is a very large vocabulary so it would be very hard to do that manually...
I must say i dont' have errors on screen while generating the menu items, by the way.
Thanks,
Da.

planctus’s picture

Nobody answered, but the problem was there and it was quite trivial...
I'm not going to provide a patch, since the changes are really straightforward.

There is a typo at line 596 of taxonomy_menu.module, first:
if (module_exists('i18nmenu')) {
The module is called i18n_menu, instead.

Second, at line 788, function _taxonomy_menu_create_item($args = array(), $node) {
'language' => $node ? $node->language : $GLOBALS['language']->language,
It is unclear to me why $node has been used here...we have the taxonomy term object inside the $args parameter, it has already been set as $term, so we have to use $term->language instead of $node->language.

I made this changes and everything is working now.
Thanks,
Da.

dstol’s picture

@planctus, could you please provide a patch? The line numbers you give don't match up with the latest code in 7.x-1.x-dev or did you patch against 7.x-1.2?

planctus’s picture

Ok, i was working on the latest dev, i guess...so, i don't know why they don't match...
Da.

planctus’s picture

Well, i don't know exactly what version i was using, at this point, since both versions 7.x.1.x and 7.x.2.x already have the correct code.
So, no need for a patch, it is already fixed. But since this issue didn't ride on the problem i had i'm not closing it..
Thanks,
Da.

dstol’s picture

Status: Active » Fixed

Closing per planctus

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.