PHP,Wordpress,phpMyAdmin,C,i18n,L10n等的下划线? [英] Double Underscore in PHP, Wordpress, phpMyAdmin, C, i18n, L10n etc?

查看:231
本文介绍了PHP,Wordpress,phpMyAdmin,C,i18n,L10n等的下划线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

引用另一个问题结尾我。



  $ WPLD_Trans ['Yes'] = __('Yes',$ WPLD_Domain); 
$ WPLD_Trans ['No'] = __('No',$ WPLD_Domain);

以及与 __()

作为上面提到的一个答案,作为一个答案开始,和其他相关。



请随意编辑和改进 - 或者输入更好的答案/问题。

解决方案

使用 __(...)



双下划线用于各种实现。提到Wordpress(WP),phpMyAdmin(PMA)是另一个,等等。



它反映在原生PHP函数 gettext(),在PHP中有一个别名作为一个下划线 _()。这不是PHP独有的。 Gettext 本质上是一个长期的GNU项目,用于在Unix系统上编写多语言程序。我们在各种编程语言中找到 _()别名。



对主题的反思



在谦逊/诚实的观点,可以说, _()作为本机和 __()作为 gettext 的自定义实现或其他特定于语言环境的用法是唯一的有效 - 因为它是一个成熟的惯例。另一方面,它不是,但即使这么简洁。例如。在ANSI-C标准双下划线 __ 保留供编译器内部使用;并且因为PHP与C密切相关,所以它们保留它,并且一般来说,它不是跨越语言(IMHO)混合的最好的东西,它在边界/薄冰等上。 p>

此处的一个问题是选择 UnderscoreJS 使用 _ 作为它们与语言支持无关的基础。)将它与prototype.js的 $ $$ ,并且可能有一些理解为什么有人在看到 __()时抓住了他们的头部 -






区域支持



在这一步我做了一些注释是用法:区域支持,重量在 i18n L10n



WP 2 3 和(文档 PMA ,提供语言支持。
例如:



__('Error'); 会产生 Feil 在挪威语或 Fehler 在德语。但是,在这里要注意的一个重要的事情是,在同一个领域,我们有更多的直接翻译,但也有其他奇怪的发现在不同的地方/文化/语言。



p (指定):



一些语言使用逗号 - 作为分数分隔符,其他语言使用dot - - 用于相同的目的。其他典型的区域设置变体是厘米与英寸,日期格式,12对24小时制,货币等。因此:

 
NUMBER LEN时间
LANG1:3,133.44 2.00英寸5:00 PM
LANG2:3.133,44 5,08厘米17:00

下一层代码可能会引用一些比较隐蔽的约定,比如 i18n l10n 在变量名,函数和文件名中。



一旦你知道他们的意思,他们是相当方便,定义可能有点模糊。一般来说,我们有:

 
i18n:国际化
l10n:本地化(常用L10n)
g11n:全球化例如IBM和Sun Microsystems)
l12y:Localizability(Microsoft)
m17n:多语言化(国际化和本地化之间的连续性)
...等等。



aich,我的头疼。



数字是指第一个和最后一个字母之间的单词中的字母数。前后的字母是字中的第一个和最后一个字母。 。。所以:

 
i18n l10n
国际化本地化
| | | |
+ - 18个字母 - + + - 10 - +

i 18 nl 10 n

(我们还有更强大的数字 ,不符合此惯例 G8 (八国集团) - 但是我们不在编程领域 - 或者我们?)。



然后到定义:



W3C 对国际化(i18n)和本地化(l10n)有相当平淡的定义。




  • 国际化(i18n)是一种产品,应用程序或文档内容的设计和开发,可以为文化,地区或语言不同的目标受众提供轻松的本地化。


  • 本地化(l10n)是指符合某种产品,应用程序或文档内容的适应




debian 主题是:




  • 国际化(I18N):使软件可以处理多个地区。

  • 本地化(L10N):使软件处理特定地区。 >


使用



在代码,阅读等,本地化一个遇到的的用法。更多搜索引擎友好 - 名称可能是翻译域





简而言之,可以将其定义为上下文。作为基地,你有一个地区。例如。苏格兰。但你可以进一步定义一个域作为主题,专业等的一部分。将会使Java 在编程中与咖啡店有所不同。



有一个线索的页面是repoze.org:

$

b
$ b

翻译目录通常是:

 
/ path / to / your / translation_root / en_US / LC_MESSAGES /
/ path / to / your / translation_root / en_GB / LC_MESSAGES /
/ path / to / your / translation_root / nn_NO / LC_MESSAGES /
...



与GetText一起使用的文件



例如PMA你会发现一个名为 locale 的目录。它包含各种语言的各种目录。这些文件带有 .mo 扩展名。这是GetText的具体文件。通常从PO,Portable Object开始,文件是纯文本文件。这些被索引并且被编译到MO,机器对象,被索引用于优化的文件。有关此此处(与上面的 PMA - 链接相同)的详情。







To quote another question that ended me here.

What does the double underscores in these lines of PHP code mean?

$WPLD_Trans['Yes']=__('Yes',$WPLD_Domain);
$WPLD_Trans['No']=__('No',$WPLD_Domain);

and related question about the usage of __(), _() etc. in Wordpress etc.

Started as an answer to the one mentioned above, and other related. But post as own question (with answer) as it became a bit more detailed.

Please feel free to edit and improve – or enter better Answer / Question.

解决方案

The usage of __(…)

Double underscore is used by various implementations. Wordpress (WP) is mentioned, phpMyAdmin (PMA) is another, and so on.

It reflects on the native PHP function gettext(), which in PHP has an alias as a single underscore: _(). This is not unique to PHP. Gettext is natively a long-standing GNU project for writing multilingual programs on Unix like systems. We find the _() alias in various programming languages.

Reflection on the subject

In ones humble/honest opinion, one could say, _() as native and __() as custom implementations of gettext, or other locale specific uses, is the only valid ones - as it is a well established convention. On the other hand it is not good, but even so concise. E.g. in ANSI-C standard double underscore __ is reserved for the compiler's internal use; and as PHP is as closely related to C as it is, they have reserved it, and in general it is not the best thing to mix up even across languages (IMHO), it is on the border/thin ice/etc.

(One issue here is the choice of UnderscoreJS to use _ as their foundation on something that has nothing to do with language support.) Mix it in with prototype.js's $ and $$ and there is might some understanding why someone scratches their head when seeing __() – especially taking into account how close PHP and JS are in implementation of a working system.


Locale support

On this step I make some notes on is the usage: Locale support with weight on i18n and L10n.

It is often used, as with WP, 2, 3 and (the well documented) PMA, by giving language support. E.g.:

__('Error'); would yield Feil in Norwegian or Fehler in German. But, one important thing to take note of here is that, in the same realm, we have more then direct translation, but also other quirks one find in differing locales/cultures/languages.

E.g. (to specify):

Some languages uses comma – , – as fractional separator, others use dot – . – for the same purpose. Other typical locale variations is centimetre vs inches, date format, 12 vs 24 hour clock, currency etc. So:

       NUMBER    LEN        TIME
LANG1: 3,133.44  2.00 inch   5:00 PM
LANG2: 3.133,44  5,08 cm    17:00

Next layer of code you unveil would probably have some reference to the rather cryptic conventions like i18n or l10n in variable names, functions and file-names.

Once you know what they mean they are quite handy, tho definitions can be somewhat blurry. In general we have:

i18n: Internationalization
l10n: Localization (Often L10n)
g11n: Globalization (Used by e.g. IBM and Sun Microsystems)
l12y: Localizability (Microsoft)
m17n: Multilingualization (Continuum between internationalization and localization)
...   And so on.

aich, my head hurts.

The number refers to number of letters in the words between first and last letter. The letter before and after – is the first and last letter in the word. Phew. So:

       i18n                 l10n
internationalization    localization
 |                |      |        |
 +-- 18 letters --+      +-- 10 --+

i       18         n    l    10    n

(We also have more powerful numeronyms that does not follow this convention like G8 (Group of Eight) -, but then we're outside the realm of programming - or are we?).

Then to the definitions:

W3C has a rather sane definition of Internationalization (i18n), and Localization (l10n).

  • Internationalization, (i18n), is the design and development of a product, application or document content that enables easy localization for target audiences that vary in culture, region, or language.

  • Localization, (l10n), refers to the adaptation of a product, application or document content to meet the language, cultural and other requirements of a specific target market (a locale).

The short, and concise, version from debian on the subject is:

  • Internationalization (I18N): To make a software potentially handle multiple locales.
  • Localization (L10N): To make a software handle an specific locale.

The use of domains

Frequently, when looking at code, reading about, etc. localization one come across the usage of domain. A more search engine friendly-name would perhaps be Translation Domain.

(Here I'm a bit on thin ice.).

In short one could define this as context. As a base you have a locale. E.g. Scotland. But you can further define a domain as part of a theme, profession etc. E.g. would Java in programming be rather different from a coffee shop. Or cow on a degenerated site about women vs. farming.

A page giving some clue is repoze.org with:

A translation directory would typically be:

/path/to/your/translation_root/en_US/LC_MESSAGES/
/path/to/your/translation_root/en_GB/LC_MESSAGES/
/path/to/your/translation_root/nn_NO/LC_MESSAGES/
…

Files used with GetText

If you take a look at e.g. PMA you will find a directory called locale. It contains various directories for various languages. The files are with .mo extension. This is GetText specific files. One typically start with PO, Portable Object, files which are plain text files. These are indexed and compiled to MO, Machine Object, files which are indexed for optimization. More about this here (Same as the PMA-link above).


这篇关于PHP,Wordpress,phpMyAdmin,C,i18n,L10n等的下划线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆