Translating your website can be the most time consuming thing to do if you are supporting other languages for a more global audience and to do that, you require a system that you can easily keep building and translate your strings later without having to go back and replace all the strings that requires a function to load the language the visitor wishes to read your website in.
WordPress is one example of a system that allows developers to provide either there themes or plug-ins in several languages by simply translating a file that stores all the strings side by side (original / translation) of each other. If a string is not translated it will load the original string.
I have created a similar function that you can use for your site if it is coded in PHP.
Simply copy and paste this function in the file you wish to store it.
function text($pages,$string){
global $page;
if($page[$pages][$string] == ''){
$loadString = $string;
}
else{
$loadString = $page[$pages][$string];
}
echo $loadString;
}
To use it, simply write:
<?php text('pagename', 'Your text string goes here.'); ?>
Now you are wondering what do I change ‘pagename’ too. That’s easy, if the string is on the homepage only then you would put ‘homepage’ in place of ‘pagename’. If the string is something that is shared or loaded on every page like your menu navigation then you would put ‘mainnavigation’ in place instead.
How do I translate my strings?
First you need a new file created and saved as the default strings you are going to produce translations of i.e. ‘default.php‘ .
Now you write your strings like so:
<?php
$page['homepage']['Welcome to my website.'] = 'Welcome to my website.';
?>
Copy the default strings file and save it as another language i.e. ‘japanese.php‘ . Now you can translate the strings in the new language like so:
<?php
$page['homepage']['Welcome to my website.'] = '私のウェブサイトへようこそ.';
?>
And that’s it. How you decide to load your language files on your site is up to you.
Good luck.
If you liked this post, why don’t you share it with others using Twitter, Facebook, Digg or Stumbleupon on the right hand side or subscribe below to receive new posts in your email.
Continue Reading