• Hello and thanks for this great Plugin !!

    As posted in the review (but I am not sure it is the right place), I find Stella to be a 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 ?
    3. Support for WPSEO, but not yet compatible with AMT (Add Meta Tags plugin)

    It will be a great Idea to include these in the next version… It will make the plugin PERFECT as more easy-to-use for WP beginners who do not like to digg into the codes and modify the sources (also a big risk for the future upgrades) and still want an easy and light solution ??

    Here are the lines (for point 1 and 2) I did add in classes/class-menu-language-switcher.php (class called soon enough to correctly trigger the local change and with just small codes lines ?? ):
    Added in _construct of Primary_Menu_Language_Switcher :

    add_filter('wp_nav_menu_objects', array($this, 'change_menu'), 1, 1);
    add_filter( 'locale', array($this, 'wpse_52419_change_language'), 1, 1 );

    The related functions, are after the custom_menu_item function :

    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

    Here are the lines I did add (for point 3) to classes/class-post-localizer.php
    Added in start of Post_Localizer

    if ( defined('AMT_DIR') ) {add_filter( 'amt_metadata_head', array($this, 'localize_stella_metatag'), 1, 1 ); }

    And the related function further down below 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_stella_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;
    }

    Hope it will be useful to those of you who want a great, but cheap, and easy localization plugin for wordpress -> STELLA is perfect with these few more lines ??
    PS: Thanks to tosho for pointing me to the right direction with his version of the wpse_52419_change_language function

    https://www.ads-software.com/plugins/stella-free/

Viewing 15 replies - 1 through 15 (of 17 total)
  • Thread Starter bloodico

    (@bloodico)

    UPDATE
    As I did the modification in 2 times (and learned a lot in between), I realize now that for a cleaner code, it is much better to add all add_filter and related function in classes/class-post-localizer.php only, instead of classes/class-menu-language-switcher.php as described in the previous post…

    It makes more sense, as it is the concerned class, and it leaves only 1 file modified -> in case of upgrade of Stella not including the new functions it will be more easy to implement them again ??

    Thread Starter bloodico

    (@bloodico)

    AND last but not least… (Almost forgot) 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…)

    So I add to modify the classes/class-menu-language-switcher.php to modify the link line (this why the codes where split in 2 classes in the 1st post) :

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

    PLEASE ??
    Stella crew, Look into these lines to make Stella the best ever multilingual plugin ! ?? I love it and loved its price ??

    Thread Starter bloodico

    (@bloodico)

    Here is another fix :
    for the next/previous posts links (next/previous pages…)

    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;
    }

    Well… there are yet no answers to this post….
    Hope you, Stella Developpers are still alive and planning to upgrade the plugin as I find it really great, light and easy, and making these few fixes will propulse it at the top of the multi-linguage plugin !!

    Nevertheless, hope this post will help fellow developers who are using the uncomnplete version 1.4 of Stella ??

    Do not give up, add these lines and make Stella a great plugin for your wordpress multi language website !
    ??

    As for Flags there is extra plugin Stella flags,
    but I am fine without it.
    https://www.ads-software.com/plugins/stella-flags/

    Thread Starter bloodico

    (@bloodico)

    Stella-flags is not downlodable anymore on the plugin page (It has never been maintained and it is not compatibl;e since 4.4.2+)… This is also the reason I made the modification myself ??

    Thanks for pointing to it anyway ??

    Hello,

    I’m trying to add flags in the menu instead of letters. I’ve paste the code you suggested, but now I don’t know how to place the link to the flags image for each language. Could you please help me? ?? I have no options on stella language admin page.

    thanks in advance,

    Anna

    Thread Starter bloodico

    (@bloodico)

    Hi Anna (@annaraguis)

    Well I do not really understand your question, as, appart from the code modification, you have nothing to do…

    just add

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

    in the classes/class-menu-language-switcher.php file (replacing the existing line) you sure have to replace also the src and change path_to_your_image-“.strtoupper($title).”.png source file by your own image flag file (which have to finish with -COUNTRYCODE in this example to work)…

    As easy as this… ??

    Thread Starter bloodico

    (@bloodico)

    Hi Anna (@annaraguis)

    Well I do not really understand your question, as, apart from the code modification, you have nothing to do…

    just add

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

    in the classes/class-menu-language-switcher.php file (replacing the existing line) you sure have to replace also the src and change path_to_your_image-“.strtoupper($title).”.png source file by your own image flag file (which have to finish with -COUNTRYCODE in this example to work)…

    As easy as this… ??

    Hello,

    thanks for the reply. I’m quite new modifying code so there are some things I’m missing…

    I have replaced the line exactly as you said. The problem is I don’t know what should i write instead of “path_to_your_image-“.strtoupper($title).”.png” and I don’t know how to associate the images with the languages.

    So far I have replaced the line in class-menu-language-switcher.php, and I have upload tw images on my media directory: “ES.png” and “EN.png”.

    hope you can help me, many thanks!! ??

    Anna

    ok, now I have solved it!

    many thanks!! ??

    Anna

    Thread Starter bloodico

    (@bloodico)

    Happy to hear you have solved your problem ??

    Unbelieva

    (@unbelieva)

    I feel really incapable at the moment, don’t know if this is because my brain is just tired or what’s going on, but I’ve been trying to solve the same thing that annaraguls was having and just can’t figure it out. Why don’t any of the paths work with “path_to_your_image-“? What was the solution for annaraguis? What e x a c t l y do I put there? Because at the moment my solutions are not working.

    Hope you can help. Bless.

    Thread Starter bloodico

    (@bloodico)

    Hi @unbelieva

    You just have to replace path_to_your_image-“.strtoupper($title).”.png with the correct path to your image

    Let’s say your domain is https://www.yoursite.com and
    Let’s say that you have your flag images like this :
    wp-content/uploads/2014/09/flag-EN.png for the English flag
    wp-content/uploads/2014/09/flag-FR.png for the French flag

    You just have to replace “path_to_your_image-“ by https://www.yoursite.com/wp-content/uploads/2014/09/flag-&#8220; and you are done ??

    Hope this helped ??

    Unbelieva

    (@unbelieva)

    Finally got it. Thank you so much!

    Thread Starter bloodico

    (@bloodico)

    Happy to hear you have solved your problem ??

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘Useful code to make Stella the BEST multi-language plugin’ is closed to new replies.