bind_textdomain_codeset

Specify the character encoding in which the messages from the DOMAIN message catalog will be returned

说明

string bind_textdomain_codeset ( string $domain , string $codeset )

With bind_textdomain_codeset, you can set in which encoding will be messages from domain returned by gettext and similar functions.

参数

domain
The domain

codeset
The code set

返回值

A string on success.

bindtextdomain

Sets the path for a domain

说明

string bindtextdomain ( 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 dcgettext ( string $domain , 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 dcngettext ( string $domain , string $msgid1 , string $msgid2 , int $n , int $category )

This function allows you to override the current domain for a single plural message lookup.

参数

domain
The domain

msgid1

msgid2

n

category

返回值

A string on success.

参见

  • ngettext

dgettext

Override the current domain

说明

string dgettext ( string $domain , 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 dngettext ( string $domain , string $msgid1 , string $msgid2 , int $n )

The dngettext function allows you to override the current domain for a single plural message lookup.

参数

domain
The domain

msgid1

msgid2

n

返回值

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 class="function">putenv should be used to define the current locale.

参见

  • setlocale

ngettext

Plural version of gettext

说明

string ngettext ( string $msgid1 , string $msgid2 , int $n )

The plural version of gettext. Some languages have more than one form for plural messages dependent on the count.

参数

msgid1
The singular message ID.

msgid2
The plural message ID.

n
The number (e.g. item count) to determine the translation for the respective grammatical number.

返回值

Returns correct plural form of message identified by msgid1 and msgid2 for count n.

范例

示例 #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 textdomain ( string $text_domain = NULL )

This function sets the domain to search within when calls are made to gettext, usually the named after an application.

参数

text_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.

目录