Saltar al contenido Saltar a la barra lateral

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

Dejar una respuesta

Por favor, mantente en el tema y sé respetuoso con los demás. Si necesitas ayuda con problemas no relacionados con esta publicación, utiliza nuestro Foro de Soporte para iniciar un chat o enviar un ticket.

Puedes usar estas etiquetas:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>