WordPress.org

Ready to get started?Download WordPress

Forums

012 Ps Multi Languages
Language Flag Not Displayed (28 posts)

  1. beaulife
    Member
    Posted 1 year ago #

    Hi,

    I have installed this plugin, it is truly a very simple and easy implementation, however, the language flag is not displaying on top of the screen.

    I have added the codes into header.php as you shared. Please review below:

    <!DOCTYPE html>
    <html <?php language_attributes(); ?>>
    <head>
    <?php if ( function_exists( 'ps_012_m17n_bread_crumb' ) ) ps_012_m17n_bread_crumb(); ?>
    <?php if ( function_exists( 'pml_multilingual_list' ) ) pml_multilingual_list(); ?>
    	<title><?php if ( is_category() ) {
    		echo 'Category Archive for "'; single_cat_title(); echo '" | '; bloginfo( 'name' );
    	} elseif ( is_tag() ) {
    		echo 'Tag Archive for "'; single_tag_title(); echo '" | '; bloginfo( 'name' );
    	} elseif ( is_archive() ) {
    		wp_title(''); echo ' Archive | '; bloginfo( 'name' );
    	} elseif ( is_search() ) {
    		echo 'Search for "'.wp_specialchars($s).'" | '; bloginfo( 'name' );
    	} elseif ( is_home() || is_front_page() ) {
    		bloginfo( 'name' ); echo ' | '; bloginfo( 'description' );
    	}  elseif ( is_404() ) {
    		echo 'Error 404 Not Found | '; bloginfo( 'name' );
    	} elseif ( is_single() ) {
    		wp_title('');
    	} else {
    		echo wp_title( ' | ', false, right ); bloginfo( 'name' );
    	} ?></title>

    [Moderator Note: Please post code or markup snippets between backticks or use the code button. Or better still - use the pastebin]

    Would you mind provide us more clue on how to display the language flag properly?

    Thank you in advance.

    http://wordpress.org/extend/plugins/012-ps-multi-languages/

  2. Wang Bin
    Member
    Plugin Author

    Posted 1 year ago #

    Hi,
    <?php if ( function_exists( 'pml_multilingual_list' ) ) pml_multilingual_list('list',true); ?>

  3. amonti
    Member
    Posted 1 year ago #

    Ok, had a need for multi-language support, and this plug-in seems to have the best admin for multiple languages. The only problem is that it doesn't seem to work, but it works beautifully with a few 'tweaks':

    1) Follow the setup instructions - I'm defaulting to English with German and French support (for now).

    2) Paste the bread_crumb line verbatim after your <head> in your header.php
    This enables the plugin to follow and re-write URLs. If you want to see the crumb trail as a test, you can pass it two parameters: ('list', true), but you should just leave the parameters out normally (they default to ('list', false)

    3) Technically, your site now supports multiple languages, but the users can't select one (unless they add /?lang=fr manually to the URL). Displaying the flags takes a bit more work.

    First: decide where you want to place the flags. I have them at the very end of my header.php (just before the main div). You can also add them at the very top or a sidebar - it doesn't matter - as long as they are visible to the users in every page.

    Second: Add the following php snippet to where you want to place the flags:

    <?php if ( function_exists( 'ps_012_multilingual_list' ) ) $gs = ps_012_multilingual_list(); ?>

    Note that this is different from the pml_multilingual_list function as referenced in the documentation. I can't find that function in the entire plugin directory, but this one looks like a re-named version. This function returns an array, like so for me (from var_dump):

    array(3) {
    ["en"]=> array(3) {
    ["name"]=> string(7) "English"
    ["url"]=> string(9) "/?lang=en"
    ["current"]=> string(8) " current" }

    ["de"]=> array(3) {
    ["name"]=> string(6) "German"
    ["url"]=> string(9) "/?lang=de"
    ["current"]=> string(0) "" }

    ["fr"]=> array(3) {
    ["name"]=> string(6) "French"
    ["url"]=> string(9) "/?lang=fr"
    ["current"]=> string(0) "" }
    }

    Note that the array contains all configured languages, plus a URL suffix, and which language is current. I used this information to automatically create flags and URLs for the appropriate languages. But before adding the code, the flags need to be copied.

    Third: Copy the flags directory from the plugin to the images directory of your theme. Copy the entire directory so that you have a /images/flags directory. Visitors can't access the flags in the plugin, so they have to copied to a directory that can be linked to for public consumption.

    Last: After the ps_012_multilingual_list function call above (to create the $gs array), paste the following code (and I wanted to use Pastebin, but it's currently down/slow):

    <?php
    	foreach(array_reverse($gs, true) as $key=>$val){
    		$flags_dir = get_bloginfo('template_directory');
    		$flags_dir .= '/images/flags/';
    		$flag_icon = $flags_dir . $key . '.png';
    		if ( url_exists( $flag_icon )):
    			if ($val['current']) {
    				$flag_icon = '<img src="'.$flag_icon.'" style="float:right;margin:2px;padding:1px;border:1px solid #021a40;background-color:#ff0>"';
    			}
    			else
    			{
    				$flag_icon = '<img src="'.$flag_icon.'" style="float:right;margin:2px">';
    			}
    		endif;
    		$html .= '<a href="'.$val['url'].'">'.$flag_icon.'</a>&nbsp';
    	}
    
    	echo $html;
    ?>

    I won't provide a line-by-line explanation of the code, suffice it to say, the proper flags and context-sensitive URLs appear on the right side of the header on my site. The selected language's flag is highlighted and 'moves forward' a bit. Feel free to edit the style as you see fit.

    Make sure you have a couple of posts and pages in different languages, or you won't notice a difference. This plug-in is excellent, but more than likely suffers a bit from a language barrier. I hope this clears up some issues that people were having with it.

    Note that if you want to simply check the currently selected language, you can use the get_load_language() function in any php function. It returns the currently selected language ('fr','en', etc.).

    <?php if ( function_exists( 'get_load_language' ) ) $currlang = get_load_language(); ?>

    If you have any additional enhancements, I'd love to see them.

  4. eroldruzi
    Member
    Posted 1 year ago #

    amonti you are a savior!

    The only problem i encountered is the flags don't link. They're just blank image icons.

    Any suggestions?

  5. amonti
    Member
    Posted 1 year ago #

    Anytime you want to see the contents of a variable, just temporarily add an echo:

    echo ($flag_icon);

    This has to be between PHP delimiters. In your case, I'd place it directly after the

    $flag_icon = $flags_dir . $key . '.png';

    line. If the URL looks ok, cut and paste it onto a browser window. If you can't see it within a browser, make sure the path exists on your server. If the path exists, make sure the permissions are set so that the public can access content in your images directory. If you are pulling images from any other location (or server), simply copy the flags directory to that location (or server) and change the flags_dir variable to match the path.

    Hope this helps! I just found a plug-in and some files that allow the rest of the site's text to be automatically translated! I'll post that in a separate post.

  6. eroldruzi
    Member
    Posted 1 year ago #

    Thanks a lot man!
    I had an error with the path, I had modified it and forgot a "/" in the end.
    I figured it out with the echo.
    Thank you very much!
    Please give me a link for your next post!

  7. amonti
    Member
    Posted 1 year ago #

    Ok, so now that the URL includes a lang parameter, you can take advantage of that to dynamically set locale and use pre-translated theme files.

    Grab pre-translated wordpress files for the twentyeleven theme by downloading the pre-localized theme. I grabbled a couple from fr.wordpress.org and de.wordpress.org

    Expand the archives and copy the following language files:

    From 'wp-content/languages', copy all files to your wordpress installation 'wp-content/languages' (the languages directory may not exists - create it). Repeat this for all languages (each archive) - there shouldn't be any naming conflicts.

    From 'themes/twentyeleven/languages', copy the .mo and .po files to the same directory in your wordpress installation. Do not copy the .pot file. Repeat for each language archive.

    Next:

    Follow this link and paste the text into a text-only file called SetLocale.php - save it in your plugins directory (wp-content\plugins) and activate it via the admin panel.

    That's it - you should now have a fully-localized site.

    Oh, and just to 'tweak; the original code, you can pull the code to find the image directory out of the loop. Pastebin finally woke-up. Here is the code.

  8. stephan13
    Member
    Posted 1 year ago #

    Ok I wil try the solution to put the flags in the header, I hope I do it the right way

  9. stephan13
    Member
    Posted 1 year ago #

    Hmm I don't get it..

    <?php if ( function_exists( 'ps_012_m17n_bread_crumb' ) ) ps_012_m17n_bread_crumb(); ?>

    <?php if ( function_exists( 'pml_multilingual_list' ) ) pml_multilingual_list(); ?>

    <?php if ( function_exists( 'ps_012_multilingual_list' ) ) $gs = ps_012_multilingual_list(); ?>

    I put these lines in my header.php file and I tried also with Twenty Ten theme. After this code I paste this code also in the header and copied the flag directory in the theme iage directory

    <?php
    foreach(array_reverse($gs, true) as $key=>$val){
    $flags_dir = get_bloginfo('template_directory');
    $flags_dir .= '/images/flags/';
    $flag_icon = $flags_dir . $key . '.png';
    if ( url_exists( $flag_icon )):
    if ($val['current']) {
    $flag_icon = '<img src="'.$flag_icon.'" style="float:right;margin:2px;padding:1px;border:1px solid #021a40;background-color:#ff0>"';
    }
    else
    {
    $flag_icon = '<img src="'.$flag_icon.'" style="float:right;margin:2px">';
    }
    endif;
    $html .= ''.$flag_icon.'&nbsp';
    }

    echo $html;
    ?>


    But no flags are shown.. so what am I missing?

  10. amonti
    Member
    Posted 1 year ago #

    I guess the initial question is to check if your plugin installation is ok. The required functions are defined in a functions.php file in the plugin's directory. Your theme has to be able to locate the file in order to call the functions. If it can't, then nothing will appear, since the code checks if the functions exist before calling them.

    Try placing the following code before all the functions:

    <?php echo(function_exists('ps_012_m17n_bread_crumb'); ?>
    <?php echo(function_exists('pml_multilingual_list'); ?>
    <?php echo(function_exists('ps_012_multilingual_list'); ?>

    This will echo something like TrueFalseTrue - one for each of the functions. If they all return false, then you should check your plug-in installation. If they return TrueFalseTrue, then you should pass the optional parameters to the functions as follows:

    <?php if ( function_exists( 'ps_012_m17n_bread_crumb' ) ) ps_012_m17n_bread_crumb('list',true); ?>

    and see if 'Home' appears at the top of your page. If it does, then the plug-in is installed and working. Next, you can pass the optional parameters to the second function:

    <?php if ( function_exists( 'ps_012_multilingual_list' ) ) $gs = ps_012_multilingual_list(true, null); ?>

    Which will print out a list of the configured languages. If both of these work, then you may have your PHP code in an incorrect place. Try placing all of the code just after the <head> tag in your header.php file.

    Hope this helps!

  11. ian6
    Member
    Posted 1 year ago #

    hi there, if anyone could answer I'd be grateful...

    excuse me in advance for the newbie questions, but I can't find any intelligible instructions anywhere:

    - I can't see anything (settings etc) in the admin page after the plugin installation...
    - do I need to create the translated pages first or after the plugin installation? (now I just have one for testing); and when all new pages are ready do I put them n a different folder per language etc?
    - do I need to translate all the pages of the basic (English) site in the other languages, or it works with just some of them too?
    - in which file does the code have to be added? Is it all in the header.php?
    - I've copied the flags folder to my "uploads" and added the link in the code but...

    Well, any input is welcome.
    Thanks :-)

  12. amonti
    Member
    Posted 1 year ago #

    Sorry - only unintelligible instructions exist for this plug -in! :)

    To answer your first question, let's go though the installation step-by-step...

    1. Upload the 012 Ps Multi Languages folder to the plugins directory in your WordPress installation

    That's pretty straightforward; even easier would be to download the plugin via the plugin admin panel. You can install it, but don't activate it yet! The plugin relies on a configuration file that you configure in the next step.

    2a. You can Sample file from (_config.php), to add the multilingual and rename from _config.php to config.php( if multi site can config-$blog_id.php )

    So, in the plugin directory, under the 012-Ps-Multi-Languages folder, you'll find a folder called config. In that folder is a file called _config.php. There are five things to do here:

    a) Rename _config.php to config.php then edit it,
    b) Define the languages supported by your site,
    c) Define the multilingual codes associated with those languages,
    d) Define the search title in each supported language, and
    e) Define the default language

    In the root of the plugin's directory is a file called multilingual_code.txt. You can search that for the languages you would like to support: the first two characters define the language, and the entire string (2-5 characters) define the code. The languages in the multilingual array re just the plain 'English' names for supported languages. So at this point, you should have completed a, b, & c.

    Next define the search titles, and select a language as the default. Returning users should have a cookie set, so when they return to your site, their language selection should be retained. The default is for net-new visitors.

    Save your config.php file.

    2b or
    make dir 012-m17n-config in /wp-content/ and
    move setting files to /wp-content/012-m17n-config/config ?
    priority is hight of /wp-content/012-m17n-config/setting files

    I believe that this configuration is for multi-site installations. I don't have a multi-site installation, but it appears that various config files would be created, each with a numerical prefix - one for each site. The config files are searched by the plugin in priority order, starting with the one with the highest prefix. Nothing to do here unless you have a multi-site installation.

    3. Go to plugins list and activate "012 Ps Multi Languages".

    This is pretty straightforward. When you activate the plugin, you should not receive any messages. Now, when you create/edit posts, categories, etc. in admin, you will see which languages the post, category, etc. is defined for. If you scroll down when creating a new post, category, etc. you will see that each entry field has been duplicated - one for each language. That is what the user will see when they select the language to view the site in. If there is no translation for a particular entry, the entry in the default language is displayed.

    For your other questions:

    - do I need to create the translated pages first or after the plugin installation? (now I just have one for testing); and when all new pages are ready do I put them n a different folder per language etc?

    All of the translated text is entered directly in the admin panels. From there, all of the text is stored in the database, so there's really no folder structure to worry about.

    - do I need to translate all the pages of the basic (English) site in the other languages, or it works with just some of them too?

    Like I mention, if a translation doesn't exist for a particular post, it will use the default.

    - in which file does the code have to be added? Is it all in the header.php?

    If you are talking about the additional code I posted to display flags and language selection to the user, the bread_crumb call has to be placed in the header, but the flag code can be anywhere (but it's usually in the header).

    - I've copied the flags folder to my "uploads" and added the link in the code but...

    If uploads is where all of your publicly-accessible images are stored, that's ok, but you'll have to manually edit the path in the flag code, as it uses the default path to the template in-use, then adds on /images/flags/. Much easier just to copy the flags directory to images as I indicate.

    I hope this helps; it's not really a noob plugin, but it isn't all that bad either, and I absolutely love how different languages are handled in the admin panels.

    If anyone has any more tips or corrections, please post!

  13. ian6
    Member
    Posted 1 year ago #

    @amonti,

    thanks a lot! I would never have thought of this all myself within the coming 235 years!

    :-)

  14. amonti
    Member
    Posted 1 year ago #

    My apologies; I have a very slight correction in the code that creates the flags. The php line that creates the highlighted flag should be changed from this:

    $flag_icon = '<img src="'.$flag_icon.'" style="float:right;margin:2px;padding:1px;border:1px solid #021a40;background-color:#ff0>"';

    to this

    $flag_icon = '<img src="'.$flag_icon.'" style="float:right;margin:2px;padding:1px;border:1px solid #021a40;background-color:#ff0">';

    The ending double-quote should have appeared before the ending '>'. This error causes all of the text on a static page for the default language to appear as a link.

    You can grab an updated version of the code here.

    I discovered this on my own site - hopefully this hasn't caused anyone undue grief!

  15. xdios
    Member
    Posted 1 year ago #

    Hi everyone!

    @amonti, thank for your great explanations.
    I've got a problem with the code.

    the function:
    <?php if ( function_exists( 'ps_012_multilingual_list' ) ) $gs = ps_012_multilingual_list(); ?>

    doesn't give me back an array so I recieve this error from php:

    Warning: array_reverse() [function.array-reverse]: The argument should be an array in /homepages/13/d432318092/htdocs/wp-content/themes/risen/header.php on line 40

    Warning: Invalid argument supplied for foreach() in /homepages/13/d432318092/htdocs/wp-content/themes/risen/header.php on line 40

    the code on line 40 is the same you have published:

    foreach(array_reverse($gs, true) as $key=>$val){
    $flags_dir = get_bloginfo('template_directory');
    $flags_dir .= '/images/flags/';
    $flag_icon = $flags_dir . $key . '.png';
    if ( url_exists( $flag_icon )):
    	if ($val['current']) {
    	$flag_icon = '<img src="'.$flag_icon.'" style="float:right;margin:2px;padding:1px;border:1px solid #021a40;background-color:#ff0">';
    	}
    	else
    	{
    	$flag_icon = '<img src="'.$flag_icon.'" style="float:right;margin:2px">';
    	}
    	endif;
    $html .= '<a href="'.$val['url'].'">'.$flag_icon.'</a>&nbsp';
    	}
    	echo $html;

    Any idea how to fix it?

    Thanks in advance.

  16. xdios
    Member
    Posted 1 year ago #

    Ok, I will answer to myself.

    In the line:
    <?php if ( function_exists( 'ps_012_multilingual_list' ) ) $gs = ps_012_multilingual_list(false); ?>
    It has to have false as a parameter in order to recieve the array.

    Then I found another mistake (at least for me) in the code for flags.

    The function url_exists() actually is called ps_url_exists() in the function.php file, so just changing it the flags are shown.

    I hope this could be helpful for someone. ;)

  17. Twingo445
    Member
    Posted 1 year ago #

    Thanks for this great tool.

    One more thing.

    How i can move the flags to the lower right or left corner of the header?

    Thanks in advance.

    Thomas

  18. Wang Bin
    Member
    Plugin Author

    Posted 1 year ago #

    Hello,
    I think you'll be referring to the following post.
    Thank you.

    languages flag_icon

    languages list

    I would like to thank the people of the answer because it's not good at English.

  19. ArjanT
    Member
    Posted 1 year ago #

    HI, sorry for another unintelligleble quaetion.
    But the flags don ´t show.

    I copied the code supplied by Amonti.
    I changed url_exist() to ps_url_exist() as suggested by xdios
    (I also needed to add the false parameter as per xdios)
    Flags don´t show up, so added the echo ($flag_icon) ; as per amonti.

    The value returned is actually the 3 urls of my languages in one string:
    http://colorartetejas.com/wp-content/themes/artificer/images/flags/nl.pnghttp://colorartetejas.com/wp-content/themes/artificer/images/flags/en.pnghttp://colorartetejas.com/wp-content/themes/artificer/images/flags/es.png

    each url apart shows up nicely, but all together of course not ...
    Any idea what could cause this?
    Thanks everybody for contributing!

  20. amonti
    Member
    Posted 1 year ago #

    How I wish I could edit my post above...unfortunately, a couple of days after I figured out the languages flag code (as per above), the author of the plug-in slightly changed one of the functions without changing the version number. This messed quite a few people up.

    Please consult this post for pastebin links to flag code that works with the current version.

  21. xdios
    Member
    Posted 1 year ago #

    To ArjanT:

    If you speak Spanish (I think so) you can read a full explanation step by step made by me in this blog: Diseño y Desarrollo Web.

    I hope this finally help you.

  22. ArjanT
    Member
    Posted 1 year ago #

    Thank you amonti and xdios (also for the link to yr site with other interesting blogs!), finally I have found the cause. I noticed the path to the icons in my error showed wp-content/themes/artificer/images/flags folder as the destiny ... and they did not exist there, I had copied them to the wp-content/images/flags folder... copying the necessary .png to the right folder made the icons show properly. Simple as that... Sorry for the confusion. Rgds.

  23. Trilobites
    Member
    Posted 1 year ago #

    Hello,

    Please, I need some help.

    The pluggin is ready but I found any problems to traslate the widgets, links and bread crumbs, ¿would you tell me whats the function to traslate this?.

    Thanks a lot!!

  24. amonti
    Member
    Posted 1 year ago #

    Trilobites: not exactly sure what you are asking, but widgets should be translated as part of the theme. Did you follow these instructions to add multiple languages to your WordPress installation?

    If you edit the .POT files, you can simply use the "__" function to automatically translate strings into the users' selected language.

    For links, you can use the get_load_language() function of this plugin to dynamically determine language and display links (or whatever) based on the language selection, like so:

    if ( function_exists( 'get_load_language' ) ) $curr_lang = get_load_language();
    switch ( $curr_lang ) :
    	case 'en' :?> (in all languages)<?php
    		break;
    	case 'de' :?> (in allen Sprachen)<?php
    		break;
    	case 'fr' :?> (dans toutes les langues)<?php
    		break;
    	default :?> (in all languages)<?php
    		break;
    endswitch;

    I don't think there's any need to translate breadcrumbs as that's something not seen by the user; please clarify your question if you think some sort of breadcrumb translation is required.

    Hope this helps...

  25. La Floutta
    Member
    Posted 1 year ago #

    @amonti : Thanks for the tips and your clear explanations
    @xdios : I faced exatly the same problems as you described. Your help was so precious. I confirm that replacing url_exists() by ps_url_exists() is necessary.

    --> You guys are my hero.

    Thank you for this great component and all the help i found here

  26. Trilobites
    Member
    Posted 1 year ago #

    Hello amonti,

    I would try to explain my problem better, sorry for my english.

    I have a blog in my multilingual web(spanish default, french, portuguese and english) and I can´t use the multilingual options to translate the widgets sidebar and the footer. I only can choose one language, for example in english: "Recent Post", "Latest Post", but I don´t have the functionality to white the same text in other languages.

    The second problem: In my theme you can show to the user the navigation with breadcrumbs, they are located close to the title. For example: "Home - Sectors- Energy" but alwais show like this "Home - Sectores (in spanish)- Energy". Is very extrange because if you are in the section "Sectors" the breadcrumb is ok: "Home-Sectors".

    If you can give an email I will send you some sreenshoots.

    Thank you very much for your help!!!

    Best regards!!

  27. amonti
    Member
    Posted 1 year ago #

    Hi Trilobites,

    No need to apologize - your English is great!

    I don't think there are any multilingual options in this plug-in to display different widget titles or text based on language selection. That generally means that you will have to add code yourself. There's a nice summary on how to dynamically hide widgets in code here. You essentially add a filter hook to the sidebar_widgets and footer_widgets to hide all widgets that are not in the selected language (determined by the get_load_language function as in the above post).

    There is also another option, but I'm not sure if it will work. You can use the "widget logic" plugin, which allows you to show or hide widgets based on certain conditions. The plug-in adds a field called "Widget logic" to a widget's configuration that allows you to specify when the widget is displayed. You would add all widgets for all language to your sidebar and footer, then use the Widget logic field to display only the widgets in the selected language. You could add something like get_load_language() == 'fr' to the Widget logic field that would only display the widget if French was the currently selected language. I'm not sure if you can add a function call in the Widget logic field. If not, you will have to set a global variable in the page header to the selected language. If you added my flag code, you should have a variable called selang which is set to the currently selected language. You could try selang = 'fr_FR' in the Widget logic field.

    As far as the breadcrumb is concerned, I find it strange that only one link would display in another language, and yet be displayed correctly when you select that link. Have you taken a look at the bread_crumb code in 012-ps-multi-languages/ps-multi-languages.php to see what is happening? I don't use the bread crumb function on my site, so I'm not really familiar with its inner workings.

    Sorry that I don't have time to test any of this or provide more breadcrumb information - hope this helps!

    - Andrew

  28. goldmelodyvn
    Member
    Posted 1 year ago #

    Summary work for me:
    Add the code follow in header.php of your theme:

    <?php
    // for multilanguage change flag
    if ( function_exists( 'ps_012_multilingual_list' ) )
    {
    	$gs = ps_012_multilingual_list(false);
    }
    foreach(array_reverse($gs, true) as $key=>$val){
    		$flags_dir = get_bloginfo('template_directory');
    		$flags_dir .= '/images/flags/';
    		$flag_icon = $flags_dir . $key . '.png';
    		if ( ps_url_exists( $flag_icon )):
    			if ($val['current']) {
    				$flag_icon = '<img src="'.$flag_icon.'" style="float:right;margin:2px;border:1px solid #021a40;background-color:#ff0>"';
    			}
    			else
    			{
    				$flag_icon = '<img src="'.$flag_icon.'" style="float:right;margin:2px">';
    			}
    		endif;
    		$html .= '<a href="'.$val['url'].'">'.$flag_icon.'</a>&nbsp';
    	}
    
    	echo $html;
    
    ?>

    Copy folder at: wordpress\wp-content\plugins12-ps-multi-languages\flags to wp-content\themes\yourtheme\images

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.