Skip to content
This repository was archived by the owner on Oct 22, 2021. It is now read-only.

Commit d5d3ec6

Browse files
committed
Updated
1 parent ee2d6d1 commit d5d3ec6

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

README.md

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Twig Translation Extension
22

3-
Twig Translation Extension for the [Poedit](https://poedit.net/) translations editor.
3+
A Twig Translation Extension.
44

55
[![Latest Version on Packagist](https://img.shields.io/github/release/odan/twig-translation.svg)](https://github.com/odan/twig-translation/releases)
66
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE.md)
@@ -23,20 +23,12 @@ composer require odan/twig-translation
2323
```php
2424
$loader = new \Twig\Loader\FilesystemLoader('/path/to/templates');
2525
$twig = new \Twig\Environment($loader, array(
26-
'cache' => '/path/to/compilation_cache',
26+
'cache' => '/path/to/twig-cache',
2727
));
2828

2929
$twig->addExtension(new \Odan\Twig\TwigTranslationExtension());
3030
```
3131

32-
### Slim Framework
33-
34-
In your `dependencies.php` or wherever you add your service factories:
35-
36-
```php
37-
$twig->addExtension(new \Odan\Twig\TwigTranslationExtension());
38-
```
39-
4032
## Register a callback function
4133

4234
Create a global callback function with the name `__`.
@@ -60,18 +52,21 @@ use Symfony\Component\Translation\Translator;
6052
*/
6153
function __($message)
6254
{
63-
/* @var Translator $translator */
55+
/** @var Translator $translator */
6456
static $translator = null;
57+
6558
if ($message instanceof Translator) {
6659
$translator = $message;
6760
return '';
6861
}
6962

7063
$translated = $translator->trans($message);
7164
$context = array_slice(func_get_args(), 1);
65+
7266
if (!empty($context)) {
7367
$translated = vsprintf($translated, $context);
7468
}
69+
7570
return $translated;
7671
}
7772
```
@@ -161,7 +156,7 @@ Create a complex plural translation:
161156
* Add a new keyword with the name `__` (2 underscores)
162157
* Click the `OK` button and `Update` the calalogue.
163158

164-
### Parsing the Twig files
159+
### Parsing Twig files
165160

166161
You need to iterate and compile all your Twig templates.
167162
The compilation step generates the PHP cache files that can be parsed from Poedit.
@@ -180,12 +175,12 @@ $loader = new \Twig\Loader\FilesystemLoader(__DIR__ . '/../templates');
180175
// Instantiate Twig
181176
$twig = new \Twig\Environment($loader);
182177

183-
// Compile all Twig templates into cache directory
178+
// Compile all Twig templates into the cache directory
184179
$cachePath = __DIR__ . '/../tmp/twig-cache';
185180
$compiler = new \Odan\Twig\TwigCompiler($twig, $cachePath);
186181
$compiler->compile();
187182

188183
echo "Done\n";
189184
```
190185

191-
To run this script just run: `php bin/parse-twig.php`
186+
To run this script just enter: `php bin/parse-twig.php`

0 commit comments

Comments
 (0)