0

I would like to know what you think about the way I deal with the PHP multi-language feature for my website.

First, I recover a variable $config['UserLang'] which contains the language. I recover it from the $_SESSION or from the database if the user is connected and has specified a language.

$config['UserLang'] = 'fr';

Then I open a file containing constants of the language:

require_once ('include/langs/'.$config['UserLang'].'.inc.php');

In the directory include/langs I have as many files as available languages, for example: en.inc.php, fr.inc.php and es.inc.php

And for example, the content of en.inc.php will be:

define("LANG_HOME_home", "Home");
define("LANG_HOME_contact", "Contact us");
define("LANG_HOME_phone", "Our phone");
define("LANG_HOME_address", "Our address");
define("LANG_HOME_desc", "Some description of the company <br> Another line about the company");

And then, when I display the DOM:

echo '
<div class="pad-t-20 txt-c">
    '.LANG_HOME_desc.'
</div>';

It's working fine bu is there anything I could to to improve it? Is there any other way which would be more conventional?

Thanks.

2
  • this (a small i18n-class) might by helpful: github.com/Philipp15b/php-i18n Commented Dec 11, 2016 at 15:33
  • Yes, I have to take a look at this scipt Commented Dec 11, 2016 at 15:52

1 Answer 1

1

Don't reinvent the wheel and use Gettext that is de facto standard for i18n and has strong support in PHP and PHP frameworks.

You can see tutorial here or here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.