WPML
상태
개발자 대기 중
관련 플러그인/테마
Pro
주제 태그
Compatibility

문제 개요

WPML과 함께 Pro 테마를 사용할 때, Cornerstone 빌더에서 생성된 단일 및 아카이브 레이아웃과 같은 레이아웃 템플릿은 WPML 번역 에디터를 통해 번역이 불가능합니다. 이는 Cornerstone이 레이아웃 렌더링을 처리하는 방식이 표준 포스트 유형과 다르기 때문입니다.

임시 해결 방법

옵션 1 – 템플릿 수동 번역

Cornerstone 에디터 상단에 있는 내장 Cornerstone 번역 전환기를 사용하세요. 이를 통해 레이아웃을 보조 언어로 복제하고 수동으로 번역할 수 있습니다.

  • Cornerstone 빌더를 사용하여 레이아웃을 편집하세요.
  • 빌더 인터페이스 상단에서 언어 전환기를 찾으세요.
  • 번역할 언어를 선택하세요.
  • 레이아웃 에디터에 번역된 텍스트를 수동으로 입력하세요.

참조: https://theme.co/forum/t/not-possible-is-it-possible-to-translate-wc-single-layouts-with-wpml/112916/7

옵션 2 – functions.php의 사용자 정의 코드


계속 진행하기 전에 사이트의 전체 사이트 백업을 생성했는지 확인하세요.

  • 테마의 functions.php 파일에 다음 코드를 추가하세요.
    /**
     * WPML Workaround for compsupp-8255 
     */
    
    // 1. Register strings when saving Layout posts.
     
    add_action( 'save_post', function( $post_id, $post, $update ) {
    
    	if ( wp_is_post_revision( $post_id ) || ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) ) {
    		return;
    	}
    
    	$pt = get_post_type( $post_id );
    	$post = get_post( $post_id );
    	$slug = $post->post_name;
    
    	$layout_types = [ 'cs_layout_single', 'cs_layout_archive', 'cs_layout_single_wc', 'cs_layout_archive_wc' ];
    
    	// If the site uses other cs_layout_* types, widen this check:
    	// if ( strpos( $pt, 'cs_layout_' ) !== 0 ) return;
    	if ( ! in_array( $pt, $layout_types, true ) ) {
    		return;
    	}
    
    	// Only if WPML String Translation is present.
    	if ( ! has_action( 'wpml_register_single_string' ) ) {
    		return;
    	}
    
    	$data = json_decode( (string) $post->post_content, true );
    	if ( ! is_array( $data ) ) {
    		return;
    	}
    
    	$items   = cs_wpml_cs_collect_text_content( $data ); // [ path => original_text ]
    	$context = 'cornerstone-layout-' . $slug;
    
    	foreach ( $items as $path => $original ) {
    		// Includes a short hash to avoid collisions and keep it semi-readable in ST.
    		$hash = substr( md5( $path . '|' . $original ), 0, 10 );
    		$name = $path . ' #' . $hash;
    
    		do_action( 'wpml_register_single_string', $context, $name, $original );
    	}
    
    }, 10, 3 );
    
    
    // 2. Replace strings on load for Layout documents.
    
    add_filter( 'cs_layout_load_content', function( $post_content ) {
    
    	if ( ! has_filter( 'wpml_translate_single_string' ) ) {
    		return $post_content;
    	}
    
    	$data = json_decode( (string) $post_content, true );
    	if ( ! is_array( $data ) ) {
    		return $post_content;
    	}
    
    	$context = 'cornerstone-layout-' . $slug;
    
    	$data = cs_wpml_cs_translate_text_content( $data, $context );
    
    	return wp_json_encode( $data );
    
    }, 10, 1 );
    
    
    // Collect ONLY 'text_content' strings
    
    function cs_wpml_cs_collect_text_content( array $data ) : array {
    	$out = [];
    
    	$walk = function( $node, $path ) use ( &$walk, &$out ) {
    
    		if ( is_array( $node ) ) {
    			foreach ( $node as $k => $v ) {
    
    				$new_path = ( $path === '' ) ? (string) $k : $path . '.' . $k;
    
    				if ( in_array( $k, [ 'text_content', 'counter_before_content', 'counter_after_content' ], true ) && is_string( $v ) ) {
    
    					// Skip Dynamic Content tokens like {{dc:...}} or {{ acf... }}
    					if ( strpos( $v, '{{' ) === false ) {
    						$out[ $new_path ] = $v;
    					}
    					continue;
    				}
    
    				if ( is_array( $v ) ) {
    					$walk( $v, $new_path );
    				}
    			}
    		}
    	};
    
    	$walk( $data, '' );
    	return $out;
    }
    
    
    // Translate ONLY 'text_content' strings.
    
    function cs_wpml_cs_translate_text_content( array $data, string $context ) : array {
    
    	$walk = function( $node, $path ) use ( &$walk, $context ) {
    
    		if ( is_array( $node ) ) {
    			foreach ( $node as $k => $v ) {
    
    				$new_path = ( $path === '' ) ? (string) $k : $path . '.' . $k;
    
    				if ( in_array( $k, [ 'text_content', 'counter_before_content', 'counter_after_content' ], true ) && is_string( $v ) ) {
    
    					// Skip Dynamic Content tokens like {{...}}
    					if ( strpos( $v, '{{' ) === false ) {
    
    						$hash = substr( md5( $new_path . '|' . $v ), 0, 10 );
    						$name = $new_path . ' #' . $hash;
    
    						$node[ $k ] = apply_filters( 'wpml_translate_single_string', $v, $context, $name );
    					}
    
    					continue;
    				}
    
    				if ( is_array( $v ) ) {
    					$node[ $k ] = $walk( $v, $new_path );
    				}
    			}
    		}
    
    		return $node;
    	};
    
    	return $walk( $data, '' );
    }
            

  • Cornerstone 에디터에서 레이아웃을 다시 저장하세요.
  • WPML > 문자열 번역으로 이동하여 cornerstone-layout 도메인을 검색하세요.
  • 문구를 번역하세요.
  • Cornerstone > 설정으로 이동하여 캐시를 지우세요.
참고:
레이아웃에 사용된 위젯에 따라 'cs_wpml_cs_collect_text_content''cs_wpml_cs_translate_text_content' 두 함수 모두에서 키 목록을 확장해야 할 수도 있습니다('toggle_anchor_text_primary_content', 'card_front_text_content', 'card_back_text_content' 등의 키 추가).

알려진 모든 문제 →