Localize countries in Dropbox

Home Forums Installation Localize countries in Dropbox

This topic contains 5 replies, has 3 voices, and was last updated by  toemmy 3 years, 4 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #3178

    toemmy
    Participant

    Hi,

    Pie Register is a really great plugin.
    I am about to translate it to german. At least the frontend textes.
    Is there a possibility to translate the country dropdown box in the address section of registration form?
    There are Strings for all Countries in the .po File, but translating them has only an effect in the backend, when choosing the default language, not in frontend.

    Any hint would be appreciated.

    Thanks in advance,
    Toemmy.

    #3188

    PIE REGISTER
    Keymaster

    Yes, you can translate all text including the country list using PO/MO file.

    Thanks

    #3588

    evani2003
    Participant

    Hey,

    I have the same problem. How did you solve it?

    Thank you!

    Eva

    #3592

    toemmy
    Participant

    Hi Eva,

    unfortunately there isn’t an easy solution without making some modifications to the plugin code.
    I checked the Plugin Files and the countries aren’t translated in other languages before they are displayed in the dropdown box.
    So I had to add some code to the plugin myself (registration_form.php, around line 450).

    The way I did it was going through the $countries array and translating every entry to the given language:

    
    $countries_t = array();
    for($i=0; $i<sizeof($countries); $i++){
     $ct = __($countries[$i], "piereg");
     array_push($countries_t, $ct);
    }
    sort($countries_t);
    $countries = $countries_t;
    

    Of course it makes sense to put this code in an hook, so you don’t have to rewrite the whole code again after a plugin update. And you still have to translate the country strings in the .po files.

    Hope I could help.

    Cheers,
    Toemmy.

    #3608

    evani2003
    Participant

    Thank you a thousand times!

    My boyfriend helped to optimize it. Use this code instead of yours in your functions.php and you will have no worries about updating:

    add_filter( 'option_pie_countries', 'eva_translate_countries_option' );
    
    function eva_translate_countries_option ( $countries ) {
    	
    	$countries_t = array();
    	for($i=0; $i<sizeof($countries); $i++){
     		$ct = __($countries[$i], "piereg");
     		array_push($countries_t, $ct);
    	}
    	sort($countries_t);
    	$countries = $countries_t;
    				
    	return $countries;
    }

    🙂

    #3609

    toemmy
    Participant

    Very nice! Thanks a lot!
    I didn’t notice that I could add the filter to get_option directly.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.