PHP code example of polyglot / template-resolver-simple
1. Go to this page and download the library: Download polyglot/template-resolver-simple library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
polyglot / template-resolver-simple example snippets
use Polyglot\SimpleTemplateResolver\PluralHandler;
use Polyglot\SimpleTemplateResolver\SimpleTemplateResolver;
/**
* @var string $prefix Prefix of parameter name in template, by default, "{"
* @var string $suffix Suffix of parameter name in template, by default, "}"
* @var string $pluralParameter Plural parameter name in template, by default, "count"
* @var string $templateDelimiter Plural template delimiter, by default, "|"
* @var PluralDetectorRegistry $pluralDetectorRegistry Plural detector registry
*/
$pluralHandler = new PluralHandler($pluralDetectorRegistry, $pluralParameter, $templateDelimiter);
$resolver = new SimpleTemplateResolver($prefix, $suffix, $pluralHandler);
/**
* @var string $template Translation template
* @var array<string, string|Stringable> $parameters Translation parameters
* @var string $locale Translation locale
*/
$translation = $resolver->resolve($template, $parameters, $locale);