Skip Navigation

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

Our next available supporter will start replying to tickets in about 3.63 hours from now. Thank you for your understanding.

This topic contains 4 replies, has 2 voices.

Last updated by souhilH-2 4 years, 6 months ago.

Assisted by: Bruno.

Author Posts
May 9, 2020 at 4:43 am #6093013

souhilH-2

My site primary lang is English

Secondary is french and Arabic too

Please Check the screenshot....There is added checkout cities field in function.php file. we need to translate the cities filed Arabic too. how can i make it ?
so the visitor for Arabic will see in Arabic cities name

Screenshot_107.png
Screenshot_106.png
May 11, 2020 at 4:37 pm #6105757

Bruno

Thank you for contacting us. To translate strings, you must make them translatable using WordPress __() function: https://developer.wordpress.org/reference/functions/__/. For example:

$cites = array(
  __('city 1', 'your-domain'),
  __('city 2', 'your-domain'),
  __('city 3', 'your-domain'),
);

Please, let me know if I can help with any other questions you may have about it. I'll be happy to help.

Thank you.

May 12, 2020 at 10:08 am #6111271

souhilH-2

Sorry I didn't get it,,
Can you explain a bit more ? Here is full code of function.php file of which needs to translate it Arabic version too..Only the cities name. ...Note that, English is default, Secondary are french and Arabic

And this is from Child themes' function.php file

/**
* Change the checkout city field to a dropdown field.
*/
function ace_change_city_to_dropdown( $fields ) {

$cities = array(
'Adrar',
'Chlef',
'Laghouat',
'Oum El Bouaghi',
'Batna',
'Béjaïa',
'Biskra',
'Béchar',
'Blida',
'Bouira',
'Tamanrasset',
'Tébessa',
'Tlemcen',
'Tiaret',
'Tizi Ouzou',
'Alger',
'Djelfa',
'Jijel',
'Sétif',
'Saïda',
'Skikda',
'Sidi Bel Abbès',
'Annaba',
'Guelma',
'Constantine',
'Médéa',
'Mostaganem',
"M'Sila",
'Mascara',
'Ouargla',
'Oran',
'El Bayadh',
'Illizi',
'Bordj Bou Arreridj',
'Boumerdès',
'El Tarf',
'Tindouf',
'Tissemsilt',
'El Oued',
'Khenchela',
'Souk Ahras',
'Tipaza',
'Mila',
'Aïn Defla',
'Naâma',
'Aïn Témouchent',
'Ghardaïa',
'Relizane',
// etc
);

$city_args = wp_parse_args( array(
'type' => 'select',
'options' => array_combine( $cities, $cities ),
'input_class' => array(
'wc-enhanced-select',
)
), $fields['shipping']['shipping_city'] );

$fields['shipping']['shipping_city'] = $city_args;
$fields['billing']['billing_city'] = $city_args;

wc_enqueue_js( "
jQuery( ':input.wc-enhanced-select' ).filter( ':not(.enhanced)' ).each( function() {
var select2_args = { minimumResultsForSearch: 5 };
jQuery( this ).select2( select2_args ).addClass( 'enhanced' );
});"
);

return $fields;

}
add_filter( 'woocommerce_checkout_fields', 'ace_change_city_to_dropdown' );

function filter_rest_allow_anonymous_comments() {
return true;
}
add_filter('rest_allow_anonymous_comments','filter_rest_allow_anonymous_comments');

May 12, 2020 at 3:27 pm #6114515

Bruno

You will need to wrap the strings in some function that allows you to translate them. You can see the official WordPress documentation: https://developer.wordpress.org/themes/functionality/internationalization/

Here is a small example (note the __() functions):

/**
* Change the checkout city field to a dropdown field.
*/
function ace_change_city_to_dropdown( $fields ) {

  $cities = array(
  __( 'Adrar', 'your-domain' ),
  __( 'Chlef', 'your-domain' ),
  ...

In WPML > Theme and plugins localization, you can scan your plugin or theme (where this code is) and then translate them using String Translation.

Please, let me know if I can help with any other questions you may have about it. I'll be happy to help.

Thank you.