Ricky55 Posted August 10, 2012 Share Posted August 10, 2012 Hi I have a static website that uses some basic PHP, includes, changing titles, conditionally loading CSS and JS files etc but no database. What would be the best way to show this website in four different languages? Just wondered if any of you guys have had to do that without using a CMS. Thanks Richard Quote Link to comment Share on other sites More sharing options...
Christian F. Posted August 10, 2012 Share Posted August 10, 2012 I use a template engine for this. I store all of the common (and short) text in a language file, and read it when I generate the template object. For bigger texts it supports localized versions of the template files, so that I can have one file named "info_no.php" and one that's named "info_en.php" and the script picks the best suited one. So, no. You won't need a CMS or a database for this, but you will need a template engine. Quote Link to comment Share on other sites More sharing options...
Adam Posted August 10, 2012 Share Posted August 10, 2012 So, no. You won't need a CMS or a database for this, but you will need a template engine. Why? @Ricky55 I'm guessing given that you're not using a framework, you have some kind of 'master' include file? In there I would just construct an object with the user's language and a translation array (if not English). Then whenever you output text just pipe it through a method in the object: <p><?php echo $lang->t('Some text here.') ?></p> If the user's language is English, or your default language, it would do nothing but return the string. If another language it would attempt to look it up in the translation array. The array could simply be created from a JSON file: translations/fr.json { "Some text here.": "Certaines parties du texte ici." } (Thanks Google translate!) Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted August 11, 2012 Share Posted August 11, 2012 IMO I like keywords better, but I might do it something like this: $lang = array( "KEYWORD1" => array( "This is English", "This is Spanish", "This is Chinese" ), "KEYWORD2" => array( "This is a second English keyword", "This is a second Spanish keyword", "This is a second Chinese keyword" ) ); Quote Link to comment Share on other sites More sharing options...
Adam Posted August 11, 2012 Share Posted August 11, 2012 Why? That just adds an overhead to the native language and forces you to define two uniques for each translation. Quote Link to comment Share on other sites More sharing options...
xylex Posted August 12, 2012 Share Posted August 12, 2012 Easiest (but not the cheapest) way to do this is to hand it off to someone else. Companies like translations.com offer services that will run a proxy in front of your website and serve a human translated version of it. They basically use a scraper to get all of your site content, build out a human translated translation memory from that, and then dynamically do a search/replace of your content as it's served from their proxies. And if you are going to build something in PHP to do this, look at the built in gettext() library. That's based off an industry standard so it's easy to find 3rd parties and tools to manage your translation bundles. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted August 13, 2012 Share Posted August 13, 2012 or... you could use Google.... Options +FollowSymlinks RewriteEngine On RewriteBase / RewriteRule ^(.*)-(fr|de|es|it|pt)$ http://www.google.com/translate_c?hl=$2&sl=en&u=http://site.com/$1 [R,NC] Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 13, 2012 Share Posted August 13, 2012 I second the templates. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.