Shane Stillwell
Shane Stillwell

Reputation: 3248

Why is the gettext alias _() missing on OS X?

I'm running OS X Lion and some of my code uses the gettext alias of _() but I get this error

Fatal error: Call to undefined function _() 

Here is my env

PHP 5.3.6 with Suhosin-Patch (cli) (built: Jun 25 2011 10:41:21) 
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
      with Xdebug v2.1.1, Copyright (c) 2002-2011, by Derick Rethans

I tried using the php option suhosin.simulation = On but that didn't change anything so it doesn't seem to be the Suhosin-Patch.

Upvotes: 2

Views: 1807

Answers (2)

prosseek
prosseek

Reputation: 190979

I could install gettext a little bit simpler with the help from brew.

Installing ICU

  • brew install icu4c

Installing gettext

  • brew install gettext

Building the modules

Building ICU module

export PATH=$PATH:/usr/local/opt/icu4c/bin

./configure --enable-intl LDFLAGS='-L/usr/local/opt/icu4c/lib' CPPFLAGS='-I/usr/local/opt/icu4c/include'

Maybe the LD/CPPFLAGS settings are not necessary.

Building gettext module

./configure --enable-gettext

Copy the generated modules

copy the modules to php libraries directory (/usr/lib/php/extensions/no-debug-non-zts-XXXXX).

Restart apache

sudo apachectl restart

Upvotes: 0

Shane Stillwell
Shane Stillwell

Reputation: 3248

For the record... This is how you add gettext to OS X Lion

Installing ICU

Download ICU

Run these commands

tar xzvf icu4c-4_8_1-src.tgz
cd icu/source
./runConfigureICU MacOSX
make
sudo make install

Download PHP 5.3.6 sources

Run these commands

tar -zxf php-5.3.6.tar.gz
cd ext/intl
phpize
./configure --enable-intl
make
sudo cp modules/intl.so /usr/lib/php/extensions/no-debug-non-zts-20090626/

Put this in your php.ini file with

extension=intl.so

Installing Gettext

Download Gettext

Run these commands

tar -zxf gettext-0.18.1.1.tar.gz
cd  gettext-0.18.1.1

Apple will not ship Gettext and Intl the problem is that Gettext apparently defines Stpncpy function, as does something in Lion.

You need to open gettext-tools/gnulib-lib/stpncpy.c and change all references of stpncpy to stpncpy2

Then run these commands

./configure
make
sudo make install

Go back to the PHP sources directory:

Run these commands

cd ext/gettext
phpize
./configure --with-gettext
make
sudo cp modules/gettext.so /usr/lib/php/extensions/no-debug-non-zts-20090626/

And add this to the php.ini file:

extension=gettext.so

References: http://www.ittreats.com/os/php/php-with-intl-and-gettext-on-osx-lion-bertrand-mansion.html

Upvotes: 6

Related Questions