woothemes/woocommerce — Issue #212: State names not translated in checkout form
Author: brocheafoin
Created: 2011-11-17 02:23:09+00:00
State: open

I'm running WooCommerce for a shop located in Canada, doing business in French. We found a good enough French translation for the plugin, which we augmented and amended. Our translations for state names are not showing up on the check-out form, though.

Here's what I've found:

1. The states menu is JavaScript-generated.
2. Its labels come from the woocommerce_params JS object, which is created by the wp_localize_script.
3. wp_localize_script is called at line 265 of woocommerce.php, with the following variables:

```php
/* Script variables */
$woocommerce_params = array(
'currency_symbol'	=> get_woocommerce_currency_symbol(),
'currency_pos'	=> get_option('woocommerce_currency_pos'),
'countries'	=> json_encode($woocommerce->countries->states),
'select_state_text'	=> __('Select a state…', 'woothemes'),
'state_text'	=> __('state', 'woothemes'),
'plugin_url'	=> $woocommerce->plugin_url(),
'ajax_url'	=> admin_url('admin-ajax.php'),
'get_variation_nonce'	=> wp_create_nonce("get-variation"),
'add_to_cart_nonce'	=> wp_create_nonce("add-to-cart"),
'update_order_review_nonce'	=> wp_create_nonce("update-order-review"),
'update_shipping_method_nonce'	=> wp_create_nonce("update-shipping-method"),
'option_guest_checkout'	=> get_option('woocommerce_enable_guest_checkout'),
'checkout_url'	=> admin_url('admin-ajax.php?action=woocommerce-checkout'),
'option_ajax_add_to_cart'	=> get_option('woocommerce_enable_ajax_add_to_cart')
);
```

4. $woocommerce->countries->states is set in classes/countries.class.php, starting at line 264:

```php
var $states = array(
'AU' => array(
'ACT' => 'Australian Capital Territory' ,
'NSW' => 'New South Wales' ,
'NT' => 'Northern Territory' ,
'QLD' => 'Queensland' ,
'SA' => 'South Australia' ,
'TAS' => 'Tasmania' ,
'VIC' => 'Victoria' ,
'WA' => 'Western Australia'
),
'CA' => array(
'AB' => 'Alberta' ,
'BC' => 'British Columbia' ,
'MB' => 'Manitoba' ,
'NB' => 'New Brunswick' ,
```
As you can see, none of these strings are being passed through __() before being json_encoded. Therefore, they show up in English no matter what.

Is there any reason why country and state names aren't passed through __() inside the countries.class.php file?

Thanks in advance!