Vai al contenuto Vai alla barra laterale

Waiting for author

Topic Tags: Compatibility

Overview of the issue

When using MapPress with WPML, you might experience that Points of Interest (POI) such as cities saved to a map are not translated. This is because the POI strings are stored based on the language used during their creation and are not automatically available for translation.

Workaround

Please, make sure of having a full site backup of your site before proceeding.

  • Add the following code to your theme’s functions.php file.
    // WPML Workaround for compsupp-4265: Translate Mappress POI fields
    if ( class_exists('Sitepress') ) { 
    
    	add_action('mappress_map_save', 'my_mappress_register_poi_strings');
    	function my_mappress_register_poi_strings($map) {
    
    		$fields = array('address','title','name','body');
    		if (empty($map->mapid) || empty($map->pois) || !is_array($map->pois))
    			return;
    
    		foreach ($map->pois as $i => $poi) {
    			foreach ($fields as $field) {
    				if (isset($poi->$field) && $poi->$field !== '') {
    					$key = "map_{$map->mapid}_poi_{$i}_{$field}";
    					do_action( 'wpml_register_single_string','mappress', $key, $poi->$field );
    				}
    			}
    		}
    	}
    
    	add_action('mappress_map_display', 'my_mappress_translate_poi_fields');
    	function my_mappress_translate_poi_fields($map) {
    
    		$fields = array('address','title','name','body');
    		if (empty($map->mapid) || empty($map->pois) || !is_array($map->pois))
    			return;
    
    		foreach ($map->pois as $i => $poi) {
    			foreach ($fields as $field) {
    				if (isset($poi->$field) && $poi->$field !== '') {
    					$key = "map_{$map->mapid}_poi_{$i}_{$field}";
    					$translated = apply_filters('wpml_translate_single_string', $poi->$field, 'mappress', $key);
    					$poi->$field = $translated;
    				}
    			}
    		}
    	}
    	
    }
            
  • Resave your Maps in “MapPress > Maps”.
  • Go to “WPML > String Translation” and translate the strings under the ‘mappress’ domain

Lascia una risposta

Per favore rimani in tema e sii rispettoso verso gli altri. Se hai bisogno di aiuto con problemi non relativi a questo post, usa il nostro Forum di Supporto per iniziare una chat o inviare un ticket.

Puoi usare questi tag:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>