Agile Toolkit Translation library

Based on I18Next library

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/

Getting started

Instantiate

$translator = new Translator();

Define root path for translations

$translator->setTranslationsPath('path/to/locales');

(optional) Define if filename has to be used has namespace

$translator->useFilenameAsNamespace(true);

(optional) Define namespaces priority

$translator->setNamespacePriority('firstNs','secondNs','otherNs');

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

$translator->setLanguagePrimary($language);
$translator->setLanguageFallback($fallback);

Add additional language

$translator->addLanguage('it');

Usage examples

1
2
3
4
5
$result = $translator->_('definitionKey');
$result = $translator->_('definitionKey', ['param1' => 'test']);
$result = $translator->_('definitionKey', ['param1' => 'test'], 'context');
$result = $translator->_('definitionKey', ['param1' => 'test'], 'context', 'specificLanguage');
$result = $translator->_('namespace:definitionKey', ['param1' => 'test'], 'context', 'specificLanguage');

The TranslatorInterface

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
<?php

declare(strict_types=1);

namespace I18Next;

interface TranslatorInterface
{
    /**
     * Translates the given message.
     *
     * @param string      $key
     * @param array|null  $parameters Array of parameters used to translate message
     * @param string|null $context    The context of the request
     * @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;
}

I18Next

\I18Next

Namespaces

Exception

\I18Next\Exception

Classes
TranslationSyntaxError
class I18Next\Exception\TranslationSyntaxError
Source:src/I18Next/Exception/TranslationSyntaxError.php#9
Parent:atk4\core\Exception
Summary
LanguageNamespaceMisuse
class I18Next\Exception\LanguageNamespaceMisuse
Source:src/I18Next/Exception/LanguageNamespaceMisuse.php#7
Parent:I18Next\Exception\Misusage
Summary
LanguageAlreadyPresent
class I18Next\Exception\LanguageAlreadyPresent
Source:src/I18Next/Exception/LanguageAlreadyPresent.php#9
Parent:atk4\core\Exception
Summary
LanguageLocaleNotExists
class I18Next\Exception\LanguageLocaleNotExists
Source:src/I18Next/Exception/LanguageLocaleNotExists.php#9
Parent:atk4\core\Exception
Summary
Misusage
class I18Next\Exception\Misusage
Source:src/I18Next/Exception/Misusage.php#9
Parent:atk4\core\Exception
Summary
LanguagePathNotDefined
class I18Next\Exception\LanguagePathNotDefined
Source:src/I18Next/Exception/LanguagePathNotDefined.php#9
Parent:atk4\core\Exception
Summary
NotFoundKey
class I18Next\Exception\NotFoundKey
Source:src/I18Next/Exception/NotFoundKey.php#10
Parent:atk4\core\Exception
Implements:Throwable
Summary
Locale

\I18Next\Locale

Namespaces
Processor

\I18Next\Locale\Processor

Namespaces
Classes
Key
class I18Next\Locale\Processor\Key
Source:src/I18Next/Locale/Processor/Key.php#10
Parent:I18Next\Locale\Processor\AbstractProcessor
Summary
Methods
  • public processKey($key, $context, $counter)
  • private processWithCounter($key, $counter)
  • private process($key)
  • private processWithNamespaceWithCounter($key, $counter)
  • private processWithNamespace($key)
  • private getKeyNamespace($key)
  • private getOnlyKeyFromNamespacedKey($key, $namespace)
Methods
public I18Next\Locale\Processor\Key::processKey($key, $context=null, $counter=null)
Source:

src/I18Next/Locale/Processor/Key.php#19

Parameters:
  • $key (string)
  • $context (string | null)
  • $counter (int | null)
Returns:

string | null

Value
class I18Next\Locale\Processor\Value
Source:src/I18Next/Locale/Processor/Value.php#12
Parent:I18Next\Locale\Processor\AbstractProcessor
Summary
Methods
  • public processValue($found_key, $parameters)
  • private processValueInterpolate($found_key, $parameters)
  • private processValueReplaceParameter($found_key, $index, $parameters)
  • private processValueNested($found_key, $parameters)
Methods
public I18Next\Locale\Processor\Value::processValue(&$found_key, $parameters)
Source:

src/I18Next/Locale/Processor/Value.php#20

Parameters:
  • $found_key (string | null)
  • $parameters (array | null)
Returns:

string | null

AbstractProcessor
class I18Next\Locale\Processor\AbstractProcessor
Source:src/I18Next/Locale/Processor/AbstractProcessor.php#12
Properties
protected static property I18Next\Locale\Processor\AbstractProcessor::$translations
Source:src/I18Next/Locale/Processor/AbstractProcessor.php#15
Type:\I18Next\Locale\Translations
Methods
public I18Next\Locale\Processor\AbstractProcessor::__construct($translations)
AbstractProcessor constructor.
Source:

src/I18Next/Locale/Processor/AbstractProcessor.php#22

Parameters:
Classes
Processor
class I18Next\Locale\Processor
Source:src/I18Next/Locale/Processor.php#13
Summary
Methods
Properties
Methods
public I18Next\Locale\Processor::__construct($translations)
Processor constructor.
Source:

src/I18Next/Locale/Processor.php#29

Parameters:
public I18Next\Locale\Processor::process($key, $parameters=null, $context=null)
Source:

src/I18Next/Locale/Processor.php#43

Parameters:
  • $key (string)
  • $parameters (array | null)
  • $context (string | null)
Returns:

string | null

Translations
class I18Next\Locale\Translations
Source:src/I18Next/Locale/Translations.php#19
Used traits:atk4\core\ConfigTrait
Summary
Methods
Properties
protected static property I18Next\Locale\Translations::$namespace_priority
Source:src/I18Next/Locale/Translations.php#27
Type:string[]
protected static property I18Next\Locale\Translations::$use_filename_as_namespace
Source:src/I18Next/Locale/Translations.php#30
Type:bool
Methods
public I18Next\Locale\Translations::load($path, $use_filename_as_namespace, ...$namespace_priority)
Source:

src/I18Next/Locale/Translations.php#45

Parameters:
  • $path (string)
  • $use_filename_as_namespace (bool)
  • …$namespace_priority (string | null)
Throws:

\atk4\core\Exception

public I18Next\Locale\Translations::useFilenameAsNamespace($enabled)
Source:

src/I18Next/Locale/Translations.php#97

Parameters:
  • $enabled (bool | null)
public I18Next\Locale\Translations::useNamespaces()
Source:src/I18Next/Locale/Translations.php#197
Returns:bool
public I18Next\Locale\Translations::getNamespaceRanked()
Source:src/I18Next/Locale/Translations.php#205
Returns:string[]
public I18Next\Locale\Translations::setLoaderFormat($format)
Source:

src/I18Next/Locale/Translations.php#213

Parameters:
  • $format (string)
atk4

\I18Next\atk4

Traits
TranslatorI18NextTrait
trait I18Next\atk4\TranslatorI18NextTrait
Source:src/I18Next/atk4/TranslatorI18NextTrait.php#10
Properties
protected static property I18Next\atk4\TranslatorI18NextTrait::$translator
Source:src/I18Next/atk4/TranslatorI18NextTrait.php#13
Type:\I18Next\TranslatorInterface
Methods
public I18Next\atk4\TranslatorI18NextTrait::setTranslator($translator)
Source:

src/I18Next/atk4/TranslatorI18NextTrait.php#20

Parameters:
Returns:

\I18Next\TranslatorInterface

public I18Next\atk4\TranslatorI18NextTrait::_($message, $parameters=null, $domain=null, $locale=null)
Translates the given message.
Source:

src/I18Next/atk4/TranslatorI18NextTrait.php#36

Parameters:
  • $message (string) The message to be translated
  • $parameters (array | null) Array of parameters used to translate message
  • $domain (string | null) The domain for the message or null to use the default
  • $locale (string | null) The locale or null to use the default
Throws:

\atk4\core\Exception

Returns:

string The translated string

Interfaces

TranslatorInterface
interface I18Next\TranslatorInterface
Source:src/I18Next/TranslatorInterface.php#7
Methods
public I18Next\TranslatorInterface::_($key, $parameters=null, $context=null, $locale=null)
Translates the given message.
Source:

src/I18Next/TranslatorInterface.php#19

Parameters:
  • $key (string)
  • $parameters (array | null) Array of parameters used to translate message
  • $context (string | null) The context of the request
  • $locale (string | null) The locale or null to use the default
Returns:

string The translated string

Classes

Locale
class I18Next\Locale
Source:src/I18Next/Locale.php#14
Properties
Methods
public I18Next\Locale::__construct($code)
Locale constructor.
Source:

src/I18Next/Locale.php#33

Parameters:
  • $code (string)
public I18Next\Locale::load($path, $use_filename_as_namespace, ...$namespace_priority)
Source:

src/I18Next/Locale.php#47

Parameters:
  • $path (string)
  • $use_filename_as_namespace (bool)
  • …$namespace_priority (string | null)
Throws:

\atk4\core\Exception

public I18Next\Locale::process($key, $parameters=null, $context=null)
Source:

src/I18Next/Locale.php#59

Parameters:
  • $key (string)
  • $parameters (array | null)
  • $context (string | null)
Returns:

string | null

public I18Next\Locale::setLoaderFormat($format)
Source:

src/I18Next/Locale.php#67

Parameters:
  • $format (string)
TranslatorStatic
class I18Next\TranslatorStatic
Source:src/I18Next/TranslatorStatic.php#13
Properties
Methods
public static I18Next\TranslatorStatic::instance()
Source:src/I18Next/TranslatorStatic.php#18
public static I18Next\TranslatorStatic::setTranslationsPath($path)
Source:

src/I18Next/TranslatorStatic.php#32

Parameters:
  • $path (string)
Throws:

\I18Next\Exception\Misusage

public static I18Next\TranslatorStatic::setNamespacePriority(...$namespace_priority)
Source:

src/I18Next/TranslatorStatic.php#42

Parameters:
  • …$namespace_priority (mixed)
Throws:

\I18Next\Exception\LanguageNamespaceMisuse

public static I18Next\TranslatorStatic::useFilenameAsNamespace($enabled)
Source:

src/I18Next/TranslatorStatic.php#52

Parameters:
  • $enabled (bool | null)
Throws:

\I18Next\Exception\LanguageNamespaceMisuse

public static I18Next\TranslatorStatic::setLanguagePrimary($language_code)
Source:

src/I18Next/TranslatorStatic.php#64

Parameters:
  • $language_code (string)
Throws:

\atk4\core\Exception

Throws:

\I18Next\Exception\LanguageAlreadyPresent

Throws:

\I18Next\Exception\LanguagePathNotDefined

Throws:

\atk4\core\Exception

Throws:

\I18Next\Exception\LanguageAlreadyPresent

Throws:

\I18Next\Exception\LanguagePathNotDefined

Throws:

\atk4\core\Exception

Throws:

\I18Next\Exception\LanguageAlreadyPresent

Throws:

\I18Next\Exception\LanguagePathNotDefined

public static I18Next\TranslatorStatic::addLanguage($code)
Source:

src/I18Next/TranslatorStatic.php#76

Parameters:
  • $code (string)
Throws:

\atk4\core\Exception

Throws:

\I18Next\Exception\LanguageAlreadyPresent

Throws:

\I18Next\Exception\LanguagePathNotDefined

Throws:

\atk4\core\Exception

Throws:

\I18Next\Exception\LanguageAlreadyPresent

Throws:

\I18Next\Exception\LanguagePathNotDefined

Throws:

\atk4\core\Exception

Throws:

\I18Next\Exception\LanguageAlreadyPresent

Throws:

\I18Next\Exception\LanguagePathNotDefined

public static I18Next\TranslatorStatic::setLanguageFallback($fallback_code)
Source:

src/I18Next/TranslatorStatic.php#88

Parameters:
  • $fallback_code (string)
Throws:

\atk4\core\Exception

Throws:

\I18Next\Exception\LanguageAlreadyPresent

Throws:

\I18Next\Exception\LanguagePathNotDefined

Throws:

\atk4\core\Exception

Throws:

\I18Next\Exception\LanguageAlreadyPresent

Throws:

\I18Next\Exception\LanguagePathNotDefined

Throws:

\atk4\core\Exception

Throws:

\I18Next\Exception\LanguageAlreadyPresent

Throws:

\I18Next\Exception\LanguagePathNotDefined

public static I18Next\TranslatorStatic::_($key, $parameters=null, $context=null, $locale=null)
Source:

src/I18Next/TranslatorStatic.php#101

Parameters:
  • $key (string)
  • $parameters (array | null)
  • $context (string | null)
  • $locale (string | null)
Returns:

string

public static I18Next\TranslatorStatic::register()
Register global function _.
Source:src/I18Next/TranslatorStatic.php#109
Translator
class I18Next\Translator
Source:src/I18Next/Translator.php#14
Implements:I18Next\TranslatorInterface
Properties
Methods
public I18Next\Translator::setTranslationsPath($path)
Set the root path of locales folder.
Source:

src/I18Next/Translator.php#45

Parameters:
  • $path (string)
Throws:

\I18Next\Exception\Misusage

public I18Next\Translator::setNamespacePriority(...$namespace_priority)
Set namespace priority.
Source:

src/I18Next/Translator.php#63

Parameters:
  • …$namespace_priority (mixed)
Throws:

\I18Next\Exception\LanguageNamespaceMisuse

public I18Next\Translator::useFilenameAsNamespace($enabled)
Set if filenames will be used as namespaces.
Source:

src/I18Next/Translator.php#79

Parameters:
  • $enabled (bool | null)
Throws:

\I18Next\Exception\LanguageNamespaceMisuse

public I18Next\Translator::setLanguagePrimary($language_code)
Set Primary Language.
Source:

src/I18Next/Translator.php#97

Parameters:
  • $language_code (string)
Throws:

\I18Next\Exception\LanguageAlreadyPresent

Throws:

\I18Next\Exception\LanguagePathNotDefined

Throws:

\atk4\core\Exception

Throws:

\I18Next\Exception\LanguageAlreadyPresent

Throws:

\I18Next\Exception\LanguagePathNotDefined

Throws:

\atk4\core\Exception

Throws:

\I18Next\Exception\LanguageAlreadyPresent

Throws:

\I18Next\Exception\LanguagePathNotDefined

Throws:

\atk4\core\Exception

public I18Next\Translator::addLanguage($code)
Add Extra languages.
Source:

src/I18Next/Translator.php#112

Parameters:
  • $code (string)
Throws:

\atk4\core\Exception

Throws:

\I18Next\Exception\LanguageAlreadyPresent

Throws:

\I18Next\Exception\LanguagePathNotDefined

Throws:

\atk4\core\Exception

Throws:

\I18Next\Exception\LanguageAlreadyPresent

Throws:

\I18Next\Exception\LanguagePathNotDefined

Throws:

\atk4\core\Exception

Throws:

\I18Next\Exception\LanguageAlreadyPresent

Throws:

\I18Next\Exception\LanguagePathNotDefined

public I18Next\Translator::setLanguageFallback($fallback_code)
Set fallback language.
Source:

src/I18Next/Translator.php#138

Parameters:
  • $fallback_code (string)
Throws:

\atk4\core\Exception

Throws:

\I18Next\Exception\LanguageAlreadyPresent

Throws:

\I18Next\Exception\LanguagePathNotDefined

Throws:

\atk4\core\Exception

Throws:

\I18Next\Exception\LanguageAlreadyPresent

Throws:

\I18Next\Exception\LanguagePathNotDefined

Throws:

\atk4\core\Exception

Throws:

\I18Next\Exception\LanguageAlreadyPresent

Throws:

\I18Next\Exception\LanguagePathNotDefined

public I18Next\Translator::_($key, $parameters=null, $context=null, $locale=null)
Source:src/I18Next/Translator.php#147

Indices and tables