• 1- get translation from default language
    [wp_translate domain=”woovina”]Subscribe[/wp_translate]
    2- shortcode to use plugin translation features
    [wpm_translate][:ar]??? ?????????[:en]LATEST BLOG POST[:fr]DERNIERS ARTICLES DE BLOG[:][/wpm_translate]
    {{{#!php
    <?php
    namespace WPM\Includes;

    if ( ! defined( ‘ABSPATH’ ) ) {
    exit; // Exit if accessed directly
    }

    /**
    * ShortCodes
    *
    * Class WPM_Shortcodes
    * @package WPM\Includes
    */
    class WPM_Shortcodes {

    /**
    * WPM_Shortcodes constructor.
    */
    public function __construct() {
    add_shortcode( ‘wpm_lang_switcher’, array( $this, ‘language_switcher’ ) );
    add_shortcode( ‘wp_translate’, array( $this,’WP_Translate_shortcode’) );
    add_shortcode( ‘wpm_translate’, array( $this,’wpm_translate_string_shortcode’ ));
    }

    /**
    * Language switcher html
    *
    * @param $atts
    *
    * @return string
    */
    public function language_switcher( $atts ) {

    $atts = shortcode_atts( array(
    ‘type’ => ‘list’,
    ‘show’ => ‘both’
    ), $atts );

    return wpm_get_language_switcher( $atts[‘type’], $atts[‘show’] );
    }

    /**
    * Language get translate string form default language
    *
    * @param $atts
    *
    * @return string
    */

    public function WP_Translate_shortcode( $atts, $content = null ) {
    extract(shortcode_atts( array(
    ‘domain’ => ‘default’,
    ), $atts ));
    return __($content,$domain);
    //return esc_html(wpm_translate_string($content));
    }

    /**
    * wpm_translate_string bu shortcode
    *
    * @param $atts
    *
    * @return string
    */

    public function wpm_translate_string_shortcode( $atts, $content = null ) {
    extract(shortcode_atts( array(
    ‘domain’ => ‘default’,
    ), $atts ));

    return wpm_translate_string($content);
    }

    }

    }}}

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter fethienv

    (@fethienv)

    Full code

    <?php
    namespace WPM\Includes;
    
    if ( ! defined( 'ABSPATH' ) ) {
    	exit; // Exit if accessed directly
    }
    
    /**
     * ShortCodes
     *
     * Class WPM_Shortcodes
     * @package WPM\Includes
     */
    class WPM_Shortcodes {
    
    	/** 
    	 * WPM_Shortcodes constructor.
    	 */
    	public function __construct() {
    		add_shortcode( 'wpm_lang_switcher', array( $this, 'language_switcher' ) );
                    add_shortcode( 'wp_translate', array( $this,'WP_Translate_shortcode') );
                    add_shortcode( 'wpm_translate', array( $this,'wpm_translate_string_shortcode' ));
    	}
    
    	/**
    	 * Language switcher html
    	 *
    	 * @param $atts
    	 *
    	 * @return string
    	 */
    	public function language_switcher( $atts ) {
    
    		$atts = shortcode_atts( array(
    			'type' => 'list',
    			'show' => 'both'
    		), $atts );
    
    		return wpm_get_language_switcher( $atts['type'], $atts['show'] );
    	}
            
            /**
    	 * Language get translate string form default language
    	 *
    	 * @param $atts
    	 *
    	 * @return string
    	 */
            
            public function WP_Translate_shortcode( $atts, $content = null ) {
                   extract(shortcode_atts( array(
                                                  'domain' => 'default',
                                                 ), $atts ));
                   return __($content,$domain);
                   //return esc_html(wpm_translate_string($content));
            }
            
            /**
    	 * wpm_translate_string bu shortcode
    	 *
    	 * @param $atts
    	 *
    	 * @return string
    	 */
            
            public function wpm_translate_string_shortcode( $atts, $content = null ) {
                   extract(shortcode_atts( array(
                                                  'domain' => 'default',
                                                 ), $atts ));
    
                   return wpm_translate_string($content);
            }
    
    }
    Thread Starter fethienv

    (@fethienv)

    How to use:

    1- get translation from default language
    [wp_translate domain=”woovina”]Subscribe[/wp_translate]
    2- shortcode to use plugin translation features
    [wpm_translate][:ar]??? ?????????[:en]LATEST BLOG POST[:fr]DERNIERS ARTICLES DE BLOG[:][/wpm_translate]

    Very interesting code.

    I tried pasting your above code into a snippet, using “Code Snippets” Plugin and I get this error message:
    The code snippet you are trying to save produced a fatal error on line 13:
    Cannot declare class WPM\Includes\WPM_Shortcodes, because the name is already in use

    Thread Starter fethienv

    (@fethienv)

    Hi
    Just replace the content of this file in WP Multilang
    includes/class-wpm-shortcodes.php

    Thread Starter fethienv

    (@fethienv)

    I added:

    add_shortcode( 'wp_translate', array( $this,'WP_Translate_shortcode') );
                    add_shortcode( 'wpm_translate', array( $this,'wpm_translate_string_shortcode' ));

    in
    public function __construct()

    and these 2 functions

    /**
    	 * Language get translate string form default language
    	 *
    	 * @param $atts string 
             * @param $content string
    	 *
    	 * @return string
    	 */
            
            public function WP_Translate_shortcode( $atts, $content = null ) {
                   extract(shortcode_atts( array(
                                                  'domain' => 'default',
                                                 ), $atts ));
                   return __($content,$domain);
                   //return esc_html(wpm_translate_string($content));
            }
            
            /**
    	 * wpm_translate_string shortcode
    	 *
    	 * @param $atts
    	 *
    	 * @return string
    	 */
            
            public function wpm_translate_string_shortcode( $atts, $content = null ) {
                   extract(shortcode_atts( array(
                                                  'domain' => 'default',
                                                 ), $atts ));
    
                   return wpm_translate_string($content);
            }

    @fethienv Oh OK.
    Thank you. I understand now. Your contribution is very much appreciated.
    Will you post it at github to make sure it stays in?
    https://github.com/VaLeXaR/wp-multilang/

    Salutations,

    Thread Starter fethienv

    (@fethienv)

    Thank you @fethienv
    Very much appreciated.
    Regards,

    Hello @fethienv ,

    I have updated WP multilang plugin shortcode file with your updated code.

    But still short code is not working, it is still displaying text with shortcode in front like this…

    [wpm_translate][:en]Call Us[:da]Ring til os[:][/wpm_translate] 50782831

    Any help?

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