geniv/nette-locale

Nette框架的Locale扩展

v2.0.12 2019-04-25 23:40 UTC

README

复数形式文档:http://docs.translatehouse.org/projects/localization-guide/en/latest/l10n/pluralforms.html

如果需要添加新项目,请使用字符$并添加括号()!否则,函数EVAL在正确评估复数形式时会存在问题。

建议更改复数索引号的位置(例如:0 => 0 片,5 片,1 => 1 片,2 => 2 片,3 片)。

安装

$ composer require geniv/nette-locale

"geniv/nette-locale": ">=1.0.0"

require

"php": ">=7.0.0",
"nette/nette": ">=2.4.0",
"dibi/dibi": ">=3.0.0"

包含在应用程序中

可用的源驱动程序

  • Dibi (dibi + cache)
  • 数组 (数组配置)
  • DevNull (忽略区域设置)

neon配置

extensions:
    locale: Locale\Bridges\Nette\Extension

neon配置扩展

# locale
locale:
#   debugger: true
#   autowired: true
#   onRequest: application.application
#   driver: Locale\Drivers\DevNullDriver
#   driver: Locale\Drivers\ArrayDriver(%default%, %locales%, %plurals%, %alias%)
    driver: Locale\Drivers\DibiDriver(%tablePrefix%)

neon配置

parameters:
    default: "cs"
    locales:
       cs: "Čeština"
       en: "English"
       de: "Deutsch"
    plurals:
       cs: "$nplurals=3; $plural=($n==1) ? 1 : (($n>=2 && $n<=4) ? 2 : 0);"
       en: "$nplurals=2; $plural=($n != 1) ? 0 : 1;"
       de: "$nplurals=2; $plural=($n != 1) ? 0 : 1;"
       ru: "$nplurals=3; $plural=($n%10==1 && $n%100!=11 ? 0 : $n%10>=2 && $n%10<=4 && ($n%100<10 || $n%100>=20) ? 1 : 2);"
    alias:
       sk: cs
       pl: en

用法

use Locale\Locale;
$locale = $this->context->getByType(ILocale::class);

// or

/** @var Locale\ILocale @inject */
public $locale;

// methods implements `ILocale`:
getListName(): array;
getListId(): array;
getLocales(): array;

getCode(bool $upper = false): string
setCode(string $code)

// is correct locale set? with method: setCode()
// true if driver is DevNullDriver
isReady(): bool

getId(): int
getIdDefault(): string

getCodeDefault(bool $upper = false): string
isDefaultLocale(): bool
getPlural(): string
getIdByCode(string $code): int

描述

onRequestNette\Application\Application中默认通过application.application实现

via: vendor/nette/application/src/Application/Application.php:41 (Nette\Application\Application)

public function onRequest(Application $application, Request $request) {}