Tutorial: How to localize concrete5 WITHOUT php 'gettext' enabled

Permalink 2 users found helpful
Hi there,

I spent several hours to get concrete5 with a correct localization working on a shared-hoster of a client with the required php-'gettext'-module disabled and no ability to edit the php.ini. So if that's what you have to face, you might continue reading.

On the other hand, it might be possible that you have the php-gettext module installed and activated on your server, but you not able to restart Apache (e.g. shared-hoster) which can be necessary to switch language-files. Solution for that is included here, too. I'll start all over with a complete tutorial for absolute beginners.

#################################################
Start
#################################################

1) Download the latest version of your language-file fromhttp://sourceforge.net/project/showfiles.php?group_id=225586... and extract it

2) Download poEdit fromhttp://www.poedit.net/download.php... and install it. Open the 'messages.po'-File with poEdit and save it. Might be possible that some error-messages appear - so don't worry ;). A 'messages.mo'-File should be created in the same directory of the opened 'messages.po'-file.

3) Create a folder with the name of your language (e.g. de_DE or fr_FR) in the /languages - directory. In this folder, you create a folder called 'LC_MESSAGES' and that's where you upload the created 'messages.po'-File, so that the structure looks like 'language/xx_XX/LC_MESSAGES/messages.po'.

4) Edit or (if not present: add) the line
define('LOCALE', 'xx_YY');

(again with your language-Code from above) into the file 'config/site.php'. I'm assuming that you already have installed conrete5, otherwise you'll also have to change the file 'concrete/config/base.php' at the point
if (!defined('LOCALE')) {
define("LOCALE", 'xx_YY');
}

5) Now it's becoming interesting. Download the latest version of php-gettext (an additional php-script, that emulates gettext), which you can find here:http://www.very-clever.com/download/nongnu/php-gettext/... and extract it

6) Create a folder 'gettext' in concrete/libraries/ and upload the 3 files 'gettext.inc', 'gettext.php' and 'streams.php' from the archive you downloaded in step 5, so that the absolute path on your server will be 'concrete/libraries/gettext/gettext.inc' and so on.

7) Open the file 'concrete/dispatcher.php' and add the line
require "libraries/gettext/gettext.inc";

just before the line
Loader::database();

8) Log into your concrete5-Backend and clear the cache (settings -> debug -> clear cache) - you should be done.

#################################################
Problem: You have gettext on your server but no permission to restart Apache
#################################################

9) What? Why another point when we're already done? Hm. As I mentioned in the beginning, i promised to provide a solution for those, who have the gettext-library installed and running on their server, but can't restart the apache to get a new language-file working. So if that's your problem, you might continue reading, otherwise: Lean back und be happy ;). When gettext is already running on your server, the translation-functions used by concrete5 are similar to the function-names of the php-gettext-script, so that the 'native' functions will still be the ones being called. To fix this problem, the php-gettext-script comes up with alias-function names, which can be called in the case that gettext is already installed and you want to use the php-gettext-script even though - which is our case. Those mentioned alias-functions start with T_, so for example the main-function gettext (which is already in use by the 'native' gettext) is also availible under T_gettext, which will definitely call the php-gettext-script's version. There are a few functions, which you have to rename to ensure that all translation-function-calls are sent to the php-gettext-script and not the the native php-gettext. If you are interested in more details related to gettext, you should check out this fabulous guide (in german):http://phpmagazin.de/itr/online_artikel/psecom,id,874,nodeid,62,_la...

10) Okay, having explained enough, we better continue. Open the file 'concrete/libraries/localization.php' and replace all function calls of gettext(...) with T_gettext(...), textdomain(...) with T_textdomain(...), _(...) with T_(...), bindtextdomain(...) with T_bindtextdomain(...) and bind_textdomain_codeset(...) with T_bind_textdomain_codeset(...). Don't forget to also change line 3
return function_exists('textdomain');

to
return function_exists('T_textdomain');

Finally, you have to outcomment the part
if (!Localization::isAvailable()) {
function gettext($string) {return $string;}
function _($string) {return $string;}
}

and you should be done.

#################################################
Finished
#################################################

Don't hesitate to ask if i have explained something kinda difficult ;).

 
katz515 replied on at Permalink Reply
katz515
Thanks.

One Japanese guy also made gettext.php here

http://jo1upk.blogdns.net/saito/?%e8%87%aa%e4%bd%9c%2FPHP%2Fgettext...

I'll compare your method and his method.
Currently, I have no server without gettext installed. So this will be my next step after 5.3 releases.

According to a source, if you use his gettext.php.... you only have to modify dispatcher.php on line 10:

if (! extension_loaded('gettext')) {
require('gettext.php');}


I haven't had time to try it. Hopefully somebody else has a server without gettext and time to try out.
dmueller replied on at Permalink Reply
You also don't need to change anything else with "my" (the official) version of php-gettext if you haven't got gettext installed "native" on your server. The whole rest is just the general configuration of the concrete5-language files and the alternative method, if you have gettext installed but aren't able to restart apache.
require "libraries/gettext/gettext.inc";
will do the job as those file automatically checks if gettext is loaded (then: use gettext native) oder if it isn't (emulate gettext) - so there is no problem to use gettext and the gettext-script on the same server.

regards
mod7609 replied on at Permalink Reply
tanks dmueller

tanks tanks