WordPress.org

Forums

Stella plugin
Nice and Easy Plug-in (1 post)

  1. bloodico
    Member
    Posted 1 year ago #

    Nice plug-in, but not properly for beginners as you will have to dig into the code a little bit, especially as:
    1. If you can nicely localize labels from menus, you can not localize URLs from links item in a menu (-> have to code it)
    2. The WordPress + Themes Core are not translated !! Just the content of the posts are.... Sad, again have to code it or am I missing something ? (Need the localized .mo file in the wp-content/languages/ and themes languages folder, of course)
    3. I saw that you have support for WPSEO, so I also added support for AMT (Add Meta Tags plugin) which I find light and better than WPSEO for Meta, Open Graph, Twitter cards....
    4. Why these ugly letters in the menu instead of flags ?? At least offer a custom field in the admin page to add the Url of a png image for each language (like domain_path/flag-EN, domain_path/flag-DE, domain_path/flag-RU...)
    5. The next/previous posts link is broken on category/tags pages as it is updated afterwards by wordpress core

    As I love Stella and its price, here are the code to apply in the source files to make Stella the best and most simple WordPress Multi-lingual plugin !

    Solution for 1., 2. & 3.

    Here are the lines I did add in classes/class-post-localizer.php :
    Added in start of Post_localizer :

    add_filter('wp_nav_menu_objects', array($this, 'change_menu'), 1, 1);
    add_filter( 'locale', array($this, 'wpse_52419_change_language'), 1, 1 );
    if ( defined('AMT_DIR') ) {add_filter( 'amt_metadata_head', array($this, 'localize_AMT_metatag'), 1, 1 ); }

    The related functions, are after the localize_wpseo_title function :

    // Function to localize description Meta Tags from Add Meta Tags plugin (title is finely done by Stella)
    // Try to catch excerpt, if empty, shorten the body - Works for Basic Meta, Open Graph, Twitter Card and Dublin Core
    function localize_AMT_metatag( $metatags ) {
     global $post;
     $meta_localized = $metatags;
     if( (is_single() || is_page()) && ( STELLA_CURRENT_LANG != STELLA_DEFAULT_LANG ) ){	// Only Post, as Index is Ok (if no specific desc entered in AMT)
     for ($lesmetas=0; $lesmetas < count($metatags); $lesmetas++) {
        if (preg_match('#description"#', $metatags[$lesmetas]))  {
    	(is_single()) ? $body_new = get_post_meta( $post->ID, '_excerpt-' . STELLA_CURRENT_LANG, true ) : $body_new = '';
    	if ('' == $body_new ) { $body_new = get_post_meta( $post->ID, '_body-' . STELLA_CURRENT_LANG, true ); }
    	$body_new = preg_replace('#<a(.+)/a>#', '...', wp_trim_excerpt( $text )); // truncate the obtained text with WP standard function
    	$meta_localized[$lesmetas] = preg_replace('#content="(.+)"#isU', 'content="'.$body_new.'"', $meta_localized[$lesmetas]);
    	}
         }
       }
       return $meta_localized;
    }
    function change_menu($items) {
    if ( STELLA_CURRENT_LANG != STELLA_DEFAULT_LANG ){
      foreach($items as $item){
    	$zonetest = $item->post_title;
    	if ($zonetest == 'The_Label') {
                $item->url = 'The_Localized_Url'; } // Do this for all
      }
      return $items;
    }
    function wpse_52419_change_language( $locale ) {
    if ( STELLA_CURRENT_LANG != STELLA_DEFAULT_LANG ){ load_textdomain( 'default', WP_CONTENT_DIR . '/languages/fr_FR.mo' ); return 'fr_FR'; } else { return 'en_US'; }
    }

    I have hardcoded the language, but you can use the reformated STELLA_CURRENT_LANG

    Solution for 4. (flags to choose language)

    So I add to modify the classes/class-menu-language-switcher.php to modify the link line :

    $html = "<li><a href=$href><img src=\"path_to_your_image-".strtoupper($title).".png\" alt=\"".$title."\" style=\"border:none\" /></a></li>";

    Solution for 5. (next/previous posts links)

    Code to add in /stella-plugin.php at the end, just after the add_action('after_setup_theme',...)

    // function to fix the next/previous postS links (single post work fine already)
    add_filter('get_pagenum_link', 'stella_next_previous_fix');
    
    function stella_next_previous_fix($url) {
    	if ( STELLA_CURRENT_LANG != STELLA_DEFAULT_LANG ){
    		if( Url_Changer::is_subfolder() ){ // if single wordpress is in subfolder
    			$siteurl = Url_Changer::get_subfolder_name();
    			$url = str_replace( $siteurl.'/'.STELLA_CURRENT_LANG, '', $url);
    		}
    		else { $siteurl = Url_Changer::get_option('siteurl'); }
    		$url = Url_Changer::just_add_language_prefix_to_url( $url );
    	}
    	return $url;
    }

    Hope it will be useful to those of you who want a great, but cheap, and easy localization plugin for wordpress.

    STELLA DEVELOPERS, It will be a great Idea to implement all these fixes in the next version... It will definitely make STELLA plugin the PERFECT multi language plugin, easy and light, as more easy-to-use for WP beginners who won't have to digg into the codes and modify the sources ! :)

    PS: Thanks to tosho for pointing me to the right direction with his version of the wpse_52419_change_language function and to Scott for pointing to the right direction for the next/previous posts link ;)

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Stella plugin
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags

No tags yet.