WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i have a list of countries in french stored in my database (wp_country). i use the code above to retrieve all the countries witth this ecohing echo '"' . $country['name_country'] . '",'; it outputs countries in this format "France", "Afrique du sud", "italie", and so. the reason i output countries between brackets followed by comma, is that i want theme inpusted in a javascript autocomplete variable : var availableCountries = [//countries list from wp_country ?> ].

My probleme is how to translate the outputed countries with the translate functions __() or _e()


global $wpdb;  

    $sql_countries = $wpdb->prepare("SELECT id, name_country  FROM country ORDER            BY name_country ASC");
    $result_countries = mysql_query($sql_countries); 

    while($country = mysql_fetch_array($result_countries)) { 

        echo '"' . $country['name_country'] . '",'; 


thank you

share|improve this question

you need to have the actual translations somewhere in a .mo file. for your plugin / theme.

1) when you setup the codes, you can also "mark them for translation" http://codex.wordpress.org/I18n_for_WordPress_Developers#Marking_Strings_for_Translation

2) create the translations for the languages somehow - various tools. eg this one: http://wordpress.org/extend/plugins/codestyling-localization/

3) in your plugin must tell wp to load the translation 'domain' http://codex.wordpress.org/I18n_for_WordPress_Developers#Choosing_and_loading_a_domain

4) then to get the translation reference the domain in the call

__('String', 'your_domain')

Note: There are various 'country' or multi language plugins that may have country translations already - try searching the wp plugins db. You could 'copy' their .mo and .po files if you did not want their plugin active. (you'd use their domain if you were not copying).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.