跳转到内容

Phalcon 翻译

注意

所有类都以前缀命名Phalcon

Translate\Adapter\AbstractAdapterAbstract

GitHub上的源码

  • 命名空间

    • Phalcon\Translate\Adapter
  • 使用

    • Phalcon\Support\Helper\Arr\Get
    • Phalcon\Translate\Exception
    • Phalcon\Translate\InterpolatorFactory
  • 继承

  • 实现

    • AdapterInterface

类 AbstractAdapter

@package Phalcon\Translate\Adapter

@property string $defaultInterpolator @property InterpolatorFactory $interpolatorFactory

属性

/**
 * @var string
 */
protected $defaultInterpolator = ;

/**
    * @var InterpolatorFactory
    */
protected $interpolatorFactory;

方法

public function __construct( InterpolatorFactory $interpolator, array $options = [] );
AbstractAdapter 构造函数。

public function _( string $translateKey, array $placeholders = [] ): string;
返回给定键的翻译字符串(方法 't' 的别名)

public function offsetExists( mixed $translateKey ): bool;
检查是否存在翻译键

public function offsetGet( mixed $translateKey ): mixed;
返回与给定键相关的翻译

public function offsetSet( mixed $offset, mixed $value ): void;
设置翻译值

public function offsetUnset( mixed $offset ): void;
从字典中移除翻译

public function t( string $translateKey, array $placeholders = [] ): string;
返回给定键的翻译字符串

protected function replacePlaceholders( string $translation, array $placeholders = [] ): string;
将占位符替换为传递的值

Translate\Adapter\AdapterInterfaceInterface

GitHub上的源码

  • 命名空间

    • Phalcon\Translate\Adapter
  • 使用

  • 继承

  • 实现

Phalcon\Translate\Adapter\AdapterInterface

Phalcon\Translate 适配器接口

方法

public function has( string $index ): bool;
检查内部数组中是否定义了翻译键

public function query( string $translateKey, array $placeholders = [] ): string;
返回与给定键相关的翻译

public function t( string $translateKey, array $placeholders = [] ): string;
返回给定键的翻译字符串

Translate\Adapter\Csv

GitHub上的源码

  • 命名空间

    • Phalcon\Translate\Adapter
  • 使用

    • ArrayAccess
    • Phalcon\Translate\Exception
    • Phalcon\Translate\InterpolatorFactory
  • 继承

    AbstractAdapter

  • 实现

    • ArrayAccess

属性

/**
 * @var array
 */
protected $translate;

方法

public function __construct( InterpolatorFactory $interpolator, array $options );
Csv 构造函数。

public function exists( string $index ): bool;
检查内部数组中是否定义了翻译键

public function has( string $index ): bool;
检查内部数组中是否定义了翻译键

public function query( string $translateKey, array $placeholders = [] ): string;
返回与给定键相关的翻译

public function toArray(): array;
返回内部数组

protected function phpFopen( string $filename, string $mode );
@todo 当我们获取 traits 时将被移除

Translate\Adapter\Gettext

GitHub上的源码

  • 命名空间

    • Phalcon\Translate\Adapter
  • 使用

    • ArrayAccess
    • Phalcon\Translate\Exception
    • Phalcon\Translate\InterpolatorFactory
  • 继承

    AbstractAdapter

  • 实现

    • ArrayAccess

Phalcon\Translate\Adapter\Gettext

use Phalcon\Translate\Adapter\Gettext;

$adapter = new Gettext(
    [
        "locale"        => "de_DE.UTF-8",
        "defaultDomain" => "translations",
        "directory"     => "/path/to/application/locales",
        "category"      => LC_MESSAGES,
    ]
);

允许使用 gettext 进行翻译

@property int $category @property string $defaultDomain @property string|array $directory @property string|false $locale

属性

/**
 * @var int
 */
protected $category;

/**
 * @var string
 */
protected $defaultDomain;

/**
 * @var string|array
 */
protected $directory;

/**
 * @var string
 */
protected $locale;

方法

public function __construct( InterpolatorFactory $interpolator, array $options );
Gettext 构造函数。

public function exists( string $index ): bool;
检查内部数组中是否定义了翻译键

public function getCategory(): int;
public function getDefaultDomain(): string;
public function getDirectory(): array | string;
public function getLocale(): string;

public function has( string $index ): bool;
检查内部数组中是否定义了翻译键

public function nquery( string $msgid1, string $msgid2, int $count, array $placeholders = [], string $domain = null ): string;
Gettext() 的复数版本。某些语言根据计数有不同的复数消息形式。

public function query( string $translateKey, array $placeholders = [] ): string;
返回与给定键相关的翻译。

$translator->query("你好 %name%!", ["name" => "Phalcon"]);

public function resetDomain(): string;
设置默认域

public function setDefaultDomain( string $domain ): void;
设置调用 gettext() 时搜索的默认域

public function setDirectory( mixed $directory ): void;
设置域的路径

// Set the directory path
$gettext->setDirectory("/path/to/the/messages");

// Set the domains and directories path
$gettext->setDirectory(
    [
        "messages" => "/path/to/the/messages",
        "another"  => "/path/to/the/another",
    ]
);

public function setDomain( string $domain = null ): string;
更改当前域(即翻译文件)

public function setLocale( int $category, array $localeArray = [] ): string | bool;
设置区域信息

// Set locale to Dutch
$gettext->setLocale(LC_ALL, "nl_NL");

// Try different possible locale names for German
$gettext->setLocale(LC_ALL, "de_DE@euro", "de_DE", "de", "ge");

protected function getOptionsDefault(): array;
获取默认选项

protected function phpFunctionExists( string $name ): bool;
@todo 当我们获取 traits 时将被移除

protected function prepareOptions( array $options ): void;
构造函数的验证器

Translate\Adapter\NativeArray

GitHub上的源码

  • 命名空间

    • Phalcon\Translate\Adapter
  • 使用

    • ArrayAccess
    • Phalcon\Translate\Exception
    • Phalcon\Translate\InterpolatorFactory
  • 继承

    AbstractAdapter

  • 实现

    • ArrayAccess

类 NativeArray

使用 PHP 数组定义翻译列表

@package Phalcon\Translate\Adapter

@property array $translate @property bool $triggerError

属性

/**
 * @var array
 */
private $translate;

/**
 * @var bool
 */
private $triggerError = false;

方法

public function __construct( InterpolatorFactory $interpolator, array $options );
NativeArray 构造函数。

public function exists( string $index ): bool;
检查内部数组中是否定义了翻译键

public function has( string $index ): bool;
检查内部数组中是否定义了翻译键

public function notFound( string $index ): string;
当未找到键时将调用此方法

public function query( string $translateKey, array $placeholders = [] ): string;
返回与给定键相关的翻译

public function toArray(): array;
返回内部数组

Translate\Exception

GitHub上的源码

  • 命名空间

    • Phalcon\Translate
  • 使用

  • 继承

    \Exception

  • 实现

Phalcon\Translate\Exception

Phalcon\Translate 抛出的异常类

Translate\Interpolator\AssociativeArray

GitHub上的源码

  • 命名空间

    • Phalcon\Translate\Interpolator
  • 使用

    • Phalcon\Support\Helper\Str\Interpolate
  • 继承

  • 实现

    • InterpolatorInterface

类 AssociativeArray

@package Phalcon\Translate\Interpolator

方法

public function replacePlaceholders( string $translation, array $placeholders = [] ): string;
将占位符替换为传递的值

Translate\Interpolator\IndexedArray

GitHub上的源码

  • 命名空间

    • Phalcon\Translate\Interpolator
  • 使用

  • 继承

  • 实现

    • InterpolatorInterface

类 IndexedArray

@package Phalcon\Translate\Interpolator

方法

public function replacePlaceholders( string $translation, array $placeholders = [] ): string;
将占位符替换为传递的值

Translate\Interpolator\InterpolatorInterfaceInterface

GitHub上的源码

  • 命名空间

    • Phalcon\Translate\Interpolator
  • 使用

  • 继承

  • 实现

Phalcon\Translate\InterpolatorInterface

Phalcon\Translate 插值器接口

方法

public function replacePlaceholders( string $translation, array $placeholders = [] ): string;
将占位符替换为传递的值

Translate\InterpolatorFactory

GitHub上的源码

  • 命名空间

    • Phalcon\Translate
  • 使用

    • Phalcon\Factory\AbstractFactory
    • Phalcon\Translate\Interpolator\InterpolatorInterface
  • 继承

    AbstractFactory

  • 实现

该文件是Phalcon框架的一部分。

(c) Phalcon团队team@phalcon.io

有关完整的版权和许可信息,请查看随此源代码分发的LICENSE.txt文件。

方法

public function __construct( array $services = [] );
InterpolatorFactor 构造函数。

public function newInstance( string $name ): InterpolatorInterface;
创建适配器的新实例

protected function getExceptionClass(): string;

protected function getServices(): array;
返回可用的适配器

Translate\TranslateFactory

GitHub上的源码

  • 命名空间

    • Phalcon\Translate
  • 使用

    • Phalcon\Config\ConfigInterface
    • Phalcon\Factory\AbstractFactory
    • Phalcon\Translate\Adapter\AdapterInterface
  • 继承

    AbstractFactory

  • 实现

类 TranslateFactory

@package Phalcon\Translate

@property InterpolatorFactory $interpolator

属性

/**
 * @var InterpolatorFactory
 */
private $interpolator;

方法

public function __construct( InterpolatorFactory $interpolator, array $services = [] );
AdapterFactory构造函数。

public function load( mixed $config ): AdapterInterface;
从Config对象创建实例的工厂

public function newInstance( string $name, array $options = [] ): AdapterInterface;
创建适配器的新实例

protected function getExceptionClass(): string;

protected function getServices(): array;
返回可用的适配器

无噪 Logo
无噪文档
25 年 6 月翻译
文档源↗