Jump to content

completely lost with gettext


Darghon

Recommended Posts

Hello all,

 

i'm attempting to implement i18n into my project.

so I read some tutorials, copied some code and eventually made the following:

/**
 * applyMultiLingual uses the gettext module from PHP to support multilingual
 * @param Array $settings 
 */
private static function applyMultiLingual($settings){
	/* init global config */
	bindtextdomain(self::$project_name,Config::path('i18n'));
	bind_textdomain_codeset(self::$project_name, 'UTF-8');
	textdomain(self::$project_name);

	if(!array_key_exists('enabled', $settings) || $settings['enabled'] == false){
		//initiate default (english)
		putenv("LC_MESSAGES=en_EN");
		setlocale(LC_MESSAGES,'en_EN');
	}
	else{
		if(Session::language() === null){
		//initiate custom
			if($settings['default'] == 'auto'){ locale::acceptFromHttp($header); }
			else{ putenv("LC_MESSAGES=".$settings['default']);setlocale(LC_MESSAGES,$settings['default']); }
		}
		else{
			putenv("LC_MESSAGES=".Session::language());
			setlocale(LC_MESSAGES,Session::language());
		}
	}
}

 

The code is (imo) pretty readable, so it sets the textdomain to "project1", and the current language to en_EN.

if should search for the translations in DOC_ROOT/i18n/

 

now, it returns the text between the _(); functions, but I get no translation files in said directory, and I also have no clue how to accomplish this.

 

so what I want to accomplish is this:

enable use of function _(), which saves all translations in a folder i18n, and subfolder LOCALE_CODE (ex. DOC_ROOT/i18n/en_EN/messages.po).

 

what am I doing wrong, and how can I fix it?

 

thx to any who can help, and if more info is needed, ask and you shall receive.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.