WPML
Stato
Risolto
Segnalato per
WPML Multilingual CMS 4.6.4
Plugin/tema correlato
The Events Calendar
Tag dell’argomento
Compatibility

Panoramica del problema

In alcune situazioni, si verifica una discrepanza nella gestione delle traduzioni dei link del calendario nel plugin The Events Calendar (TEC) quando utilizzato con WPML. Invece di visualizzare il termine tradotto atteso, il link della data appare erroneamente come (/?:month|monat|miesic|….), ad esempio.

Nota: Questo problema dovrebbe essere stato risolto. Tuttavia, abbiamo ricevuto una segnalazione simile di recente.

Soluzione alternativa

Assicurati di avere un backup completo del tuo sito prima di procedere.


  • Vai su Utenti > Il tuo profilo e imposta la tua lingua predefinita come lingua dell’utente.

  • Vai su Impostazioni > Permalink e salva di nuovo. A volte questa azione risolve il problema.

  • In caso contrario, aggiungi il seguente codice al tuo file 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;
    }
  • Vai su Impostazioni > Permalink e salva nuovamente.
  • Dopodiché, controlla come funzionano i permalink sul front-end per ogni lingua.
  • Se il problema persiste, potresti avere ancora alcune stringhe non tradotte. In tal caso, vai su WPML > Traduzione stringhe e traduci le stringhe con il textdomain the-events-calendar e il nome TEC Calendar Slugs: ****.

Tutti i problemi noti →