콘텐츠로 건너뛰기 사이드바로 건너뛰기

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

답글 남기기

주제에 집중하고 다른 사람을 존중해 주세요. 이 게시물과 관련 없는 문제에 도움이 필요하면 지원 포럼을 사용하여 채팅을 시작하거나 티켓을 제출하세요.

다음 태그를 사용할 수 있습니다:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>