php国际化
I18N internationalization(国际化)简写为I18N,中间的数字为省略的字母个数。 在 Linux 系统中,通过定义一组环境变量来设置程序的语言环境,以实现对I18N的支持,这种机制称为:locale(本地化) LANG 低优先级全局 locale 变量 如果下面的变量未赋值,默认使用此变量的值 LC_COLLATE 比较和排序习惯 会影响目录列表的分类显示等 LC_CTYPE 定义系统的字符处理特性 哪些字符能被视为字母、数字,等等;与中文输入关系密切 LC_MESSAGES 提示信息,错误信息, 状态信息, 标题, 标签, 按钮和菜单等 LC_MONETARY 定义货币单位和货币型数值的格式 LC_NUMERIC 定义非货币型数值的格式 影响到千位分隔符和小数分隔符等 LC_TIME 定义日期和时间的格式 LC_NAME 姓名书写方式 LC_ADDRESS 地址书写方式 LC_TELEPHONE 电话号码书写方式 LC_MEASUREMENT 度量衡表达方式 LC_PAPER 定义默认的纸张尺寸 LC_IDENTIFICATION 对 locale 自身包含信息的概述 LC_ALL 高优先级全局 locale 变量 为此变量赋值会强行覆盖上面变量的值,不推荐 步骤一:搭建环境 1,首先查看你的php扩展目录下是否有php_gettext.dll这个文件,如果没有,这就需要你 下载一个或是从其他地方拷贝一个,然后放到php扩展目录。 2,打开php.ini,查找”;extension=php_gettext.dll“ ,然后去除注释,重启apache。 步骤二:原理讲解 假如你的没有国际化的程序里有这样的代码,echo "你好";,而国际化的程序你要写成 echo gettext("你好");,然后再在配置文件里添加“你好”相对应的英文“Hi”。 这时,中国地区浏览都会在屏幕上输出“你好”,而美国地区浏览都会在屏幕上输出 “Hi”。也就是说,最终显示什么是根据你的配置文件而定的,如果找不到配置文件, 才会输出程序里面的内容。 步骤三:编码测试 1,我们在d:\www下面新建文件hi.php,详细代码如下 1 这时你运行改程序,只会输出“Hi”。但我们是中国人,我们不认识“Hi”, 我们只认识“你好”,这时就要配置文件出马。配置文件的生成一般借助一款工具。 下载地址:http://nchc.dl.sourceforge.net/sourceforge/gnuwin32/gettext-0.14.4.exe 安装好以后,为了在任意目录里使用,需要把“安装路径/bin”添加到系统环境变量里。 步骤四:配置文件的生成 1,我们假设你的工具已经安装好,并且可以在任意目录使用。现在就要运行cmd,并把 路径切换到d:\www下面,也就是hi.php所在目录。 键入xgettext -d hi hi.php --from-code=gb2312,然后执行,这时你可以看到新生成一个 hi.po文件,注意:--from-code=gb2312,其中gb2312还可以是utf-8。 2,打开hi.po文件,显示如下: # SOME DESCRIPTIVE TITLE. # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the PACKAGE package. # FIRST AUTHOR , YEAR. # #, fuzzy msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2009-01-19 17:47+0800\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" #: hi.php:6 msgid "Hi!" msgstr "" 现在有两个地方需要修改, 1:"Content-Type: text/plain; charset=CHARSET\n" 2:msgstr "" 把1中的CHARSET修改成gb2312,然后把2修改成msgstr "你好"。 3,键入msgfmt -o hi.mo hi.po,执行,这时生成hi.mo文件。 然后在d:\www下新建locale\zh_Cn\LC_MESSAGES目录,把hi.mo拷到这里就行了。 4,现在重启apache,再次运行,屏幕上可以输出“你好”。 其他: 如果使用utft-8编码的话,需要使用 bind_textdomain_codeset($domain,'UTF-8'); 相应的要把hi.po里的CHARSET改成utf-8,还需要把hi.po保存成utf-8格式, 再次生成hi.mo就行了。 总结: 我们都希望我们写的程序可以被大众甚至国际普遍使用,像大名鼎鼎的wordpress的 国际化使用的也是他。gettext还是非常不错的,简单易用, http://www.cnblogs.com/suimengsiqu/archive/2009/01/19/1378466.html

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.
