LMSouq
php-dev Open

Use PHP Gettext without having to install locales

CO
Community Contributor
1 month ago
3 views
Problem Description
I've been looking at options for internationalizing an open source project: * Gettext, which everyone seems to recommend, apparently needs locales to be "installed on your system" to be used. See this [note](http://www.php.net/manual/en/book.gettext.php#91187) on the PHP manual, which reflects exactly my situation. This [SO question](https://stackoverflow.com/questions/3398113/php-gettext-problems) also asks about the same problem. This isn't suitable for an open source project because I can't trust that the end users have the appropriate locales installed on their system. Besides, it's very very weird that you have to install locales just to use strings that you've translated (IMO). * Zend_Translate is also recommended in favour of gettext sometimes, but I'm not using the Zend framework so I don't think it's an option for me. Some people have said you can split it from the Zend framework, but I'd have no clue how. If anyone can tell me what files I need (I've downloaded a tarball of the Zend framework) to pick out, I would be open to using Zend_Translate. * Arrays. That's what I'm doing now, but it's not ideal because: * It will be using up lots of memory to define every translation, when most won't be used by the current page. * I am having problems with finding myself duplicating the keys in the array, which has already become 1000 lines of code long and I've barely added anything yet... * It means non-programmers can't really translate, whereas POedit is the standard that everyone expects to use. Can I somehow read `.mo` files without Gettext or Zend_Translate, or must I use Gettext? If so, how can I make all locales work, like in the question I linked to above? EDIT: I'm now willing to use Zend_Translate. I just need to work out what files I need (it would be great if they could be combined into one file) - I don't want the entire Zend Framework in my project....

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base