abbadon1334 / atk4-i18next-php
description
1.0.1
2019-07-15 07:02 UTC
Requires
- php: >=7.2
- atk4/core: dev-develop
Requires (Dev)
- atk4/data: dev-develop
- codacy/coverage: dev-master@dev
- evert/phpdoc-md: dev-master@dev
- friendsofphp/php-cs-fixer: dev-master@dev
- phpmd/phpmd: 2.6.1
- phpmetrics/phpmetrics: dev-master@dev
- phpstan/phpstan: 0.11.12
- phpunit/phpunit: 8.2.4
- squizlabs/php_codesniffer: 3.4.2
- thecodingmachine/phpstan-safe-rule: 0.1.3
- victorjonsson/markdowndocs: 1.3.8
This package is auto-updated.
Last update: 2024-10-08 15:56:55 UTC
README
Based on i18next http://i18next.com
Interpolate direct with ATK4 - Agile Toolkit Models https://www.agiletoolkit.org/
install with composer :
composer require abbadon1334/atk4-i18next-php
All documentation about the original library can be found here : http://i18next.com/
How to use :
$this->translator = new Translator();
$this->translator->setTranslationsPath(__DIR__.'/data/locales');
Define if filename will be used has namespace :
$this->translator->useFilenameAsNamespace(true);
Define primary and fallback languages (using names of the folder) :
$this->translator->setLanguagePrimary($language);
$this->translator->setLanguageFallback($fallback);
Add additional language :
$this->translator->addLanguage('it');
Translate :
interface TranslatorInterface { /** * Translates the given message. * * @param string $key * @param array|null $parameters Array of parameters used to translate message * @param string|null $context * @param string|null $locale The locale or null to use the default * * @return string The translated string */ public function _(string $key, ?array $parameters = null, ?string $context = null, ?string $locale = null): string; } // Usage $result = $this->translator->_('definitionKey'); $result = $this->translator->_('definitionKey', ['param1' => 'test']); $result = $this->translator->_('definitionKey', ['param1' => 'test'], 'context'); $result = $this->translator->_('definitionKey', ['param1' => 'test'], 'context', 'specificLanguage'); $result = $this->translator->_('namespace:definitionKey', ['param1' => 'test'], 'context', 'specificLanguage');
Support I18Next
http://i18next.com
- Read translations files from folder, every folder is a language code
- JSON
- YAML
- PHP Array
- Write translations files to a folder, every folder is a language code
- JSON
- YAML
- PHP Array
- Get a defined translation in primary language
- If not found try in fallback language
- If not found return original string
- If not found try in fallback language
- Namespaces
- Get defined translation based on prioritized fallback namespaces
- Context as {key}_{context}
- Plurals
- Singular as {key}
- Plurals as {key}_plural
- Multiple plurals as {key}_{int $counter}
- Manage when $counter is bigger than max defined plurals
- Nested interpolate plurals
- Intervals
- Interpolate
- Replace {{key}} with defined $paramater value
- If {{key}} has a point like {{key.index}} and $parameters[index] is an array or object will retrive the value
- Replace {{key}} with defined $paramater value
- Nesting
- Basic
- Plurals
- Formatting
- Adding Helper for use method Translator::_ as global functions __
- Adding Helper for use Translator as a global singleton instance
- Collect missing requested keys
- Adding Helper for search/collect calls to method Translator _ in code
- Added direct translations using key as translation
Support ATK4 - Agile Toolkit Model
https://www.agiletoolkit.org
- Interpolate with \atk4\data\Model