amonti
Forum Replies Created
-
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_widgetsandfooter_widgetsto hide all widgets that are not in the selected language (determined by theget_load_languagefunction 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 calledselangwhich is set to the currently selected language. You could tryselang = '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_crumbcode in012-ps-multi-languages/ps-multi-languages.phpto 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
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…
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.
I just went through this and successfully excluded a few pages, and I’m using ‘post name’ for permalinks. The plugin code to exclude posts/page is as follows:
if(is_array($excludes) && count($excludes)>0) { $where.=" AND ID NOT IN ('" . implode("','",$excludes) . "')"; }ID refers to the post/page id from the wp_posts table in the wordpress database. This code basically takes all of the post IDs entered in the ‘exclude’ field and ensures that they are excluded from the sitemap creation. This means that nothing but a numeric post ID will work. If you have changed your permalink structure to something that hides the post id, you won’t have any idea what the id for a post or page is.
If you know how to query the WordPress database from phpMyAdmin, MySQL Workbench, or the command line, then maybe you can skip the next step.
Install and activate the SQL Executioner plugin.
Then select Tools, then “SQL Executioner”
You should see an input area at the top where you can enter a query. To find a post by post name, type:
SELECT ID, post_name FROM $posts where post_name = 'post name'If you are using PHPMyAdmin, or MySQL Workbench, you can use:
SELECT * FROM wordpress.wp_posts where post_name = 'post name'Where post name is replaced with the name of the post you are looking for. When you locate your post/page, note the corresponding ID.
Open the Sitemap plugin and enter the post/page IDs as only numbers (no slashes), separated by commas. Hit Apply, manually rebuild your sitemap, and the posts/pages you entered should be excluded.
Hope this helps!
Well, my SEO friend didn’t come through, but I have found an easy way to ensure that Googlebot indexes pages in all languages.
As a pre-requisite, I am assuming that your site is registered and configured with with Google Webmaster tools
I installed and configured the “Google XML Sitemaps” plug-in and generated a sitemap. Note that you can’t add language parameters to the sitemap URLs as Google will flag the entries as errors.
Configure Webmaster tools to automatically pull in your sitemap, and then wait a few days for Google to start indexing your site. You should resolve any errors. After Google indicates that a few pages have been indexed, open up the “URL Parameters” option under “Configuration”.
The message will indicate that no parameter issues are being experienced, but choose “Add Parameter” anyway. A list of parameter keywords should be displayed, and one of them should be “lang”. It will be set to “Let Googlebot decide” as to how to crawl the parameter, but select “Edit” anyway.
In the popup window, change the parameters so that it looks like this.
After the configuration change, Google will try to index all pages with all of the language parameters configured for your site. The Googlebot may have been scanning all languages, but this way, you guarantee that all pages are scanned in all languages. Give it a few more days, then check to see if search results return in all supported languages.
Hope this helps!
I have a friend who specializes in SEO working on this. He swears that it’s possible; I’ll post what he comes up with (one way or another).
Wang; thanks for writing the plug-in – the admin interface is great! I’ll have to try the iframe code as well; I’ll also var_dump $selang to make sure it’s the right type.
I also added code to append: “&lang=’ to the end of the Twitter and Facebook parameters to make sure that links are sent using the users’ selected language. The code is really easy:
Twitter:
data-url="<?php printf('%s&lang=%s',the_permalink(),get_load_language()); ?>"Facebook:
href="<?php printf('%s&lang=%s',the_permalink(),get_load_language()); ?>"I should create another thread for the following question, but I’ll ask you here:
Is there any chance that you can figure out a way to only display comments for a particular language?
I’m stuck where everyone else who have tackled the problem seems to be: I can store language metadata with the comment and can filter the comments based on language, but the comment counts and comment page functionality only consider ALL comments – not just comments for a particular language.
So for example, if a German user looks at a post, it says that there are 3 comments, but because they are all in English, no comments appear. If there are enough filtered comments, “Next” appears, even though there aren’t any comments displayed! Comment count processing seems to be buried deep in the query and comment classes.
If there’s enough interest, I’ll create a separate thread.
Any suggestions would be appreciated!
That’s great news, and thanks for the kudos – glad to help!
Are your URLs being re-written with the selected language on the end?
http://www.yoursite.com/?lang=de
Mine doesn’t show any URL suffix in initially entering the site, but every link after that results in the suffix in the selected language being added. Could another plugin be interfering with this behaviour?
That is strange! Did you install the
setlocaleplug-in as per my post here?The language preference uses cookies, so you have to have cookies enabled. The language preference should persist between pages/posts, and even sessions.
I just verified that my test site maintain the language selection between pages/posts/sessions, and I really didn’t do anything other than install the setlocale plugin. If you installed & activated the plug-in and are still having issues, please follow-up.
I think I found the source of the ‘bugs’ you found, and cleared up something I was confused by.
The author of the plug-in updated the source files, but did not update the revision number! The current source files have a datestamp of ‘2012-10-03 9:39AM’, while the source files that I have have a datestamp of ‘2012-09-30 4:12PM’ – and there are a few changes. If the author of the plugin is reading this – PLEASE UPDATE YOUR VERSION NUMBER WHEN YOU UPDATE SOURCE FILES!! ソースファイルを更新するときに、バージョン番号を更新してください!
So, from my diff, here are all the changes between the files:
You found two of the changes: lines 855 and 864 of ps-multi-languages.php (change ‘url_exists’ to ‘ps_url_exists’), and
Two changes within functions.php: lines 19 and 67 : change the $echo parameter to ps_012_multilingual_list from false to true (19), and change the function name from url_exists to ps_url_exists.
Here’s an updated version of ps-multi-languages.php
If someone downloads and updates the new function.php, the previous flag code I posted won’t work, since calling the function will return the flag html snippet, which is what I think the author originally intended. In this case, your change to function.php to display the flags will do the trick.
Here’s an updated version of functions.php with the flag code included, reverse and highlighted. Users will have to remove the php code in their header to display the flags, but leave the following line:
<?php if ( function_exists( 'ps_012_multilingual_list' ) ) $gs = ps_012_multilingual_list() ; ?>Finally, to answer your question, I re-applied my changes to the ‘new’ version of ps-multi-languages.php, and it seems to work just fine. I updated the tagline for all of my supported languages, and the changes appeared on the test site. Did you change any other code in any function? Maybe I’m misinterpreting what you mean by blogdescription? Please let me know.
I gave it a shot and added multi-language support for excerpts by modifying the following files:
ps-multi-languages.php&
ps-multilingual-edit-post.phpThe only caveat is that the excerpt fields for supported languages does not honour the show/hide excerpt checkbox – they always display.
I tested multilingual excerpts by entering excerpt text in multiple languages, and adding snippets to the home page of my test site. The excerpts display in the selected language.
Backup the current version of your code, and replace the files with these:
ps-multi-languages.php
ps-multilingual-edit-post.phpTo be safe, you should temporarily deactivate the plug-in, replace the files, and reactivate the plugin. If you update your version of the plugin, you will have to re-apply the changes to the new version.
Please let me know if this works for you.
Great, but just a small caution – if the plug-in is ever upgraded, the changes in
function.phpmay be run-over. Users should remember to re-apply their changes to the new version offunction.php.There a bunch of commented-out code for adding multi-language support for media files, so it’s possible that an upgrade is in the works (hope so, anyway).
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!
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 installationThat’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-Languagesfolder, you’ll find a folder calledconfig. In that folder is a file called_config.php. There are five things to do here:a) Rename
_config.phptoconfig.phpthen 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 languageIn 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.phpfile.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 filesI 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_crumbcall 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
uploadsis 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 toimagesas 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!