Passer au contenu Passer à la barre latérale

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

Laisser une réponse

Veuillez rester sur le sujet et être respectueux envers les autres. Si vous avez besoin d'aide pour des problèmes non liés à ce message, utilisez notre Forum de Support pour démarrer une discussion ou soumettre un ticket.

Vous pouvez utiliser ces balises :
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>