The function i18n_taxonomy_term_get_translations() in it's current state only returns the term of which the term id is given as an argument. Instead of loading one term, the function should return all terms belonging to the translation set of the i18n_tsid given as an argument.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

skilip’s picture

Status: Active » Needs review
FileSize
2.05 KB
skilip’s picture

Issue tags: +di18nscb
Berdir’s picture

Status: Needs review » Needs work
+++ b/i18n_taxonomy/i18n_taxonomy.moduleundefined
@@ -722,33 +722,31 @@ function i18n_taxonomy_form_all_localize(&$item) {
+  if (is_numeric($i18n_tsid) && $i18n_tsid) {

That check is IMHO unecessary. It's a required argument and you pass in an invalid argument, bad things will happen. That's true for most drupal API functions. Also, is_numeric() actually allows things like "-123e12" so you can still pass in invalid stuff if you really want to.

+++ b/i18n_taxonomy/i18n_taxonomy.moduleundefined
@@ -722,33 +722,31 @@ function i18n_taxonomy_form_all_localize(&$item) {
+      $result = db_select('taxonomy_term_data', 'td')
+        ->fields('td', array('tid', 'name', 'vid', 'language'))
+        ->condition('td.i18n_tsid', $i18n_tsid)

Only use db_select if you have to (dynamic queries, node access, ...) because it is slower than db_query().

+++ b/i18n_taxonomy/i18n_taxonomy.moduleundefined
@@ -722,33 +722,31 @@ function i18n_taxonomy_form_all_localize(&$item) {
+      foreach ($result as $term) {
+        $translations[$i18n_tsid][$term->language] = $term;

Can be written as:

$translations[$i18n_tsid] = $query->fetchAllAssoc('language');

Powered by Dreditor.

skilip’s picture

Status: Needs work » Needs review
FileSize
1.89 KB

Thanks for the review!

Berdir’s picture

Status: Needs review » Needs work
+++ b/i18n_taxonomy/i18n_taxonomy.moduleundefined
@@ -722,33 +722,25 @@ function i18n_taxonomy_form_all_localize(&$item) {
+    $translations = array(
+      $i18n_tsid => db_query($sql, array(':i18n_tsid' => $i18n_tsid))->fetchAllAssoc('language'),

This means that you re-create the complete array every time so the static cache is pretty much useless. You need "$translations[$i18n_tsid] = ... ".

Powered by Dreditor.

skilip’s picture

You're right

skilip’s picture

Status: Needs work » Needs review
skilip’s picture

Forgot to remove dpm()

Berdir’s picture

Yes, this looks good now.

Just wondering, is this function never actually used anywhere in the i18n project?

skilip’s picture

Formerly it was used in i18n_taxonomy_translate_terms, which is indeed not used anymore. However we're working on a patch which adds a 'translation' tab to term edit pages in which this function is needed: #1155238: Create translation tabs for terms

Berdir’s picture

Status: Needs review » Reviewed & tested by the community

Ok great, then let's get this in :)

Jose Reyero’s picture

Status: Reviewed & tested by the community » Fixed

We may later use translation set functions (i18n_translation) for this, but anyway, better to have a working api function than a broken one.

Committed, thanks.

Jose Reyero’s picture

Status: Fixed » Closed (fixed)

Keeping our list clean.

skilip’s picture

Status: Closed (fixed) » Needs work

Just discovered that the function i18n_taxonomy_term_get_translations() can be replaced by i18n_translation_set_load(). Will create a patch for it later on. Sorry for inconvenience.

skilip’s picture

Status: Needs work » Needs review
FileSize
1.07 KB
Jose Reyero’s picture

Status: Needs review » Needs work

Yes, sorry I had missed that too.

Anyway, for this function, I think we should re-purpose it to work just as translation_node_get_translations() taking a tid argument, or a full term object, which I think could be handy for other functions here, as you could iterate over the resulting array, etc.. http://api.drupal.org/api/drupal/modules--translation--translation.modul...

Btw, there's also i18n_taxonomy_translation_set_load(), which is the one to be used here, it is mostly a specific wrapper for taxonomy.

skilip’s picture

Can't we just delete i18n_taxonomy_term_get_translations? The function isn't used anywhere anymore

skilip’s picture

Status: Needs work » Needs review
FileSize
2.46 KB

This patch removes usage of the function i18n_taxonomy_term_get_translations() and replaces it with i18n_translation_set_load().

webflo’s picture

Good cleanup. Thx committed in 4e9f16c

webflo’s picture

Status: Needs review » Fixed

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