I’ve written a simple multi-language system, whereby clicking on a flag icon sets a one year cookie containing a two letter language code (e.g. nl, de, etc).
I hook into the wp
action to read the cookie value, then use the the_title
and the_content
filters to show the correct language (the different languages are entered via metaboxes on the page/post edit screen).
This all works great except I’d also like to have permalinks for each language version whereby the two letter language code is between the domain name and the usual permalink structure. I’m using the %postname%
permalink structure, so all the following would be valid:
http://example.com/nl/about-us
http://example.com/de
http://example.com/fr/2012/03
http://example.com/es/this-is-a-post-title
If the current language is English, then no two letter code should be used (it will just be the normal permalink).
So far I have used the query_vars
filter to add a query var called lang
, but that’s sa far a I’ve got, I’m unsure what the next steps are. Any advice much appreciated!
Your question is complicated enough to answer by myself, but I would suggest you to install
qTranslate
plugin. As the plugin’s description says:So you can try to inspect the plugin’s code and see how they do it, or just use it at all.
This is the filter I’m using: