Recently, I’ve been thinking of implementing an easy and simple localization feature in my
WordPress site.
I thought about adding a custom taxonomy to my posts, and pages called “Languages.”
So when you click the link of the language it just filters the posts with that Language term.
I’ve been using WPML and it is awesome, but I just wanted an embedded implementation for my theme.
Have anyone tried this before?
What could be the pros and downsides of doing this?
The Pro: You can reuse native WP code.
Contra: You have to write your own taxonomy selector to avoid posts tagged with more than one language. The plugin Posts 2 Posts from @scribu should guide you to a more flexible approach.
I was facing a similar dilemma this week, and ended up creating a solution which I thought you might find useful.
I personally dislike the use of taxonomies for this purpose. I think the only pro is that it’s already built-in, and maybe it gives you a good out-of-the-box permalink structure, but it feels like a corruption of the taxonomies original purpose.
My approach is fairly self-sufficient and uses postmeta to store translations. All you would have to do to filter posts which have translations is to check for
_translate_content_{$lang}
post meta (e.g._translate_content_fr_FR
). I haven’t yet coded the front-end parts, but that should vary a lot according to what you want to do in your theme.Code is commented, but let me know if there is anything that’s not clear.
Note: I do this for pages only, but it should be easy to add posts to it as well. Also, keep in mind that I haven’t tested this with revisions, which I don’t use.