php 如何在 MacOS X 上安装 gettext

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14940383/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 08:14:48  来源:igfitidea点击:

How to install gettext on MacOS X

phpmacos

提问by aharris88

How do I install gettext on mac?

如何在 mac 上安装 gettext?

I get this error on one of my php pages:

我在其中一个 php 页面上收到此错误:

Fatal error: Call to undefined function bindtextdomain()

and it's because I don't have gettext installed.

这是因为我没有安装 gettext。

I can't find good instructions on how to install it. I've tried using:

我找不到有关如何安装它的好的说明。我试过使用:

brew install gettext

and it puts some files here:

它把一些文件放在这里:

/usr/local/Cellar/gettext/0.18.2

/usr/local/Cellar/gettext/0.18.2

but I don't know what to do with that.

但我不知道该怎么办。

Update: Instead of trying to use homebrew, now I tried this method unsucessfully using wget:

更新:现在我没有尝试使用自制软件,而是使用 wget 尝试了此方法失败:

Download with wget

用 wget 下载

cd ~/Downloads
wget http://ftp.gnu.org/gnu/gettext/gettext-0.18.2.tar.gz
tar -zxvf gettext-0.18.2.tar.gz
cd gettext-0.18.2
./configure
make

make check is optional to run self-tests

make check 是运行自检的可选选项

make check

Errors I got:

我得到的错误:

make[3]: *** [check-TESTS] Error 1

make[3]: *** [check-TESTS] 错误 1

make[2]: *** [check-am] Error 2

make[2]: *** [check-am] 错误 2

make[1]: *** [check-recursive] Error 1

make[1]: *** [check-recursive] 错误 1

sudo make install

That installs it here: /usr/local/share/gettext

在这里安装它:/usr/local/share/gettext

And the documentation here: /usr/local/share/doc/gettext

和这里的文档:/usr/local/share/doc/gettext

but how do I make my php pages be able to use gettext and the bindtextdomain() function?

但是如何让我的 php 页面能够使用 gettext 和 bindtextdomain() 函数?

采纳答案by aharris88

I finally got it. You have to reconfigure php, so I ended up upgrading from 5.3.15 to 5.4.12. These websites were very helpful:

我终于明白了。你必须重新配置 php,所以我最终从 5.3.15 升级到 5.4.12。这些网站非常有帮助:

http://mac.tutsplus.com/tutorials/server/upgrading-the-native-php-installation-on-os-x-mountain-lion/

http://mac.tutsplus.com/tutorials/server/upgrading-the-native-php-installation-on-os-x-mountain-lion/

http://mansion.im/2011/php-with-intl-and-gettext-on-osx-lion/

http://mansion.im/2011/php-with-intl-and-gettext-on-osx-lion/

#Install dependencies
brew install libjpeg
brew install pcre
brew install libxml2
brew install mcrypt

#Get autoconf just because
brew install autoconf

#Install Intl extension
#Install ICU
#Download from http://site.icu-project.org/download/48#ICU4C-Download
cd ~/Downloads
tar xzvf icu4c-4_8_1-src.tgz
cd icu/source
./runConfigureICU MacOSX
make
sudo make install

cd ~/Downloads/php-5.4.12/ext/intl
phpize
./configure --enable-intl
make
sudo cp modules/intl.so /usr/lib/php/extensions/no-debug-non-zts-20090626/

#Install gettext
#Download from http://ftp.gnu.org/gnu/gettext/
cd ~/Downloads
tar xzvf gettext-0.18.1.1.tar.gz
cd gettext-0.18.1.1
./configure
make
sudo make install

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

#Add intl and get text to php.ini
cd ~/Downloads/php-5.4.12
nano php.ini-development
#Add these lines
extension=intl.so
extension=gettext.so

#Download PHP source files from php.net
cd ~/Downloads
tar xzvf?php-5.4.12.tar.bz2
cd php-5.4.12

./configure \
--prefix=/usr \
--with-gettext \
--mandir=/usr/share/man \
--infodir=/usr/share/info \
--sysconfdir=/private/etc \
--with-apxs2=/usr/sbin/apxs \
--enable-cli \
--with-config-file-path=/etc \
--with-libxml-dir=/usr \
--with-openssl=/usr \
--with-kerberos=/usr \
--with-zlib=/usr \
--enable-bcmath \
--with-bz2=/usr \
--enable-calendar \
--with-curl=/usr \
--enable-dba \
--enable-exif \
--enable-ftp \
--with-gd \
--enable-gd-native-ttf \
--with-icu-dir=/usr \
--with-iodbc=/usr \
--with-ldap=/usr \
--with-ldap-sasl=/usr \
--with-libedit=/usr \
--enable-mbstring \
--enable-mbregex \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--without-pear \
--with-pdo-mysql=mysqlnd \
--with-mysql-sock=/var/mysql/mysql.sock \
--with-readline=/usr \
--enable-shmop \
--with-snmp=/usr \
--enable-soap \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--with-tidy \
--enable-wddx \
--with-xmlrpc \
--with-iconv-dir=/usr \
--with-xsl=/usr \
--enable-zip \
--with-imap=/usr/local/imap-2007 \
--with-kerberos \
--with-imap-ssl \
--enable-intl \
--with-pcre-regex \
--with-pgsql=/usr \
--with-pdo-pgsql=/usr \
--with-freetype-dir=/usr/X11 \
--with-jpeg-dir=/usr \
--with-png-dir=/usr/X11

make test
sudo make install

#Restart Apache
sudo apachectl restart

回答by Gabriele Petronella

You can use brewto link gettext after installing it

brew安装后可以使用链接gettext

brew install gettext
brew link --force gettext

回答by mbritto

I found an easiest working solution, which still works on mavericks. Here it is: https://stackoverflow.com/a/11792640/512504

我找到了一个最简单的工作解决方案,它仍然适用于小牛。这是:https: //stackoverflow.com/a/11792640/512504

回答by Ben

If reinstall php is acceptable, try to download and install the php version you want from here.

如果可以重新安装 php,请尝试从这里下载并安装您想要的 php 版本。

In my case, I used 7.0 version. Steps to reinstall:

就我而言,我使用了 7.0 版本。重装步骤:

  1. Open terminal and run curl -s https://php-osx.liip.ch/install.sh | bash -s 7.0
  2. The installed php will reside at /usr/local/php5-7.0.31-20180903-120321/lib(I'm not sure why the directory name is php5-7xxxx, but the installed php version is 7.0)

  3. Edit apache2 config at /private/etc/apache2/httpd.conf(make a backup if necessary)

  4. Replace LoadModule php7_module libexec/apache2/libphp7.sowith LoadModule php7_module /usr/local/php5-7.0.31-20180903-120321/libphp7.so(remember to uncomment the "#" symbol), then save and exit.

  5. Finally, run apachectl restartto restart your apache server.

  1. 打开终端并运行 curl -s https://php-osx.liip.ch/install.sh | bash -s 7.0
  2. 安装的php将驻留在/usr/local/php5-7.0.31-20180903-120321/lib(我不知道为什么目录名是php5-7xxxx,但安装的php版本是7.0)

  3. 编辑 apache2 配置/private/etc/apache2/httpd.conf(如有必要,请进行备份)

  4. 替换LoadModule php7_module libexec/apache2/libphp7.soLoadModule php7_module /usr/local/php5-7.0.31-20180903-120321/libphp7.so(记得取消注释“#”符号),然后保存退出。

  5. 最后,运行apachectl restart以重新启动您的 apache 服务器。

enabled_gettext

enabled_gettext