diff --git a/uc_store/uc_store.admin.inc b/uc_store/uc_store.admin.inc index d75161a..0d35772 100644 --- a/uc_store/uc_store.admin.inc +++ b/uc_store/uc_store.admin.inc @@ -381,7 +381,12 @@ function uc_store_configuration_page() { * @ingroup forms */ function uc_country_import_form($form, &$form_state) { - $countries = db_query("SELECT * FROM {uc_countries} ORDER BY country_name ASC")->fetchAll(); + $countries = array(); + $result = db_query("SELECT * FROM {uc_countries}"); + foreach ($result as $country) { + $countries[t($country->country_name)] = $country; + } + uksort($countries, 'strnatcasecmp'); $files = _uc_country_import_list(); $header = array(t('Country'), t('Code'), t('Version'), t('Operations')); @@ -389,7 +394,7 @@ function uc_country_import_form($form, &$form_state) { if (is_array($countries)) { foreach ($countries as $country) { $row = array( - $country->country_name, + t($country->country_name), $country->country_iso_code_3, array('data' => abs($country->version), 'align' => 'center') ); @@ -514,7 +519,12 @@ function uc_country_formats_form($form, &$form_state) { '#suffix' => '

' . t('Adding _if to any country variable will make it display only for addresses whose country is different than the default store country.') . '

', ); - $countries = db_query("SELECT * FROM {uc_countries} ORDER BY country_name ASC")->fetchAll(); + $countries = array(); + $result = db_query("SELECT * FROM {uc_countries}"); + foreach ($result as $country) { + $countries[t($country->country_name)] = $country; + } + uksort($countries, 'strnatcasecmp'); if (is_array($countries)) { $form['countries'] = array( @@ -524,12 +534,12 @@ function uc_country_formats_form($form, &$form_state) { foreach ($countries as $country) { $form['countries'][$country->country_id] = array( '#type' => 'fieldset', - '#title' => $country->country_name, + '#title' => t($country->country_name), '#group' => 'country', ); $form['countries'][$country->country_id]['address_format'] = array( '#type' => 'textarea', - '#title' => t('@country address format', array('@country' => $country->country_name)), + '#title' => t('@country address format', array('@country' => t($country->country_name))), '#default_value' => variable_get('uc_address_format_' . $country->country_id, ''), '#description' => t('Use the variables mentioned in the instructions to format an address for this country.'), '#rows' => 6, @@ -912,10 +922,10 @@ function uc_country_disable($country_id) { )) ->condition('country_id', $country_id) ->execute(); - drupal_set_message(t('!country disabled.', array('!country' => $country->country_name))); + drupal_set_message(t('!country disabled.', array('!country' => t($country->country_name)))); } else { - drupal_set_message(t('!country is already disabled.', array('!country' => $country->country_name)), 'error'); + drupal_set_message(t('!country is already disabled.', array('!country' => t($country->country_name))), 'error'); } } else { @@ -940,10 +950,10 @@ function uc_country_enable($country_id) { )) ->condition('country_id', $country_id) ->execute(); - drupal_set_message(t('@country enabled.', array('@country' => $country->country_name))); + drupal_set_message(t('@country enabled.', array('@country' => t($country->country_name)))); } else { - drupal_set_message(t('@country is already enabled.', array('@country' => $country->country_name)), 'error'); + drupal_set_message(t('@country is already enabled.', array('@country' => t($country->country_name))), 'error'); } } else { @@ -963,7 +973,7 @@ function uc_country_enable($country_id) { */ function uc_country_remove_form($form, &$form_state, $country_id) { // Fetch the country name from the database. - $country = db_query("SELECT country_name FROM {uc_countries} WHERE country_id = :id", array(':id' => $country_id))->fetchField(); + $country = t(db_query("SELECT country_name FROM {uc_countries} WHERE country_id = :id", array(':id' => $country_id))->fetchField()); // If orders exist for this country, show a warning message prior to removal. if (isset($form_state['triggering_element']) && $form_state['triggering_element']['#value'] != t('Remove') && module_exists('uc_order')) { @@ -1012,7 +1022,7 @@ function uc_country_remove_form_submit($form, &$form_state) { } } - drupal_set_message(t('!country removed.', array('!country' => $country->country_name))); + drupal_set_message(t('!country removed.', array('!country' => t($country->country_name)))); drupal_goto('admin/store/settings/countries'); } diff --git a/uc_store/uc_store.module b/uc_store/uc_store.module index f10e9d7..730c36a 100644 --- a/uc_store/uc_store.module +++ b/uc_store/uc_store.module @@ -302,6 +302,9 @@ function uc_store_process_address_field($element, $form_state) { switch ($base_field) { case 'country': $countries = db_query("SELECT country_id, country_name FROM {uc_countries} WHERE version > :version", array(':version' => 0))->fetchAllKeyed(); + foreach ($countries as $country_id => $country_name) { + $countries[$country_id] = t($country_name); + } natcasesort($countries); $subelement = array( @@ -1123,13 +1126,13 @@ function uc_address_format($first_name, $last_name, $company, $street1, $street2 '!zone_code' => $zone_data['zone_code'], '!zone_name' => $zone_data['zone_name'], '!postal_code' => check_plain($postal_code), - '!country_name' => $country_data['country_name'], + '!country_name' => t($country_data['country_name']), '!country_code2' => $country_data['country_iso_code_2'], '!country_code3' => $country_data['country_iso_code_3'], ); if (uc_store_default_country() != $country) { - $variables['!country_name_if'] = $country_data['country_name']; + $variables['!country_name_if'] = t($country_data['country_name']); $variables['!country_code2_if'] = $country_data['country_iso_code_2']; $variables['!country_code3_if'] = $country_data['country_iso_code_3']; } @@ -1354,8 +1357,9 @@ function uc_zone_option_list() { $result = db_query("SELECT z.*, c.country_name FROM {uc_zones} AS z LEFT JOIN {uc_countries} AS c ON z.zone_country_id = c.country_id ORDER BY c.country_name, z.zone_name"); foreach ($result as $zone) { - $options[$zone->country_name][$zone->zone_id] = $zone->zone_name; + $options[t($zone->country_name)][$zone->zone_id] = $zone->zone_name; } + uksort($options, 'strnatcasecmp'); return $options; } @@ -1411,11 +1415,12 @@ function uc_country_select($title, $default = NULL, $options = array()) { $countries = array(); foreach ($result as $country) { - $countries[$country->country_id] = $country->$order_by; + $countries[$country->country_id] = ($order_by == 'country_name') ? t($country->$order_by) : $country->$order_by; } if (empty($countries)) { $countries[] = t('No countries found.'); } + natcasesort($countries); if (!$default || !isset($countries[$default])) { $default = uc_store_default_country(); @@ -1459,15 +1464,16 @@ function uc_country_ajax_zone($form, &$form_state) { * Returns a list of available countries. */ function uc_country_option_list() { - $result = db_query("SELECT * FROM {uc_countries} WHERE version > :version ORDER BY country_name", array(':version' => 0)); + $result = db_query("SELECT * FROM {uc_countries} WHERE version > :version", array(':version' => 0)); $options = array(); while ($country = $result->fetchAssoc()) { - $options[$country['country_id']] = $country['country_name']; + $options[$country['country_id']] = t($country['country_name']); } if (count($options) == 0) { $options[] = t('No countries found.'); } + natcasesort($options); return $options; } @@ -1952,7 +1958,7 @@ function uc_store_default_country() { $result = db_query("SELECT COUNT(*) FROM {uc_countries} WHERE country_id = :id AND version > :version", array(':id' => $default, ':version' => 0))->fetchField(); if ($result == 0) { - $default = db_query_range("SELECT country_id FROM {uc_countries} WHERE version > :version ORDER BY country_name", 0, 1, array(':version' => 0))->fetchField(); + $default = db_query_range("SELECT country_id FROM {uc_countries} WHERE version > :version", 0, 1, array(':version' => 0))->fetchField(); } return $default;