Asked  2 Years ago    Answers:  5   Viewed   61 times

I am currently researching the best methods to integrate i18n into projects.

There's several methods I have thought of doing this, first being a database scheme to store the strings and relevant locale, but the problem with this is that it would not be that easy to select the strings, because i would not like to perform quesries like so:

SELECT text FROM locales WHERE locale = 'en_GB' AND text_id = 245543

Or

SELECT text FROM locales WHERE locale = 'en_GB' AND text_primary = 'hello'

The next method would be to store them within files such as locales/en_gb/login/strings.php and then try and access them via an class specifically developed like so:

$Language = Registry::Construct('Language',array('en_GB'));
echo $Language->login->strings->hello;

The issue with this is I would have to build a system that would update these files via an administration panel witch is very time consuming, not just building the system to manage the strings but actually managing the strings as the site grows

  • What other methods are there that will be beneficial for a large system
  • Is there any automated way to do 'Translation' as such
  • Should I stick with a database method and build a system for users to translate strings with rating / suggest better version ?
  • What systems have you tried in the past and should I look into them or totally avoid them.

 Answers

5

In addition to gettext already mentioned, PHP 5.3 has native Internationalization support

If that's not an option, consider using Zend Framework's Zend_Translate, Zend_Locale and related components for that. Zend_Translate supports a number of adapters, including but not limited to simple arrays, gettext, XmlTm and others.

Tuesday, November 29, 2022
3

As discussed in the comments, the gettext extension relies on the standard locale specifiers containing the language and region code, i.e. ja_JP for "Japanese in Japan" or with the specified encoding ja_JP.utf-8. Even if there is an alias like japanese, the PHP implementation of gettext does not accept this. Note that the locale has to be installed and configured on your system.

Language and region specifiers can be found in IANA language-subtag-registry

This code already should work for the Japanese language:

$dir     = $_SERVER['DOCUMENT_ROOT'] . '/locale';
$domain  = 'messages';
$locale  = 'ja_JP.utf8';
$codeset = 'UTF-8';

setlocale( LC_MESSAGES, $locale);
bindtextdomain($domain, $dir);
textdomain($domain);
bind_textdomain_codeset($domain, $codeset);

Remember to also rename your directory into locale/ja_JP.utf8. Ensure your .po files are stored with the correct encoding, i.e. UTF-8 in this example, and contain the line

"Content-Type: text/plain; charset=UTF-8n"

(as you already have done).

Tuesday, August 9, 2022
 
discdev
 
4

Yes, IIRC, you need to have locale on the system to make it work.

Sunday, December 11, 2022
 
4

If you are using apache2.4 and PHP 7, run

sudo apt-get install php-mbstring php7.0-mbstring php-gettext

then restart your server

sudo service apache2 restart
Sunday, October 23, 2022
 
mack
 
4

I ran into the same issue and found the following solution in the documentation: http://symfony.com/doc/current/book/testing.html#your-first-functional-test

To run your functional tests, the WebTestCase class bootstraps the kernel of your application. In most cases, this happens automatically. However, if your kernel is in a non-standard directory, you'll need to modify your phpunit.xml.dist file to set the KERNEL_DIR environment variable to the directory of your kernel:

<phpunit>
    <!-- ... -->
    <php>
        <server name="KERNEL_DIR" value="/path/to/your/app/" />
    </php>
    <!-- ... -->
</phpunit>

So check your phpunit.xml.dist configuration file and try to add the absolute path to your app-directory.

Hope it helps.

Tuesday, November 1, 2022
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 

Browse Other Code Languages