• Resolved dezemberundjuli

    (@dezemberundjuli)


    Hi there

    Does someone implement this plugin on a multilang website? I try to do it with wpml. Some solutins to set the text in two languages?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Schweizer Solutions GmbH

    (@schweizersolutions)

    Hey, the next version will support WPML.

    If it is urgent, you can install the support yourself as follows:

    1. Go to this folder on your WordPress installation: /wp-content/plugins/opt-out-for-google-analytics/
    2. Create a new file: wpml-config.xml
    3. Insert this code into this file:

    <wpml-config>
        <admin-texts>
            <key name="_gaoo_link_deactivate"/>
            <key name="_gaoo_link_activate"/>
            <key name="_gaoo_popup_deactivate"/>
            <key name="_gaoo_popup_activate"/>
        </admin-texts>
    </wpml-config>

    4. Don’t forget to save the file 😉

    Regards Andreas

    Hey Andreas

    Thank you for posting the solution. I did the stetps 1-4, but what’s to do next?
    Where can I put the translations?

    Plugin Author Schweizer Solutions GmbH

    (@schweizersolutions)

    Hi, you have to use the WPML String Translation. There you can search for the key name like _gaoo_link_deactivate and translate it.

    Ok, that make sense. And if I use WPML with Loco Translate for strings? Because the WPML String Translation plugin is sooo slow…

    Special Configuration, I know 😉

    Plugin Author Schweizer Solutions GmbH

    (@schweizersolutions)

    As far as I know, “Loco Translate” does not offer any possibility to translate the contents of the database 😉

    Ok. I did this jQuery to get it work for me:

    /* ----------------------------------------------------------------------------------------------------------------------------- */
        /* Übersetzen des Google Analytics Links auf der Datenschutzseite (=page-id-7730) */
       
        // Text nach dem Laden umschreiben:
        $('.page-id-7730 .gaoo-link-deactivate').html('Disable Google Analytics');
        $('.page-id-7730 .gaoo-link-activate').html('Enable Google Analytics');
        
        // Funktion 'gaoo_handle_optout' nach dem Laden umschreiben, nur auf der englischsprachigen Seite:
        if ( $('.page-id-7730').length ) {
            window.gaoo_handle_optout = function() {
        		var data = {"link_deactivate":"Disable Google Analytics","link_activate":"Enable Google Analytics","popup_activate":"Tracking is now enabled. Click the link again to disable it.","popup_deactivate":"Tracking is now disabled. Click the link again to activate it."}
        		var disableStr = 'ga-disable-SET-YOUR-GOOGLE-ANALYTICS-CODE-HERE';
        
        		if (document.cookie.indexOf(disableStr + '=true') > -1) {
        			document.cookie = disableStr + '=; expires=Thu, 01 Jan 1970 00:00:01 UTC; path=/';
        			window[disableStr] = false;
        
        		  		if (data.hasOwnProperty('popup_activate')) {
        		    		alert(data.popup_activate);
        		  		}
        
        		  		var link = document.getElementById('gaoo-link');
        		  		
        		  		link.innerHTML = data.link_deactivate;
        		  		link.className = link.className.replace(/\b-activate\b/,'-deactivate');
        		}
        		else {
        		 	document.cookie = disableStr + '=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/';
        		  		window[disableStr] = true;
        
        		  		if (data.hasOwnProperty('popup_deactivate')) {
        		    		alert(data.popup_deactivate);
        		  		}
        
        			var link = document.getElementById('gaoo-link');
        		  		
        		  		link.innerHTML = data.link_activate;
        		  		link.className = link.className.replace(/\b-deactivate\b/,'-activate');
        		}
                origHelloWorld(argument);   // after your code if you want to call original function 
            }
            
        }
    Plugin Author Schweizer Solutions GmbH

    (@schweizersolutions)

    Hey @dezemberundjuli,

    thank you for sharing your solution! But you can use our filters, to translate it.
    It is not necessary to modify the JavaScript code. With your change you will have problems with the updates. For example, we have revised the JavaScript code in the new version.

    Please use this code instead. You can paste the code into your functions.php from your child theme.

    /**
     * Translate the strings from the plugin "Google Analytics Opt-Out (DSGVO / GDPR)"
     *
     * @param string $type
     * @param string $fallback  Fallback text if no translation found. (Default: empty string)
     * @param null|int $post_id ID of the post or null, to take the current post. (Default: null)
     *
     * @return string Translated string.
     */
    function gaoo_get_translation( $type, $fallback = '', $post_id = null ) {
    	if ( empty( $post_id ) ) {
    		global $post;
    		$post_id = $post->ID;
    	}
    
    	$translations = array(
    		2   => array( // set the post id, where this translation should work.
    			'link_activate'    => 'Allow Google Analytics to track me',
    			'link_deactivate'  => 'Prohibit Google Analytics from following me',
    			'popup_activate'   => 'Tracking is now activated. Click the link again to disable it.',
    			'popup_deactivate' => 'Tracking is now disabled. Click the link again to activate it.',
    		),
    		322 => array( // set the post id, where this translation should work.
    			'link_activate'    => 'Permitir que Google Analytics me rastree',
    			'link_deactivate'  => 'Prohibir que Google Analytics me siga',
    			'popup_activate'   => 'El rastreo está ahora activado. Haga clic de nuevo en el enlace para desactivarlo.',
    			'popup_deactivate' => 'El rastreo está desactivado. Haga clic de nuevo en el enlace para activarlo.',
    		),
    		// ... one post per language and you can translate it here ...
    	);
    
    	if ( empty( $post_id ) || empty( $type ) || ! isset( $translations[ $post_id ] ) || ! isset( $translations[ $post_id ][ $type ] ) ) {
    		return $fallback;
    	}
    
    	return $translations[ $post_id ][ $type ];
    }
    
    function gaoo_link_deactivate_text( $text ) {
    	return gaoo_get_translation( 'link_deactivate', $text );
    }
    
    function gaoo_link_activate_text( $text ) {
    	return gaoo_get_translation( 'link_activate', $text );
    }
    
    function gaoo_popup_activate_text( $text ) {
    	return gaoo_get_translation( 'popup_activate', $text );
    }
    
    function gaoo_popup_deactivate_text( $text ) {
    	return gaoo_get_translation( 'popup_deactivate', $text );
    }
    
    add_filter( 'gaoo_link_deactivate_text', 'gaoo_link_deactivate_text' );
    add_filter( 'gaoo_link_activate_text', 'gaoo_link_activate_text' );
    add_filter( 'gaoo_popup_deactivate_text', 'gaoo_popup_deactivate_text' );
    add_filter( 'gaoo_popup_activate_text', 'gaoo_popup_activate_text' );

    Yes, thats much better 🙂 Thank you very much for sharing this code!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Multilang’ is closed to new replies.