Localize countries in Dropbox

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

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #10003178
    Avatar
    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.

    #10003188
    Avatar
    Pie Register
    Participant

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

    Thanks

    #10003588
    Avatar
    evani2003
    Participant

    Hey,

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

    Thank you!

    Eva

    #10003592
    Avatar
    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.

    #10003608
    Avatar
    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;
    }

    🙂

    #10003609
    Avatar
    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)

The forum ‘Installation’ is closed to new topics and replies.

Checkout
0
PURCHASE NOW