WPML
ステータス
解決済み
報告対象
WPML Multilingual CMS 4.6.4
関連するプラグイン/テーマ
The Events Calendar
トピックタグ
Compatibility

問題の概要

特定の状況において、WPMLThe Events Calendar (TEC)プラグインを併用した場合、カレンダーリンクの翻訳の処理に不一致が生じます。期待される翻訳済みの用語が表示される代わりに、例えば日付リンクが誤って(/?:month|monat|miesic|….)のように表示されます。

注記: この問題はすでに解決されているはずです。しかし、最近になって同様の報告がありました

回避策

続行する前に、必ずサイトの完全なバックアップを作成してください。


  • ユーザー > プロフィールに移動し、デフォルト言語をユーザー言語として設定します。

  • 設定 > パーマリンクに移動して再保存します。この操作で問題が解決する場合があります。

  • 解決しない場合は、functions.phpファイルに以下のコードを追加します。
    /*
    *  WPML Workaround for compsupp-6815
    */
    add_filter( 'tribe_rewrite_canonical_url', 'wpml_compsupp6815_resolve_missing_urls', 10, 3 );
    
    function wpml_compsupp6815_resolve_missing_urls( $resolved, $url, $object ) {
    
    	if ( class_exists('Sitepress') ) {
    		$wpml_default_lang = apply_filters('wpml_default_language', NULL );
    		$wpml_current_lang = apply_filters( 'wpml_current_language', NULL );
    		
    		// Let's register the calendar strings so we can translate and use in the workaround
    		if ($wpml_default_lang == $wpml_current_lang ) {
    			
    			$events_slug = $tec_options['eventsSlug'];	
    			$single_events_slug = $tec_options['singleEventSlug']; 
    			$tec_options = get_option('tribe_events_calendar_options');
    					
    			do_action( 'wpml_register_single_string', 'the-events-calendar', 'TEC Calendar Slugs: '.substr($events_slug, 0, 20), $events_slug);
    			do_action( 'wpml_register_single_string', 'the-events-calendar', 'TEC Calendar Slugs: '.substr($single_events_slug, 0, 20), $single_events_slug );
    			
    			foreach ($tec_options['tribeEnableViews'] as $calendar_string) {
    				do_action( 'wpml_register_single_string', 'the-events-calendar', 'TEC Calendar Slugs: '.substr($calendar_string, 0, 20), $calendar_string);
    			}
    		}
    
    		// Check if the URL is not resolved yet. If not, we will resolve it with the translated strings
    		if ( preg_match( '#/(/?:.+)#',  $resolved ) ) {
    
    			$resolved = preg_replace_callback( '#/(/?:.+?)#', function($matches) use ($url) {
    				$options = explode('|', trim($matches[0], '/(?:)'));
    				
    				$slug = $options[0];					
    
    				$translated_slug = apply_filters('wpml_translate_single_string', $slug , 'the-events-calendar', 'TEC Calendar Slugs: '.substr($slug, 0, 20) );
    
    				// Only apply the translation if the string already exists in the URL. If not, replace with the original. This may avoid possible 404 errors
    				if (in_array(strtolower($translated_slug), $options) && $translated_slug != '') {
    					$slug = $translated_slug;
    				} 
    
    				return '/' . $slug;
    
    			}, $resolved );
    			
    		}
    	}
    
        return $resolved;
    }
  • 再度設定 > パーマリンクに移動して再保存します。
  • その後、すべての言語のフロントエンドでパーマリンクがどのように機能するかを確認します。
  • 問題が解決しない場合は、未翻訳の文字列が残っている可能性があります。その場合は、WPML > 文字列翻訳に移動し、the-events-calendarテキストドメインとTEC Calendar Slugs: ****という名前の文字列を翻訳します。

すべての既知の問題 →