PHP Classes
elePHPant
Icontem

ATK4 i18next PHP: Translate application texts like il8next-PHP

Recommend this page to a friend!
  Info   View files Documentation   View files View files (468)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2019-07-15 (18 days ago) RSS 2.0 feedNot yet rated by the usersTotal: Not yet counted Not yet ranked
Version License PHP version Categories
atk4-i18next-php 1.0MIT/X Consortium ...7Localization, PHP 7
Collaborate with this project Author

atk4-i18next-php - github.com

Description

This package can Translate application texts like il8next-PHP.

It can provide localized texts for the use in the current page based on the URL of the HTTP request.

The locale text translations will be read from files stored in a given directory. If the files for the current language are missing, it can read the locale texts, from the default language texts.

  Performance   Level  
Innovation award
Innovation award
Nominee: 1x

 

Details

PHP Language library

Based on i18next http://i18next.com

Interpolate direct with ATK4 - Agile Toolkit Models https://www.agiletoolkit.org/

Build Status Codacy Badge Codacy Badge Coverage Status StyleCI Maintainability Test Coverage

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 TranslatorMock();
$this->translator->setTranslationsPath(__DIR__.'/data/locales');

Define if filename will be used has namespace :

$this->translator->useFilenameAsNamespace(true);

Define primary and fallback language (name of the folders where library load files) :

$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

  • [x] Read translations files from folder, every folder is a language code - [x] JSON - [ ] YAML - [ ] PHP Array
  • [ ] Write translations files to a folder, every folder is a language code - [ ] JSON - [ ] YAML - [ ] PHP Array
  • [x] Get a defined translation in primary language - [x] If not found try in fallback language - [x] If not found return original string
  • [x] Namespaces - [x] Get defined translation based on prioritized fallback namespaces
  • [x] Context as {key}_{context}
  • [x] Plurals - [x] Singular as {key} - [x] Plurals as {key}_plural - [x] Multiple plurals as {key}_{int $counter} - [x] Manage when $counter is bigger than max defined plurals - [x] Nested interpolate plurals - [x] Intervals
  • [x] Interpolate - [x] Replace {{key}} with defined $paramater value - [x] If {{key}} has a point like {{key.index}} and $parameters[index] is an array or object will retrive the value
  • [x] Nesting - [x] Basic - [x] Plurals
  • [ ] Formatting
  • [x] Adding Helper for use method Translator::_ as global functions __
  • [x] 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
  • [x] Added direct translations using key as translation

Support ATK4 - Agile Toolkit Model

https://www.agiletoolkit.org

  • [x] Interpolate with \atk4\data\Model
  Files folder image Files  
File Role Description
Files folder imagedocs (11 files, 7 directories)
Files folder imagesrc (1 directory)
Files folder imagetests (17 files, 1 directory)
Accessible without login Plain text file .codeclimate.yml Data Auxiliary data
Accessible without login Plain text file .coveralls.yml Data Auxiliary data
Accessible without login Plain text file .phpdoc.xml Data Auxiliary data
Accessible without login Plain text file .phpmetrics.json Data Auxiliary data
Accessible without login Plain text file .php_cs.dist Example Example script
Accessible without login Plain text file .styleci.yml Data Auxiliary data
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file renovate.json Data Auxiliary data

 Version Control Unique User Downloads  
 99%
Total:0
This week:0