• 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/

Viewing 15 replies - 1 through 15 (of 27 total)
  • Plugin Author Wang Bin

    (@ouhinit)

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

    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.

    amonti you are a savior!

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

    Any suggestions?

    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.

    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!

    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.

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

    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?

    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!

    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 πŸ™‚

    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!

    @amonti,

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

    πŸ™‚

    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!

    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.

    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. πŸ˜‰

Viewing 15 replies - 1 through 15 (of 27 total)
  • The topic ‘[Plugin: 012 Ps Multi Languages] Language Flag Not Displayed’ is closed to new replies.