No longer supported! Not compatible with WP 2.0!
Another day, another version of my Language Picker Plugin. New features in version .9:
- WordPress localization can be tied to user’s preferred language!
- List languages available for the current post.
- Provide translations for other text in your templates!
Getting started:
- To begin with, download lang_picker.phps and rename it lang_picker.php
- Change the default language in lang_picker.php, if neccessary, by replacing en with the appropriate language code
- Upload the file to your plugins directory (/wp_content/plugins)
- Then activate it in the Plugins section of the WP admin panel
Using the plugin:
- To write a post in more than one language, simply enclose everything not in the default language in these tags:
and . Be sure to replace xx with the appropriate language code - At first, only posts in the specified default language will be displayed. To temporarily view another language, append ?lp_lang_view=xx to any cruft-free URL, or &lp_lang_view=xx to any cruft-full URL, being sure to replace xx with the appropriate language code. For example, you can temporarily view the German version of this entry.
- To permanently view another language, use lp_lang_pref instead of lp_lang_view. This will set a cookie and display the new language preference whenever it is available. For example, you can set your preference to the German version of this site. (Or switch back to English.)
- To list languages available for a post, use this tag: < ?php lp_other_langs(’none’, ‘
- ‘, ‘
‘, ‘
- (’, ‘)
- ‘none’: the string to display if there are no other languages
- ‘
- ‘: the string to put in front of the list of other languages
- ‘
- ‘
- (’: the string to put in front of each language
- ‘)
- To provide a translation for any text in your template (like the menu on this site), use the < ?php lp(’arg’); ?> function.
- Method 1: Set ‘arg’ to ’start’ to start the localization, and then call the function again with ’stop’ to stop the localization
- Method 2: Alternately, you can just eliminate ‘arg’ completely, but this is less readable and makes it easier to forget a starting or stopping < ?php lp(); ?> call
- Method 3: Set ‘arg’ to the text to be localized
Examples:
- Method 1: < ?php lp(’start’); ?>Hello!
Guten Tag! < ?php lp(’stop’); ?> - Method 2: < ?php lp(); ?>Hello!
Guten Tag! < ?php lp(); ?> - Method 3: < ?php lp(’Hello!
Guten Tag!’); ?>
In each of these cases, “Hello!” would be displayed unless the user’s preference was set to ‘de’, in which case “Guten Tag” would be displayed.
- Tying WP localization to a user’s language preference is a two step process:
- Comment out the line setting the language for localization in wp-config.php
- Rename .mo files to match the language codes used in your blog. For example, de_DE.mo might become de.mo. (Of course,if you only want to use this plugin to allow per user localization and do not want to write posts in other languages, there is no need to rename the .mo files. Just use the name of the file, without the .mo extension, when creating the links to set cookies.)
- Version .9: Made it possible to tie preferred language to WP localization.
- Version .8: Not released. Added ability to translate other text.
- Version .7: Not released. Added ability to list languages in post.
- Version .6: First public release
- Version .5: Switched from my-hacks to plugin
- < .5: Hacked together for personal use with WP 1.0
- Optimize
- Add other features from the old my-hacks version
‘);?>. The arguments are (defaults indicated in example code):
‘: the string to put at the end of the list of other languages
‘: the string to put at the end of each language
Note: If you do not manually specify an excerpt (in one language), your RSS feed will generate one for you without running it through the Language Picker Plugin. Thus, both languages will be visible. History:
To do:
Wonderful plugin!
After following your instrunctions, I have an error though. Maybe you know where I need to check. It’s showing:
Warning: Cannot modify header information – headers already sent by (output started at [...]/blog/wp-content/plugins/lang_picker.php:1) in [...]/blog/wp-content/plugins/lang_picker.php on line 42
line 42 in lang_picker.php is the setcookie part.
Thanks!
I get the same problem when trying to enter wp-admin or any child page and a suspicious || before the error or enclosing it.
Would there be a way to translate the titles as well? and but it doesn’t seem to work. It shows the two languages at the same time
I’ve tried both with the php tags and without with the
sorry for filling up so much comment space
and `
In the message above I meant `
It seems the “list languages available for a post” is not working as expected (I think). At the end of my permalink it writes `/xx/`(language mo name) instead of the `?lp_lang_view=xx`
Thanks for the feedback! I’ll look at your problems when I have time later today or tomorrow…
Hi Jason,
it seems I’ve fixed the error. I’m not sure how, but it’s over now.
About the title thing, do you think it could be done adding a new custom field for the second language?
Hello, grate plug-in. Works wonderful except the problem with titles. Have there been (or will be?) any fixes for that?
The thing about titles has to do with where there are filters available. Until the next version of WP, titles probably won’t be possible, unless I make use of custom fields… I’ll have to look at it some more…
It seems I have the same error about the headers that are being resent (post 1 and 2). I have it on two brand-new installations, and two different hosts. It would be very suspicious if it’s the host.
Would you have some ideas about this? WordPress is really unusable due to this error, sadly.
Could you post a URL so I could see an example of what you’re talking about, David?
I’m sorry to have bothered you with this. It seems there were multiple files which had excessive white space. That made PHP complain.
The problem is fixed now.
Thanks for a fine plugin.
I have sucsessfully integrated the lovely plugin to my blog. However I think I have found a bug. The line “lp_other_langs(’none’, ‘
‘, ‘
‘, ‘
‘);” is added into index.php in the meta part of an entry.
The link that is generated is not working. The ?lp_lang_view=en is added at the end of the link, however this does not work when WP allready has added ?p=220. The plugin should, as you proberbly know, add &lp_lang_view=en instead, to get the link to work. Hope this is easy to fix. A sneek preview of my blog can be seen at http://217.8.138.143/~nortis/blog/index.php?lp_lang_pref=en
I fixed the problem with correcting line 113 and 121 in wp-content/plugins/lang_picker.php. I replaced the “…a href=’”.$link.”?lp_lang_view=$lang…” with “…a href=’”.$link.”&lp_lang_view=$lang…” it seemes to work fine now.
I have tried to install this plugin twice. Each time I get an error when I want to save the new post in the admin section. The following error is displayed:
Warning: Cannot modify header information – headers already sent by (output started at /home/hansguid/public_html/wp-content/plugins/lang_picker.php:164) in /home/hansguid/public_html/wp-admin/post.php on line 146
Any idea what is going wrong? Would really like to use the plugin…
The new message still seems to get saved. When editing a post and saving it the error appears in another line:
Warning: Cannot modify header information – headers already sent by (output started at /home/hansguid/public_html/wp-content/plugins/lang_picker.php:164) in /home/hansguid/public_html/wp-admin/post.php on line 340
Implemented language_picker despite of the errors with posting in the admin section. It turns out to give also errors when someone wants to post a comment. After clicking “Say It” the following appears:
Warning: Cannot modify header information – headers already sent by (output started at /home/hansguid/public_html/wp-content/plugins/lang_picker.php:164) in /home/hansguid/public_html/wp-comments-post.php on line 89
Warning: Cannot modify header information – headers already sent by (output started at /home/hansguid/public_html/wp-content/plugins/lang_picker.php:164) in /home/hansguid/public_html/wp-comments-post.php on line 90
Warning: Cannot modify header information – headers already sent by (output started at /home/hansguid/public_html/wp-content/plugins/lang_picker.php:164) in /home/hansguid/public_html/wp-comments-post.php on line 91
Warning: Cannot modify header information – headers already sent by (output started at /home/hansguid/public_html/wp-content/plugins/lang_picker.php:164) in /home/hansguid/public_html/wp-comments-post.php on line 93
Warning: Cannot modify header information – headers already sent by (output started at /home/hansguid/public_html/wp-content/plugins/lang_picker.php:164) in /home/hansguid/public_html/wp-comments-post.php on line 94
Warning: Cannot modify header information – headers already sent by (output started at /home/hansguid/public_html/wp-content/plugins/lang_picker.php:164) in /home/hansguid/public_html/wp-comments-post.php on line 95
Warning: Cannot modify header information – headers already sent by (output started at /home/hansguid/public_html/wp-content/plugins/lang_picker.php:164) in /home/hansguid/public_html/wp-comments-post.php on line 96
Warning: Cannot modify header information – headers already sent by (output started at /home/hansguid/public_html/wp-content/plugins/lang_picker.php:164) in /home/hansguid/public_html/wp-comments-post.php on line 101
Please delete these comments, but it seems the only way to get a tip how to solve this.
Check http://www.hansguido.nl when you want to see it happening.
Hmmm, strange, the problem seem to have solved itself…? Similar to Aletheia I messed around and now suddenly the errors do not appear anymore.
May be the settings in the heading of lang_picker.php -> set both on FALSE?
Deleted all my cookies to be sure…
Anyhow, let’s see how it holds. I am happy with it!
Sorry (you can delete the other comments), this time some more feedback. There are two things that I am struggling with: tags. When I have a long article in two languages and I want to split both of them into an introduction I am placing two tags in the text. This does not work properly – the alternative language will not show properly.
1. language picker does not work together with the
2. In the category screen (overview of articles) the Language Switch does not switch the language of the category view (…./index.php?cat=3&lp_lang_view=en) but takes the oldest article and translates that.
Especially the incompatibility with the tag makes it quite difficult to use properly.
I managed to translate the titles by simply adding the following line to the plugin code:
add_filter('the_title', 'lang_picker',1);and then using the <lang_xx> tags as for normal text…
This was using Wordpress 1.2 Mingus, BTW.
Hope this helps somebody
The problem had been that RSS feeds ended up showing <lang_xx> tags without choosing a language. Looks like RSS content is correctly filtered now.
I’d love to find the time to update this plugin. Maybe after 1.3 is released. Seems silly to do any work before that.
I also had the problem with “headers already sent” warnings… I checked the plugin source, and at the end of the file ( ?> ) I had white space after the “?>”.
Please check, maybe thats the problem ?
No new line shall not occur after this also.
Great plugin, thanks !
And maybe a useful thing: instead a line :
$default_lang = 'en';
I put the lines below to autmatically detect accepted language of visitor:
$language = getenv("HTTP_ACCEPT_LANGUAGE");
$pattern = '/^(.{2})[,|-](.*)/i';
preg_match($pattern, $language, $match);
if ($match[1] == 'pl')
$default_lang = 'pl';
else
$default_lang = 'en';
The code is simple, probably might be enhanced, but works nice
That is a good idea, Przemek.
Unfortunately, I don’t think I’m going to continue developing this plugin until 1.3 comes out, and even then it will likely take a very different form. If I do take it a different direction, however, I’ll be sure to include a way to upgrade from the current format.
Hi, I’ve installed our wonderful switcher on my blog. But, unfortunatly, there is something that bothers me : I often include quotes, or code fragment, in my blog entries. And I’ve not found any other way to use them but to include them in both default and language specific version.
As an example, suppose I write the following entry
<lang_en>
an image : <img src=”toto”>
</lang_en>
une image : <img src=”toto”>
Hi Jason, I’m using your plugin for one of my websites and it’s great.
However I have a problem now with the language in some parts of the site and I’m not sure if this could be the plugin or something I changed.
The admin is all in English instead of the main language I have set in the plugin which is Spanish. The weird thing is that the Plugin section is in Spanish. The archive months are in English as well.
Have you seen a problem like this before? Could it have anything to do with the plugin?
Thanks
Esther: I’m not seeing it at your site right now. Did it happen after clicking a link to view an entry in English? If so, clicking a link to view an entry in Spanish would set it back to Spanish.
Great plugin
I have a problem, the translatios work for the main page, but if i choose to view a post in a given translation then it shows it in the default language set in the plugin code.
Default lang is spanish, if i see the main site in english: http://elbolo.lacucalbina.org/blog/?lp_lang_view=en
then it works, but if i want to see any post in english for example:
http://elbolo.lacucalbina.org/blog/index.php?p=5?lp_lang_view=en
it shows it in the default language (spanish), not in the lang that it should!
What have i done wrong?
Jason, I wasn’t using the plugin in my page. I was using it for a page I developed using wordpress. I ended up turning off the plugin. I wasn’t using it after all and I set back the language in the wp-l10n file, then it worked again.
But thanks anyway for taking the time.
I’ve sucessfully installed lang_picker and it works well except for the interaction with the tag. Putting two in messes up the html, but only putting one in (in the default language section) leaves the other language version without a means to jump. Any comments or suggestions for how I could try and tackle this? Thanks!
Hi, I’ve tried installing the plugin, but as soon as I activate it I get the following error:
parse error, unexpected ‘}’ in /customers/bering-express.dk/bering-express.dk/httpd.www/weblog/wp-content/plugins/lang_picker.php on line 112
What to do?