Ref/gettext-Phpdoc专题
bind_textdomain_codeset
Specify the character encoding in which the messages from the DOMAIN message catalog will be returned
说明
string<span
class="type">false <span
class="methodname">bind_textdomain_codeset ( <span
class="methodparam">string $domain
,
string
$codeset
)
With bind_textdomain_codeset, you can
set in which encoding will be messages from domain
returned by <span
class="function">gettext and similar functions.
参数
domain
The domain
codeset
The code set
返回值
A string on success.
bindtextdomain
Sets the path for a domain
说明
string<span
class="type">false <span
class="methodname">bindtextdomain ( <span
class="methodparam">string $domain
,
string
$directory
)
The bindtextdomain function sets the path for a domain.
参数
domain
The domain
directory
The directory path
返回值
The full pathname for the domain
currently being set.
范例
示例 #1 bindtextdomain example
<?php
$domain = 'myapp';
echo bindtextdomain($domain, '/usr/share/myapp/locale');
?>
以上例程会输出:
/usr/share/myapp/locale
dcgettext
Overrides the domain for a single lookup
说明
string <span
class="methodname">dcgettext ( <span
class="type">string $domain
, <span
class="methodparam">string $message
,
int
$category
)
This function allows you to override the current domain for a single message lookup.
参数
domain
The domain
message
The message
category
The category
返回值
A string on success.
参见
- gettext
dcngettext
Plural version of dcgettext
说明
string <span
class="methodname">dcngettext ( <span
class="type">string $domain
, <span
class="methodparam">string $singular
, string
$plural
, <span
class="type">int $count
, <span
class="methodparam">int $category
)
This function allows you to override the current domain for a single plural message lookup.
参数
domain
The domain
singular
plural
count
category
返回值
A string on success.
参见
- ngettext
dgettext
Override the current domain
说明
string <span
class="methodname">dgettext ( <span
class="type">string $domain
, <span
class="methodparam">string $message
)
The dgettext function allows you to
override the current domain
for a single message lookup.
参数
domain
The domain
message
The message
返回值
A string on success.
参见
- gettext
dngettext
Plural version of dgettext
说明
string <span
class="methodname">dngettext ( <span
class="type">string $domain
, <span
class="methodparam">string $singular
, string
$plural
, <span
class="type">int $count
)
The dngettext function allows you to
override the current domain
for a single plural message lookup.
参数
domain
The domain
singular
plural
count
返回值
A string on success.
参见
- ngettext
gettext
Lookup a message in the current domain
说明
string gettext
( string
$message
)
Looks up a message in the current domain.
参数
message
The message being translated.
返回值
Returns a translated string if one is found in the translation table, or the submitted message if not found.
范例
示例 #1 gettext-check
<?php
// Set language to German
putenv('LC_ALL=de_DE');
setlocale(LC_ALL, 'de_DE');
// Specify location of translation tables
bindtextdomain("myPHPApp", "./locale");
// Choose domain
textdomain("myPHPApp");
// Translation is looking for in ./locale/de_DE/LC_MESSAGES/myPHPApp.mo now
// Print a test message
echo gettext("Welcome to My PHP Application");
// Or use the alias _() for gettext()
echo _("Have a nice day");
?>
注释
Note:
You may use the underscore character '_' as an alias to this function.
Note:
Setting a language isn't enough for some systems and the <span class="function">putenv should be used to define the current locale.
参见
- setlocale
ngettext
Plural version of gettext
说明
string <span
class="methodname">ngettext ( <span
class="type">string $singular
, <span
class="methodparam">string $plural
,
int $count
)
The plural version of gettext. Some languages have more than one form for plural messages dependent on the count.
参数
singular
The singular message ID.
plural
The plural message ID.
count
The number (e.g. item count) to determine the translation for the
respective grammatical number.
返回值
Returns correct plural form of message identified by singular
and
plural
for count count
.
范例
示例 #1 ngettext example
<?php
setlocale(LC_ALL, 'cs_CZ');
printf(ngettext("%d window", "%d windows", 1), 1); // 1 okno
printf(ngettext("%d window", "%d windows", 2), 2); // 2 okna
printf(ngettext("%d window", "%d windows", 5), 5); // 5 oken
?>
textdomain
Sets the default domain
说明
string <span
class="methodname">textdomain ( <span
class="type">string<span
class="type">null $domain
)
This function sets the domain to search within when calls are made to gettext, usually the named after an application.
参数
domain
The new message domain, or null
to get the current setting without
changing it
返回值
If successful, this function returns the current message domain, after possibly changing it.
目录
- bind_textdomain_codeset — Specify the character encoding in which the messages from the DOMAIN message catalog will be returned
- bindtextdomain — Sets the path for a domain
- dcgettext — Overrides the domain for a single lookup
- dcngettext — Plural version of dcgettext
- dgettext — Override the current domain
- dngettext — Plural version of dgettext
- gettext — Lookup a message in the current domain
- ngettext — Plural version of gettext
- textdomain — Sets the default domain