How can I have the listing address format different in each language?

First of all, here’s an article that explains to you how to display the elements that you need on the address part.

This article will explain how to have this structure different depending on different languages. For example, let’s continue the example from the other side. Let’s say that for default we’ll display the city, the country and the street (in this order), for the French language we’ll display the country first, the city and the street and for Deutsch, we’ll have the city, the street and, finally, the country. In this case, this is the code that we’ll use for default:

<span class="address__city" itemprop="addressLocality">{geolocation_city}</span>
<span class="address__country-short" itemprop="addressCountry">{geolocation_country_short}</span>
<span class="address__street">{geolocation_street}</span>

This is the code for French:

<span class="address__country-short" itemprop="addressCountry">{geolocation_country_short}</span>
<span class="address__city" itemprop="addressLocality">{geolocation_city}</span>
<span class="address__street">{geolocation_street}</span>

And for the Deutsch part:

<span class="address__city" itemprop="addressLocality">{geolocation_city}</span>
<span class="address__street">{geolocation_street}</span>
<span class="address__country-short" itemprop="addressCountry">{geolocation_country_short}</span>

The wrapper part is the same one (as presented in the other article) but there are two new elements for the two additional languages:

function my_custom_listing_address ( $formats ) {
$formats = array(
'default' => '',
‘fr_FR’ => ‘’,
‘de_DE’ => ‘’) ;
return $formats;
}
add_filter( 'listable_localisation_address_formats', 'my_custom_listing_address', 15 ) ;

Now, the final step is to put all those parts in just one place, like this:

function my_custom_listing_address($formats) {
$formats = array(
'default' => '<span class="address__city" itemprop="addressLocality">{geolocation_city}</span>
<span class="address__country-short" itemprop="addressCountry">{geolocation_country_short}</span>
<span class="address__street">{geolocation_street}</span>’,
‘fr_FR’ => ‘<span class="address__country-short" itemprop="addressCountry">{geolocation_country_short}</span>
<span class="address__city" itemprop="addressLocality">{geolocation_city}</span>
<span class="address__street">{geolocation_street}</span>’,
‘de_DE’ => ‘<span class="address__city" itemprop="addressLocality">{geolocation_city}</span>
<span class="address__street">{geolocation_street}</span>
<span class="address__country-short" itemprop="addressCountry">{geolocation_country_short}</span>’);
return $formats;
}
add_filter('listable_localisation_address_formats', 'my_custom_listing_address', 15);

You can find the locale for all the languages right here, on the WP_Locale column. We had a look here when we took the de_DE and fr_FR parts for our languages.

This should be all. Just give it a try and let us know if there anything comes up.

Updated on May 31, 2017

Was this article helpful?

Related Articles