From 56491693a4240ab3faa2f44e7198f8be00354d0f Mon Sep 17 00:00:00 2001
From: Pol Dell'Aiera <Pol@47194.no-reply.drupal.org>
Date: Mon, 17 Oct 2011 13:28:44 +0200
Subject: [PATCH 2/2] 1312074: Sort exposed translated filters by their value

---
 i18nviews.module |   27 +++++++++++++++++++++++++++
 1 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/i18nviews.module b/i18nviews.module
index ce0740b..a47186b 100644
--- a/i18nviews.module
+++ b/i18nviews.module
@@ -211,3 +211,30 @@ function i18nviews_views_ui_edit_display_submit($form, &$form_state) {
     }
   }
 }
+
+/**
+ * Implementation of hook_form_alter().
+ */
+function i18nviews_form_alter(&$form, &$form_state, $form_id) {
+
+  if ($form_id != 'views_exposed_form')
+    return;
+
+  foreach (element_children($form) as $key) {
+    if (!preg_match('/^tid/', $key) && !preg_match('/^term_node_tid_depth/', $key)) continue;
+
+    uasort($form[$key]['#options'], '_i18nviews_option_value_compare');
+
+    if ($form[$key]['#options']['All']) {
+      $all = array('All' => $form[$key]['#options']['All']);
+      unset($form[$key]['#options']['All']);
+      $form[$key]['#options'] = $all + $form[$key]['#options'];
+    }
+  }
+}
+
+function _i18nviews_option_value_compare(&$a, &$b) {
+  if (is_object($a) && is_object($b)) {
+    return strnatcmp(reset(array_values($a->option)), reset(array_values($b->option)));
+  }
+}
\ No newline at end of file
-- 
1.7.3.4

