views:

245

answers:

1

I have a custom directory, eg /www/phpstuff which is in my include_path. Inside of this phpstuff directory is a folder i18n. It contains server-side level .mo files.

Zend_Translate lets you specify a directory in the second parameter of the constructor, I can't really do

Zend_Translate( 'gettext', 'i18n/', 'en' );

It tries to read from the directory in which this script is invoked, is there any sort of trick I can use to not have to specify /www/phpstuff/i18n explicitly? Reason being this framework I'm working with will be used across many different platforms, and it would be easier specifying a directory in an include_path than an absolute path.

The only workaround I can come up with is manually reading the include path, splitting by the separator, checking if any of the directories are named 'gettext' and then grab the absolute path of the first directory found and set it.

+1  A: 

You'll need to define the application path somewhere. If you don't want to set an absolute path, you'll need to set a relative path. Take this dir structure for example:

/application/
/application/i18n/
/public_html/
/public_html/index.php

The application path in this case would be:

define('APPLICATION_PATH', '../application');

And you can use it like this:

Zend_Translate( 'gettext', APPLICATION_PATH . '/i18n', 'en' );

Hope that helps.

Basher
Yeah, but this is still application specific. What if I wanted to use the same .mo files for multiple applications, so I can update one mo file and it would reflect on all of them?
meder
Put the i18n folder somewhere out of the application and define a path to it. The question is not where you put the i18n folder but that you define a path somewhere that is specific to the application.
Basher
I get what you're saying, but I'm not using Zend primarily for this application - only utilizing the Zend_Translate, and regardless I'm trying to implement these across multiple servers, I can't just put the i18n in the parent's parent directory of all my applications as sometimes it's inconsistently structured... I guess that leaves me with no choice but to define an absolute path constant and use it.
meder