PHP.mk документација

textdomain

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

function.textdomain.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека function.textdomain.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
textdomain

Референца за `function.textdomain.php` со подобрена типографија и навигација.

function.textdomain.php

textdomain

(PHP 4, PHP 5, PHP 7, PHP 8)

textdomainГо поставува стандардниот домен

= NULL

textdomain(?string $domain = null): string

Оваа функција го поставува доменот за пребарување кога се прават повици до gettext(), обично именуван по апликација.

Параметри

domain

Новиот домен на пораката, или null за да ја добиете тековната поставка без да ја промените

Вратени вредности

Ако е успешна, оваа функција го враќа тековниот домен на пораката, откако евентуално ќе го промени.

Errors/Exceptions

Фрла ValueError if domain Доменот string.

Дневник на промени

Верзија = NULL
8.4.0 Сега фрла ValueError if domain Доменот string.
8.4.0 domain е опционално сега. Претходно, параметарот секогаш мораше да биде специфициран.

Белешки

Забелешка:

На textdomain() информациите се одржуваат по процес, не по нишка.

Белешки од корисници 2 забелешки

ninja (без а) на informance dot dot dot info
пред 15 години
When you set a text domain, it (obviously) erases the previous one. 

This can be a problem when you use nested includes in which there can be textdomain() calls with different text domains. After returning from the include, your textdomain is changed, and the rest of the parent script fails in translating the remaining sentences.

I wrote these two small functions to avoid that. You should put the whole code into a file which you require_once in every script that needs gettext functionalities. Then, use only set_textdomain() and restore_textdomain() at the beginning and the end of every script/function that sets a text domain.

A call to set_textdomain() MUST correspond to a call to restore_textdomain(), and there is no limit in how many nested calls are done.

One optimization is done here: when the new text domain is the same as the current one, no change is made, and restore_textdomain() will be aware of this so you can still call it safely.

<?php
$_td_stack = array(); // text domains stack

/**
 * Sets a new text domain after recording the current one
 * so it can be restored later with restore_textdomain().
 *
 * It's possible to nest calls to these two functions.
 * @param string the new text domain to set
 */
function set_textdomain($td)
{
    global $_td_stack;
    
    $old_td = textdomain(NULL);
    
    if ($old_td)
    {
        if (!strcmp($old_td, $td))
        {
            array_push($_td_stack, false);
        }
        else
        {
            array_push($_td_stack, $old_td);
        }
    }
    
    textdomain($td);
}

/**
 * Restore the text domain active before the last call to
 * set_textdomain().
 */
function restore_textdomain()
{
    global $_td_stack;
    
    $old_td = array_pop($_td_stack);
    
    if ($old_td)
    {
        textdomain($old_td);
    }
}
?>
ipso на snappymail dot ca
пред 18 години
I was having very strange issues with gettext only setting the locale once per Apache process (non-threaded), until I found this bug report:

http://bugs.php.net/bug.php?id=21965

It almost seemed like gettext was caching the data once per process, but in fact calling textdomain() fixed the issue for me.
Навигација

Прелистувај сродни теми и функции.

На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.