pax_global_header 0000666 0000000 0000000 00000000064 14500127216 0014510 g ustar 00root root 0000000 0000000 52 comment=a514a2afd29717a2a68c298582cc2739e8edeed0
twig-i18n-extension-4.1.0/ 0000775 0000000 0000000 00000000000 14500127216 0015253 5 ustar 00root root 0000000 0000000 twig-i18n-extension-4.1.0/CHANGELOG.md 0000664 0000000 0000000 00000003011 14500127216 0017057 0 ustar 00root root 0000000 0000000 # Change Log
## [4.1.0] - 2023-09-12
* Drop support for PHP 7.2
* Add support for PHP 8.3
## [4.0.1] - 2021-06-10
* Fix TransNode constructor optional parameters
## [4.0.0] - 2021-02-25
* Add support for domain translation (#4)
* TransNode constructor signature changed, new $domain parameter `?Node $notes, ?Node $domain = null, int $lineno` (#4)
* TransNode constructor signature changed, new $context parameter `?AbstractExpression $count, ?Node $context = null, ?Node $notes` (#6)
* Add support for contexts in translations (#6)
* Add support for enabling `phpmyadmin/motranslator` or complex non php-gettext supported functions (#6)
* Add support for custom notes labels (#6)
* Make debug info disabled by default, `TransNode::$enableAddDebugInfo = true;` will add it back
* Some slight performance improvements
* Added tests for all the code
## [3.0.0] - 2020-06-14
* Add a .gitattributes file
* Support Twig 3
* Remove extra field from composer.json
* Add support field in composer.json
* Require php >= 7.1
* Setup and apply phpmyadmin/coding-standard
* Apply changes for php 8.0 compatibility (https://github.com/twigphp/Twig/issues/3327)
## 2.0.0 - 2020-01-14
* First release of this library.
[4.1.0]: https://github.com/phpmyadmin/twig-i18n-extension/compare/v4.0.1...4.1.0
[4.0.1]: https://github.com/phpmyadmin/twig-i18n-extension/compare/v4.0.0...v4.0.1
[4.0.0]: https://github.com/phpmyadmin/twig-i18n-extension/compare/v3.0.0...v4.0.0
[3.0.0]: https://github.com/phpmyadmin/twig-i18n-extension/compare/v2.0.0...v3.0.0
twig-i18n-extension-4.1.0/LICENSE 0000664 0000000 0000000 00000002131 14500127216 0016255 0 ustar 00root root 0000000 0000000 Copyright (c) 2010-2019 Fabien Potencier
Copyright (c) 2019-2021 phpMyAdmin contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
twig-i18n-extension-4.1.0/README.rst 0000664 0000000 0000000 00000015317 14500127216 0016751 0 ustar 00root root 0000000 0000000 Twig i18n Extension
===================
The ``i18n`` extension adds `gettext`_ support to Twig. It defines one tag,
``trans``.
Code status
-----------
.. image:: https://github.com/phpmyadmin/twig-i18n-extension/workflows/Run%20tests/badge.svg?branch=master
:alt: Tests
:target: https://github.com/phpmyadmin/twig-i18n-extension/actions
.. image:: https://codecov.io/gh/phpmyadmin/twig-i18n-extension/branch/master/graph/badge.svg
:alt: Code coverage
:target: https://codecov.io/gh/phpmyadmin/twig-i18n-extension
Installation
------------
This library can be installed via Composer running the following from the
command line:
.. code-block:: bash
composer require phpmyadmin/twig-i18n-extension
Configuration
-------------
You need to register this extension before using the ``trans`` block
.. code-block:: php
use PhpMyAdmin\Twig\Extensions\I18nExtension;
$twig->addExtension(new I18nExtension());
Note that you must configure the ``gettext`` extension before rendering any
internationalized template. Here is a simple configuration example from the
PHP `documentation`_
.. code-block:: php
// Set language to French
putenv('LC_ALL=fr_FR');
setlocale(LC_ALL, 'fr_FR');
// Specify the location of the translation tables
bindtextdomain('myAppPhp', 'includes/locale');
bind_textdomain_codeset('myAppPhp', 'UTF-8');
// Choose domain
textdomain('myAppPhp');
.. caution::
The ``i18n`` extension only works if the PHP `gettext`_ extension is
enabled.
Usage
-----
Use the ``trans`` block to mark parts in the template as translatable:
.. code-block:: twig
{% trans "Hello World!" %}
{% trans string_var %}
{% trans %}
Hello World!
{% endtrans %}
In a translatable string, you can embed variables:
.. code-block:: twig
{% trans %}
Hello {{ name }}!
{% endtrans %}
During the gettext lookup these placeholders are converted. ``{{ name }}`` becomes ``%name%`` so the gettext ``msgid`` for this string would be ``Hello %name%!``.
.. note::
``{% trans "Hello {{ name }}!" %}`` is not a valid statement.
If you need to apply filters to the variables, you first need to assign the
result to a variable:
.. code-block:: twig
{% set name = name|capitalize %}
{% trans %}
Hello {{ name }}!
{% endtrans %}
To pluralize a translatable string, use the ``plural`` block:
.. code-block:: twig
{% trans %}
Hey {{ name }}, I have one apple.
{% plural apple_count %}
Hey {{ name }}, I have {{ count }} apples.
{% endtrans %}
The ``plural`` tag should provide the ``count`` used to select the right
string. Within the translatable string, the special ``count`` variable always
contain the count value (here the value of ``apple_count``).
To add notes for translators, use the ``notes`` block:
.. code-block:: twig
{% trans %}
Hey {{ name }}, I have one apple.
{% plural apple_count %}
Hey {{ name }}, I have {{ count }} apples.
{% notes %}
This is shown in the user menu. This string should be shorter than 30 chars
{% endtrans %}
You can use ``notes`` with or without ``plural``. Once you get your templates compiled you should
configure the ``gettext`` parser to get something like this: ``xgettext --add-comments=notes``
Within an expression or in a tag, you can use the ``trans`` filter to translate
simple strings or variables:
.. code-block:: twig
{{ var|default(default_value|trans) }}
Complex Translations within an Expression or Tag
------------------------------------------------
Translations can be done with both the ``trans`` tag and the ``trans`` filter.
The filter is less powerful as it only works for simple variables or strings.
For more complex scenario, like pluralization, you can use a two-step
strategy:
.. code-block:: twig
{# assign the translation to a temporary variable #}
{% set default_value %}
{% trans %}
Hey {{ name }}, I have one apple.
{% plural apple_count %}
Hey {{ name }}, I have {{ count }} apples.
{% endtrans %}
{% endset %}
{# use the temporary variable within an expression #}
{{ var|default(default_value|trans) }}
Extracting Template Strings
---------------------------
If you use the Twig I18n extension, you will probably need to extract the
template strings at some point.
Using Poedit 2
~~~~~~~~~~~~~~
Poedit 2 has native support for extracting from Twig files and no extra
setup is necessary (Pro version).
Using ``xgettext`` or Poedit 1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unfortunately, the ``xgettext`` utility does not understand Twig templates
natively and neither do tools based on it such as free versions of Poedit.
But there is a simple workaround: as Twig converts templates to
PHP files, you can use ``xgettext`` on the template cache instead.
Create a script that forces the generation of the cache for all your
templates. Here is a simple example to get you started
.. code-block:: php
use Twig\Environment;
use Twig\Loader\FilesystemLoader;
use PhpMyAdmin\Twig\Extensions\I18nExtension;
$tplDir = __DIR__ . '/templates';
$tmpDir = '/tmp/cache/';
$loader = new FilesystemLoader($tplDir);
// force auto-reload to always have the latest version of the template
$twig = new Environment($loader, [
'auto_reload' => true,
'cache' => $tmpDir,
]);
$twig->addExtension(new I18nExtension());
// configure Twig the way you want
// iterate over all your templates
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($tplDir), RecursiveIteratorIterator::LEAVES_ONLY) as $file)
{
// force compilation
if ($file->isFile()) {
$twig->loadTemplate(str_replace($tplDir . '/', '', $file));
}
}
Use the standard ``xgettext`` utility as you would have done with plain PHP
code:
.. code-block:: text
xgettext --default-domain=messages -p ./locale --from-code=UTF-8 -n --omit-header -L PHP /tmp/cache/*.php
Another workaround is to use `Twig Gettext Extractor`_ and extract the template
strings right from `Poedit`_.
.. _`gettext`: https://www.php.net/gettext
.. _`documentation`: https://www.php.net/manual/en/function.gettext.php
.. _`Twig Gettext Extractor`: https://github.com/umpirsky/Twig-Gettext-Extractor#readme
.. _`Poedit`: https://poedit.net/
History
-------
This project was forked in 2019 by the phpMyAdmin team, since it was abandoned by the
`Twig project`_ but was still in use for phpMyAdmin.
.. _`Twig project`: https://github.com/twigphp/Twig-extensions
If you find this work useful, or have a pull request to contribute, please find us on
`Github`_.
.. _`Github`: https://github.com/phpmyadmin/twig-i18n-extension/
twig-i18n-extension-4.1.0/composer.json 0000664 0000000 0000000 00000002712 14500127216 0017777 0 ustar 00root root 0000000 0000000 {
"name": "phpmyadmin/twig-i18n-extension",
"description": "Internationalization support for Twig via the gettext library",
"keywords": ["i18n","gettext"],
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "The phpMyAdmin Team",
"email": "developers@phpmyadmin.net",
"homepage": "https://www.phpmyadmin.net/team/"
}
],
"support": {
"issues": "https://github.com/phpmyadmin/twig-i18n-extension/issues",
"source": "https://github.com/phpmyadmin/twig-i18n-extension"
},
"require": {
"php": "^7.2 || ^8.0",
"twig/twig": "^1.42.3|^2.0|^3.0"
},
"require-dev": {
"phpmyadmin/coding-standard": "^3.0.0",
"phpmyadmin/motranslator": "^5.2",
"phpstan/phpstan": "^1.9.4",
"phpunit/phpunit": "^7 || ^8 || ^9"
},
"scripts": {
"phpstan": "./vendor/bin/phpstan analyse",
"phpunit": "phpunit",
"phpcs": "phpcs",
"phpcbf": "phpcbf"
},
"autoload": {
"psr-4": { "PhpMyAdmin\\Twig\\Extensions\\": "src/" }
},
"autoload-dev": {
"psr-4": { "PhpMyAdmin\\Tests\\Twig\\Extensions\\": "test/" }
},
"config":{
"sort-packages": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
twig-i18n-extension-4.1.0/phpunit.xml.dist 0000664 0000000 0000000 00000001367 14500127216 0020435 0 ustar 00root root 0000000 0000000
./test/
./src/
twig-i18n-extension-4.1.0/src/ 0000775 0000000 0000000 00000000000 14500127216 0016042 5 ustar 00root root 0000000 0000000 twig-i18n-extension-4.1.0/src/I18nExtension.php 0000664 0000000 0000000 00000003034 14500127216 0021167 0 ustar 00root root 0000000 0000000
*/
class TransNode extends Node
{
/**
* The label for gettext notes to be exported
*
* @var string
*/
public static $notesLabel = '// notes: ';
/**
* Enable MoTranslator functions
*
* @var bool
*/
public static $enableMoTranslator = false;
/**
* Enable calls to addDebugInfo
*
* @var bool
*/
public static $enableAddDebugInfo = false;
/**
* Enables context functions usage
*
* @var bool
*/
public static $hasContextFunctions = false;
public function __construct(
Node $body,
?Node $plural,
?AbstractExpression $count,
?Node $context = null,
?Node $notes = null,
?Node $domain = null,
int $lineno = 0,
?string $tag = null
) {
$nodes = ['body' => $body];
if ($count !== null) {
$nodes['count'] = $count;
}
if ($plural !== null) {
$nodes['plural'] = $plural;
}
if ($notes !== null) {
$nodes['notes'] = $notes;
}
if ($domain !== null) {
$nodes['domain'] = $domain;
}
if ($context !== null) {
$nodes['context'] = $context;
}
parent::__construct($nodes, [], $lineno, $tag);
}
/**
* {@inheritdoc}
*/
public function compile(Compiler $compiler)
{
if (self::$enableAddDebugInfo) {
$compiler->addDebugInfo($this);
}
[$msg, $vars] = $this->compileString($this->getNode('body'));
$hasPlural = $this->hasNode('plural');
if ($hasPlural) {
[$msg1, $vars1] = $this->compileString($this->getNode('plural'));
$vars = array_merge($vars, $vars1);
}
$hasDomain = $this->hasNode('domain');
$hasContext = $this->hasNode('context');
$function = $this->getTransFunction($hasPlural, $hasContext, $hasDomain);
if ($this->hasNode('notes')) {
$message = trim($this->getNode('notes')->getAttribute('data'));
// line breaks are not allowed cause we want a single line comment
$message = str_replace(["\n", "\r"], ' ', $message);
$compiler->raw(static::$notesLabel . $message . "\n");
}
if ($vars) {
$compiler
->raw('echo strtr(' . $function . '(');
if ($hasDomain) {
[$domain] = $this->compileString($this->getNode('domain'));
$compiler
->subcompile($domain)
->raw(', ');
}
if ($hasContext && (static::$hasContextFunctions || static::$enableMoTranslator)) {
[$context] = $this->compileString($this->getNode('context'));
$compiler
->subcompile($context)
->raw(', ');
}
$compiler
->subcompile($msg);
if ($hasPlural) {
$compiler
->raw(', ')
->subcompile($msg1)
->raw(', abs(')
->subcompile($this->getNode('count'))
->raw(')');
}
$compiler->raw('), array(');
foreach ($vars as $var) {
$attributeName = $var->getAttribute('name');
if ($attributeName === 'count') {
$compiler
->string('%count%')
->raw(' => abs(')
->subcompile($this->getNode('count'))
->raw('), ');
} else {
$compiler
->string('%' . $attributeName . '%')
->raw(' => ')
->subcompile($var)
->raw(', ');
}
}
$compiler->raw("));\n");
} else {
$compiler
->raw('echo ' . $function . '(');
if ($hasDomain) {
[$domain] = $this->compileString($this->getNode('domain'));
$compiler
->subcompile($domain)
->raw(', ');
}
if ($hasContext) {
if (static::$hasContextFunctions || static::$enableMoTranslator) {
[$context] = $this->compileString($this->getNode('context'));
$compiler
->subcompile($context)
->raw(', ');
}
}
$compiler
->subcompile($msg);
if ($hasPlural) {
$compiler
->raw(', ')
->subcompile($msg1)
->raw(', abs(')
->subcompile($this->getNode('count'))
->raw(')');
}
$compiler->raw(");\n");
}
}
/**
* Keep this method protected instead of private some implementations may use it
*/
protected function compileString(Node $body): array
{
if (
$body instanceof NameExpression
|| $body instanceof ConstantExpression
|| $body instanceof TempNameExpression
) {
return [$body, []];
}
$vars = [];
if (count($body)) {
$msg = '';
foreach ($body as $node) {
if ($node instanceof PrintNode) {
$n = $node->getNode('expr');
while ($n instanceof FilterExpression) {
$n = $n->getNode('node');
}
while ($n instanceof CheckToStringNode) {
$n = $n->getNode('expr');
}
$attributeName = $n->getAttribute('name');
$msg .= sprintf('%%%s%%', $attributeName);
$vars[] = new NameExpression($attributeName, $n->getTemplateLine());
} else {
/** @phpstan-var TextNode $node */
$msg .= $node->getAttribute('data');
}
}
} else {
$msg = $body->getAttribute('data');
}
return [new Node([new ConstantExpression(trim($msg), $body->getTemplateLine())]), $vars];
}
/**
* Keep this protected to allow people to override it with their own logic
*/
protected function getTransFunction(bool $hasPlural, bool $hasContext, bool $hasDomain): string
{
$functionPrefix = '';
if (static::$enableMoTranslator) {
// The functions are prefixed with an underscore
$functionPrefix = '_';
}
// If it has not context function support or not MoTranslator
if (! static::$hasContextFunctions && ! static::$enableMoTranslator) {
// Not found on native PHP: dnpgettext, npgettext, dpgettext, pgettext
// No domain plural context support
// No domain context support
// No context support
// No plural context support
if ($hasDomain) {
// dngettext($domain, $msgid, $msgidPlural, $number);
// dgettext($domain, $msgid);
return $functionPrefix . ($hasPlural ? 'dngettext' : 'dgettext');
}
// ngettext($msgid, $msgidPlural, $number);
// gettext($msgid);
return $functionPrefix . ($hasPlural ? 'ngettext' : 'gettext');
}
if ($hasDomain) {
if ($hasPlural) {
// dnpgettext($domain, $msgctxt, $msgid, $msgidPlural, $number);
// dngettext($domain, $msgid, $msgidPlural, $number);
return $functionPrefix . ($hasContext ? 'dnpgettext' : 'dngettext');
}
// dpgettext($domain, $msgctxt, $msgid);
// dgettext($domain, $msgid);
return $functionPrefix . ($hasContext ? 'dpgettext' : 'dgettext');
}
if ($hasPlural) {
// npgettext($msgctxt, $msgid, $msgidPlural, $number);
// ngettext($msgid, $msgidPlural, $number);
return $functionPrefix . ($hasContext ? 'npgettext' : 'ngettext');
}
// pgettext($msgctxt, $msgid);
// gettext($msgid);
return $functionPrefix . ($hasContext ? 'pgettext' : 'gettext');
}
}
twig-i18n-extension-4.1.0/src/TokenParser/ 0000775 0000000 0000000 00000000000 14500127216 0020277 5 ustar 00root root 0000000 0000000 twig-i18n-extension-4.1.0/src/TokenParser/TransTokenParser.php 0000664 0000000 0000000 00000010146 14500127216 0024257 0 ustar 00root root 0000000 0000000 preParse($token);
return new TransNode($body, $plural, $count, $context, $notes, $domain, $lineno, $tag);
}
protected function preParse(Token $token): array
{
$lineno = $token->getLine();
$stream = $this->parser->getStream();
$domain = null;
$count = null;
$plural = null;
$notes = null;
$context = null;
/* If we aren't closing the block, do we have a domain? */
if ($stream->test(Token::NAME_TYPE)) {
$stream->expect(Token::NAME_TYPE, 'from');
$domain = $this->parser->getExpressionParser()->parseExpression();
}
if (! $stream->test(Token::BLOCK_END_TYPE)) {
$body = $this->parser->getExpressionParser()->parseExpression();
} else {
$stream->expect(Token::BLOCK_END_TYPE);
$body = $this->parser->subparse([$this, 'decideForFork']);
$next = $stream->next()->getValue();
if ($next === 'plural') {
$count = $this->parser->getExpressionParser()->parseExpression();
$stream->expect(Token::BLOCK_END_TYPE);
$plural = $this->parser->subparse([$this, 'decideForFork']);
$next = $stream->next()->getValue();
if ($next === 'notes') {
$stream->expect(Token::BLOCK_END_TYPE);
$notes = $this->parser->subparse([$this, 'decideForEnd'], true);
} elseif ($next === 'context') {
$stream->expect(Token::BLOCK_END_TYPE);
$context = $this->parser->subparse([$this, 'decideForEnd'], true);
}
} elseif ($next === 'context') {
$stream->expect(Token::BLOCK_END_TYPE);
$context = $this->parser->subparse([$this, 'decideForEnd'], true);
} elseif ($next === 'notes') {
$stream->expect(Token::BLOCK_END_TYPE);
$notes = $this->parser->subparse([$this, 'decideForEnd'], true);
}
}
$stream->expect(Token::BLOCK_END_TYPE);
$this->checkTransString($body, $lineno);
return [$body, $plural, $count, $context, $notes, $domain, $lineno, $this->getTag()];
}
/**
* @return bool
*/
public function decideForFork(Token $token)
{
return $token->test(['plural', 'context', 'notes', 'endtrans']);
}
/**
* @return bool
*/
public function decideForEnd(Token $token)
{
return $token->test('endtrans');
}
/**
* {@inheritdoc}
*/
public function getTag()
{
return 'trans';
}
/**
* @return void
*
* @throws SyntaxError
*/
protected function checkTransString(Node $body, int $lineno)
{
foreach ($body as $i => $node) {
if (
$node instanceof TextNode
||
($node instanceof PrintNode && $node->getNode('expr') instanceof NameExpression)
) {
continue;
}
throw new SyntaxError(
'The text to be translated with "trans" can only contain references to simple variables.',
$lineno
);
}
}
}
twig-i18n-extension-4.1.0/test/ 0000775 0000000 0000000 00000000000 14500127216 0016232 5 ustar 00root root 0000000 0000000 twig-i18n-extension-4.1.0/test/Fixtures/ 0000775 0000000 0000000 00000000000 14500127216 0020043 5 ustar 00root root 0000000 0000000 twig-i18n-extension-4.1.0/test/Fixtures/DomainContext.test 0000664 0000000 0000000 00000000341 14500127216 0023516 0 ustar 00root root 0000000 0000000 --TEST--
A simple trans with context and a domain
--TEMPLATE--
{% trans from "core" %}Some text{% context %}This text is all about bla, foo, bar, blog{% endtrans %}
--DATA--
return []
--CONFIG--
return []
--EXPECT--
Some text twig-i18n-extension-4.1.0/test/Fixtures/DomainPluralContext.test 0000664 0000000 0000000 00000000640 14500127216 0024700 0 ustar 00root root 0000000 0000000 --TEST--
Test a plural example with context and a domain
--TEMPLATE--
{# Plural tag with domain #}
{% set name = 'Jim' %}
{% set apple_count = 1 %}
{% trans from 'core' %}
Hey {{ name }}, I have one apple.
{% plural apple_count %}
Hey {{ name }}, I have {{ count }} apples.
{% context %}Context for the plural block
{% endtrans %}
--DATA--
return []
--CONFIG--
return []
--EXPECT--
Hey Jim, I have one apple. twig-i18n-extension-4.1.0/test/Fixtures/ObjectTrans.test 0000664 0000000 0000000 00000001142 14500127216 0023160 0 ustar 00root root 0000000 0000000 --TEST--
Test a plural example with "exotic" code
--TEMPLATE--
{# Plural tag without domain #}
{% set name = 'Jim' %}
{% set apple_count = 2 %}
{% trans from obj %}
Hey {{ name }}, I have one apple.
{% plural [a][0] %}
Hey {{ name }}, I have {{ count }} apples.
{% context %}
{{ obj|upper }} {{ obj }}
{% endtrans %}
--DATA--
if (! class_exists('CustomObj')) {
class CustomObj {
public $count = 2;
public function __toString()
{
return 'Jim';
}
}
}
return ['obj' => new CustomObj(), 'a' => 2]
--CONFIG--
return []
--EXPECT--
Hey Jim, I have 2 apples. twig-i18n-extension-4.1.0/test/Fixtures/PluralContext.test 0000664 0000000 0000000 00000000607 14500127216 0023553 0 ustar 00root root 0000000 0000000 --TEST--
Test a plural example with context
--TEMPLATE--
{# Plural tag with domain #}
{% set name = 'Jim' %}
{% set apple_count = 1 %}
{% trans %}
Hey {{ name }}, I have one apple.
{% plural apple_count %}
Hey {{ name }}, I have {{ count }} apples.
{% context %}Context for the plural block
{% endtrans %}
--DATA--
return []
--CONFIG--
return []
--EXPECT--
Hey Jim, I have one apple. twig-i18n-extension-4.1.0/test/Fixtures/PluralExample.test 0000664 0000000 0000000 00000000522 14500127216 0023516 0 ustar 00root root 0000000 0000000 --TEST--
Test a plural example
--TEMPLATE--
{# Plural tag without domain #}
{% set name = 'Jim' %}
{% set apple_count = 2 %}
{% trans %}
Hey {{ name }}, I have one apple.
{% plural apple_count %}
Hey {{ name }}, I have {{ count }} apples.
{% endtrans %}
--DATA--
return []
--CONFIG--
return []
--EXPECT--
Hey Jim, I have 2 apples. twig-i18n-extension-4.1.0/test/Fixtures/PluralExampleDomain.test 0000664 0000000 0000000 00000000533 14500127216 0024650 0 ustar 00root root 0000000 0000000 --TEST--
Test a plural example
--TEMPLATE--
{# Plural tag with domain #}
{% set name = 'Jim' %}
{% set apple_count = 2 %}
{% trans from 'core' %}
Hey {{ name }}, I have one apple.
{% plural apple_count %}
Hey {{ name }}, I have {{ count }} apples.
{% endtrans %}
--DATA--
return []
--CONFIG--
return []
--EXPECT--
Hey Jim, I have 2 apples. twig-i18n-extension-4.1.0/test/Fixtures/PluralOneExample.test 0000664 0000000 0000000 00000000523 14500127216 0024161 0 ustar 00root root 0000000 0000000 --TEST--
Test a plural example
--TEMPLATE--
{# Plural tag without domain #}
{% set name = 'Jim' %}
{% set apple_count = 1 %}
{% trans %}
Hey {{ name }}, I have one apple.
{% plural apple_count %}
Hey {{ name }}, I have {{ count }} apples.
{% endtrans %}
--DATA--
return []
--CONFIG--
return []
--EXPECT--
Hey Jim, I have one apple. twig-i18n-extension-4.1.0/test/Fixtures/PluralOneExampleDomain.test 0000664 0000000 0000000 00000000554 14500127216 0025315 0 ustar 00root root 0000000 0000000 --TEST--
Test a plural one example with domain
--TEMPLATE--
{# Plural tag with domain #}
{% set name = 'Jim' %}
{% set apple_count = 1 %}
{% trans from 'core' %}
Hey {{ name }}, I have one apple.
{% plural apple_count %}
Hey {{ name }}, I have {{ count }} apples.
{% endtrans %}
--DATA--
return []
--CONFIG--
return []
--EXPECT--
Hey Jim, I have one apple. twig-i18n-extension-4.1.0/test/Fixtures/PluralWithNotes.test 0000664 0000000 0000000 00000000615 14500127216 0024052 0 ustar 00root root 0000000 0000000 --TEST--
Test a plural example with notes
--TEMPLATE--
{# Plural tag with domain #}
{% set name = 'Jim' %}
{% set apple_count = 1 %}
{% trans from 'core' %}
Hey {{ name }}, I have one apple.
{% plural apple_count %}
Hey {{ name }}, I have {{ count }} apples.
{% notes %}Notes for the plural block
{% endtrans %}
--DATA--
return []
--CONFIG--
return []
--EXPECT--
Hey Jim, I have one apple. twig-i18n-extension-4.1.0/test/Fixtures/PluralWithSprintf.test 0000664 0000000 0000000 00000000426 14500127216 0024407 0 ustar 00root root 0000000 0000000 --TEST--
Test a plural example without variables in the content
--CONFIG--
return []
--TEMPLATE--
{% trans %}%s table{% plural num_tables %}%s tables{% endtrans %}
--DATA--
return [ 'num_tables' => 1]
--EXPECT--
%s table
--DATA--
return [ 'num_tables' => 2]
--EXPECT--
%s tables twig-i18n-extension-4.1.0/test/Fixtures/SimpleContext.test 0000664 0000000 0000000 00000000310 14500127216 0023534 0 ustar 00root root 0000000 0000000 --TEST--
A simple trans with context
--TEMPLATE--
{% trans %}Some text{% context %}This text is all about bla, foo, bar, blog{% endtrans %}
--DATA--
return []
--CONFIG--
return []
--EXPECT--
Some text twig-i18n-extension-4.1.0/test/Fixtures/SimpleDomain.test 0000664 0000000 0000000 00000000277 14500127216 0023333 0 ustar 00root root 0000000 0000000 --TEST--
Test a simple domain example
--TEMPLATE--
{# With specific domain #}
{% trans from "core" %}Castle Quote{% endtrans %}
--DATA--
return []
--CONFIG--
return []
--EXPECT--
Castle Quote twig-i18n-extension-4.1.0/test/Fixtures/SimpleExample.test 0000664 0000000 0000000 00000000223 14500127216 0023506 0 ustar 00root root 0000000 0000000 --TEST--
Test a simple trans tag
--TEMPLATE--
{% trans %}Castle Quote{% endtrans %}
--DATA--
return []
--CONFIG--
return []
--EXPECT--
Castle Quote twig-i18n-extension-4.1.0/test/Fixtures/SimpleXssExample.test 0000664 0000000 0000000 00000000305 14500127216 0024205 0 ustar 00root root 0000000 0000000 --TEST--
Test a simple trans tag against XSS injection
--TEMPLATE--
{% trans %}{% endtrans %}
--DATA--
return []
--CONFIG--
return []
--EXPECT--