WordPress in two (or more) languages

Browsing the internet, I noticed the necessity to have a blog in two or more languages. It’s a necessity I’m having too, so the first thing I did was a search into the official WordPress plugin repository, convinced that the solution to my problem was a few clicks away.

I was much, much wrong.

Anyway I observed all tricks and plugins developed in order to solve this WordPress deficiency.
Let’s see them and discover their weak points.
During the following examples I will consider the idea to create a blog in two languages, even if the same concept can be widened to a number of n languages.

Creation of two different blogs, with a homepage showing a language selection
It’s the simplest solution, anyway lacks the capability to switch form one language to another from the inside of the blog.

Creation of a button with a link to Babelfish or another service of online translations
Online translation services aren’t yet that smart to expect of being able to translate posts much more complex than “Hello world” without losing the sense of the post.

“Polyglot” plugin and other plugins inspired by it
It’s the best solution at the moment, even if lacks some options like comment separation based on their language.

No one of those systems however resolved my requirement, consisting in two distinct blogs (even hosted on two different domains), where not necessarily every page of the blog A had a correspondence in blog B, but if it should eventually exists, was reachable by a hypertext link.

Having installed WP two days ago, I do not have the required knowledge (neither the time) in order to develpo a plugin, anyway I promise to make it in a quiet moment of my work (translation: never ever), and I hope however that my small intuition shall open the way to the creation of a well coded plugin.

What do we need for having a blog in two languages?

Ingredients are:
2 images of small flags
2 installations of WordPress completely independent (two different domains, or two different databases)
1 new table in database
A bit of php coding

About the flag icos, I think you can easily draw or find them in the web.
Personally, I love these ones.

As far as the installation of WordPress, being a neophyte I cannot help you very much… just install it and eventually customize it to display the sidebar on every page, because in my example we’ll see how to change sidebar content to insert the language change link.

Let’s start with the new table

CREATE TABLE `wp_language_jump` (
  `id` int(11) NOT NULL auto_increment,
  `page` text NOT NULL,
  `link_to` text NOT NULL,

where the interesting columns are “page” that will contain the address of the page in which inserting the link, and “link_to” that will contain the link (or links) to which page we want to publish the translation.

In a practical example I installed one version of WP in root of http://www.emanueleferonato.com/ and another in “ita” directory href=”http://www.emanueleferonato.com/ita”>www.emanueleferonato.com/ita. I want that from each of two blogs page there is a link to its proper translation, and in the same way I will deal with all future pages.
The row I inserted in the table is:

INSERT INTO `wp_language_jump` VALUES (1, '/index.php/', '/ita/');

Which communicates that from the homepage (index.php) I want to link to the italian blog homepage.
My links should be different than yours because I used “date and name based” permalink structure, please refer to documentation supplied with WP in order to understand what type of links (or permalinks) you used, even if as far as I can see more than 90% of blogs have a links structure like mine.

In the same way I want the italian homepage to link to english one, so the row is:

INSERT INTO wp_language_jump VALUES (2, '/ita/index.php/ita/', '/');

Subsequently you can insert all page link translations you want.
Now let’s see the php script. I want my link to be at the top of sidebar, so I am going to edit sidebar.php from WP administration panel, menu Presentation -> Theme Editor -> WordPress Default theme files.
You are obviously free to choose where to insert the script.
I did it after

that is just at the beginning of the sideba. The script is:

  •  English version
  • Let’s explain it line by line.

    1: I insert an element in the list that composes the sidebar; in this way my link of change language will be the first element displayed in the sidebar. You can insert the script wherever you want, I was working on the theme I have currently installed, Kubrick if I am right… (although I installed WP a few time ago, I begin to practice).

    2: Rock and roll! I open Php tag.

    3: I connect to database. I am sure there are already lot of functions to connect to a WP database, but I don’t know them so I connect with the appropriate command.

    4: Choosing the db… same considerations as line 3

    5: Get the path of the page I am browsing by using predefined php variables. You will find a complete reference at this page. This line may need to be adapted to your permalink type.

    6: Creates a MySql query to verify the presence of the path in the table we created before

    7: Executing the query. Same considerations as line 3

    8: I put the (first) row of the query result in an array. Notice that this simple script does not handle the case that the table does not contain current path. It will be a “future feature”, that sounds like “no way”.

    9: The script is over…

    10: Creation of the graphical/text link for the language exchange, calling at the right time the content of the query I have processed before.

    11: Closing list tag

    As you can see, in a few lines, even if in a “WP extremely UNfriendly” way, I managed to create an automatic link between two blogs in two different languages without modifying post structure with any tag.

    There are a lot of improvements to do, for example a control if a translated pages exists or not, additional columns where to insert link title, or image… and so on (and this “and so on” is HUGE). At the moment, that’s the most important thing to consider, it WORKS. Try the link in the sidebar and believe.

    Now the ball passes to volounteers that want to adapt – or transform – or delete (best way) – this script to make it a real WP plugin.

    That’s all folks, I think that this first post in something more than an “Hello World”.

    Get the most popular Phaser 3 book

    Through 202 pages, 32 source code examples and an Android Studio project you will learn how to build cross platform HTML5 games and create a complete game along the way.

    Get the book

    // 1+2=3
    // 100 rounds
    // 10000000
    // 2 Cars
    // 2048
    // A Blocky Christmas
    // A Jumping Block
    // A Life of Logic
    // Angry Birds
    // Angry Birds Space
    // Artillery
    // Astro-PANIC!
    // Avoider
    // Back to Square One
    // Ball Game
    // Ball vs Ball
    // Ball: Revamped
    // Balloon Invasion
    // BallPusher
    // Ballz
    // Bar Balance
    // Bejeweled
    // Biggification
    // Block it
    // Blockage
    // Bloons
    // Boids
    // Bombuzal
    // Boom Dots
    // Bouncing Ball
    // Bouncing Ball 2
    // Bouncy Light
    // BoxHead
    // Breakout
    // Bricks
    // Bubble Chaos
    // Bubbles 2
    // Card Game
    // Castle Ramble
    // Chronotron
    // Circle Chain
    // Circle Path
    // Circle Race
    // Circular endless runner
    // Cirplosion
    // CLOCKS - The Game
    // Color Hit
    // Color Jump
    // ColorFill
    // Columns
    // Concentration
    // Crossy Road
    // Crush the Castle
    // Cube Jump
    // CubesOut
    // Dash N Blast
    // Dashy Panda
    // Deflection
    // Diamond Digger Saga
    // Don't touch the spikes
    // Dots
    // Down The Mountain
    // Drag and Match
    // Draw Game
    // Drop Wizard
    // DROP'd
    // Dudeski
    // Dungeon Raid
    // Educational Game
    // Elasticity
    // Endless Runner
    // Erase Box
    // Eskiv
    // Farm Heroes Saga
    // Filler
    // Flappy Bird
    // Fling
    // Flipping Legend
    // Floaty Light
    // Fuse Ballz
    // GearTaker
    // Gem Sweeper
    // Globe
    // Goat Rider
    // Gold Miner
    // Grindstone
    // GuessNext
    // Helicopter
    // Hero Emblems
    // Hero Slide
    // Hexagonal Tiles
    // HookPod
    // Hop Hop Hop Underwater
    // Horizontal Endless Runner
    // Hundreds
    // Hungry Hero
    // Hurry it's Christmas
    // InkTd
    // Iromeku
    // Jet Set Willy
    // Jigsaw Game
    // Knife Hit
    // Knightfall
    // Legends of Runeterra
    // Lep's World
    // Line Rider
    // Lumines
    // Magick
    // MagOrMin
    // Mass Attack
    // Math Game
    // Maze
    // Meeblings
    // Memdot
    // Metro Siberia Underground
    // Mike Dangers
    // Mikey Hooks
    // Nano War
    // Nodes
    // o:anquan
    // One Button Game
    // One Tap RPG
    // Ononmin
    // Pacco
    // Perfect Square!
    // Perfectionism
    // Phyballs
    // Pixel Purge
    // PixelField
    // Planet Revenge
    // Plants Vs Zombies
    // Platform
    // Platform game
    // Plus+Plus
    // Pocket Snap
    // Poker
    // Pool
    // Pop the Lock
    // Pop to Save
    // Poux
    // Pudi
    // Pumpkin Story
    // Puppet Bird
    // Pyramids of Ra
    // qomp
    // Quick Switch
    // Racing
    // Radical
    // Rebuild Chile
    // Renju
    // Rise Above
    // Risky Road
    // Roguelike
    // Roly Poly
    // Run Around
    // Rush Hour
    // SameGame
    // SamePhysics
    // Save the Totem
    // Security
    // Serious Scramblers
    // Shrink it
    // Sling
    // Slingy
    // Snowflakes
    // Sokoban
    // Space Checkers
    // Space is Key
    // Spellfall
    // Spinny Gun
    // Splitter
    // Spring Ninja
    // Sproing
    // Stabilize!
    // Stack
    // Stairs
    // Stick Hero
    // String Avoider
    // Stringy
    // Sudoku
    // Super Mario Bros
    // Surfingers
    // Survival Horror
    // Talesworth Adventure
    // Tetris
    // The Impossible Line
    // The Moops - Combos of Joy
    // The Next Arrow
    // Threes
    // Tic Tac Toe
    // Timberman
    // Tiny Wings
    // Tipsy Tower
    // Toony
    // Totem Destroyer
    // Tower Defense
    // Trick Shot
    // Tunnelball
    // Turn
    // Turnellio
    // TwinSpin
    // vvvvvv
    // Warp Shift
    // Way of an Idea
    // Whack a Creep
    // Wheel of Fortune
    // Where's my Water
    // Wish Upon a Star
    // Word Game
    // Wordle
    // Worms
    // Yanga
    // Yeah Bunny
    // Zhed
    // zNumbers