Useful code to make Stella the BEST multi-language plugin
-
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_Localizerif ( 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
- The topic ‘Useful code to make Stella the BEST multi-language plugin’ is closed to new replies.