how to solve or make website in dual language with all content.
i want make website in two language (Gujarati Or English).
it can possible in single database?.how?.
please give me proper logically solution. i can't understand that how to code it.
thank you so much.

Member Avatar for diafol

Many methods available to you. If you're using a cms like Wordpress, this functionality should be built-in or there may be a specific plugin or module that you can use.

If you're developing your own solution you could use either database or files for your storage and you have a nultitude of formats for the data. I perhaps would avoid the DB approach for now as it can become quite difficult to maintain unless you get the schema exactly right and you have a n easy way to update translations.

Anyway. For file based storage, you can save your data in one language file for english (lang/en.php) and one for gujarati (lang/gu.php) or if the thought of loading all the translation strings for every page is a bit much, you could split the translations into various files...

lang/en/
    common.php
    home.php
    about.php
    contact.php
    profile.php
lang/gu/
    common.php
    home.php
    about.php
    contact.php
    profile.php

The problem with all these is that ensuring that all strings are added at the same time or you could end up with more strings in one translation than the other. To overcome this problem you could load the default (complete) language and then "merge" with the chosen language (if different), that way you get the default language string where the chosen langauge string doesn't exist. This of course does not cover changes made to exisiting strings. Hence the headache for keeping translations "in sync".

Databases could in fact solve this problem with a "updated_at" field, so you could check to see if a translation in a secondary language was older (not synched) than the default language or otherwise.

How you'd store your data is a matter of preference. Some like straight php arrays, e.g.

en.php

$lang = array(
    'author' => 'diafol'
);

gu.php

$lang = array(
    'author' => 'શેતાન'
);

Obviously you'd have more than just the one item in the arrays. Other systems use XML, JSON or YAML formats.

You could also use GETTEXT with .pot/.po files. This can be a bit of a pain to set up (see my diafolCode link - I have a few articles on this - but it's an old site not active any more), but I quite like it as I can open up PoEdit and scan for new or updated translations.
If you weren't aware, this is pretty cool as you pretty much write your text in the default language, add a few tags around it and that's it - PoEdit will pick this up and offer it as a new translation for you to translate. Nice.

Actually identifying which language to use should be straightforward - make it obvious in the url, e.g.

www.example.com/en/about
www.example.com/gu/about

These would translate to $_GET['langurl'] if you set up your .htaccess to do so (see Apache mod_rewrite).

Armed with that, you then are able to do...

$langurl = $_GET['langurl']; //check the langauge is valid though
require "lang/$langurl/common.php";
require "lang/$langurl/about.php";

You will then be able to use:

<p><?php echo $lang['author'];?></p>

I've seen people use session-based language variables - which is fine, but the language is not displayed in the url. It probably hurts SEO not to show this.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.