geniv / nette-locale
Locale extension for Nette Framework
Installs: 1 276
Dependents: 10
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=7.0.0
- dibi/dibi: >=3.0.0
- nette/nette: >=2.4.0
This package is auto-updated.
Last update: 2024-11-07 08:40:12 UTC
README
Plural forms documents: http://docs.translatehouse.org/projects/localization-guide/en/latest/l10n/pluralforms.html
In case new item must by added char $
and add brackets (
, )
! Otherwise function EVAL
has problem with correct evaluate plural form.
It is recommended change position plurals index number (eg: 0 => 0 oken, 5 oken
, 1 => 1 okno
, 2 => 2 okna, 3 okna
).
Installation
$ composer require geniv/nette-locale
or
"geniv/nette-locale": ">=1.0.0"
require:
"php": ">=7.0.0", "nette/nette": ">=2.4.0", "dibi/dibi": ">=3.0.0"
Include in application
available source drivers:
- Dibi (dibi + cache)
- Array (array configure)
- DevNull (ignore locale)
neon configure:
extensions: locale: Locale\Bridges\Nette\Extension
neon configure extension:
# 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 configure:
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
usage:
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
description
onRequest
is default in Nette\Application\Application
via application.application
:
via: vendor/nette/application/src/Application/Application.php:41 (Nette\Application\Application)
public function onRequest(Application $application, Request $request) {}