Skip to content

Commit

Permalink
Further readme updates
Browse files Browse the repository at this point in the history
  • Loading branch information
cooperaj committed Aug 26, 2020
1 parent 6603c38 commit 5e3c811
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Better Twig i18n
Better Twig Gettext i18n
======

Allows the use of a POT/PO/MO (gettext) set of language definitions with Twig, using an identical syntax to the current
Expand All @@ -7,7 +7,39 @@ official [Twig translation extension](https://github.com/symfony/twig-bridge).
It supports full extraction of Twig templates into language catalogues from the
[gettext/gettext](https://github.com/php-gettext/Gettext) library, which you can use to write out POT files if desired.

## Usage
### Supports
* Translation tags (`{% trans %} ... {% endtrans %}`) and filters (`| trans`)
* Variable interpolation `{% trans with { '%var%': var } %}%var%{% endtrans %}`
* Pluralisation `{% trans count 3 %}%count% item|%count% items{% endtrans %}`
* Message specific domains `{% trans from 'errors' %} ... {% endtrans %}`
* Message contexts `{% trans %} ... {% context %}Some context{% endtrans %}`
* Notes/comments for the translation `{% trans %} ... {% notes %}A translation note{% endtrans %}`


* or some horrid combination of all of them
```twig
{% trans count 5 with { '%name%': 'Adam' } from 'errors' %}
%name% has %count% apple|%name% has %count% apples
{% notes %}A translation note
{% context %}Some context to the translation
{% endtrans %}
```

The extraction of which would result in a POT file that looked like:
```
#. A translation note
msgctxt "Some context to the translation"
msgid "%name% has %count% apple"
msgid_plural "%name% has %count% apples"
msgstr[0] ""
```

And the (default, i.e. no language supplied) output of which would look like
```
Adam has 5 apples
```

## Usage

> See [extract.php](example/extract.php) and [index.php](example/index.php) for example usage.

0 comments on commit 5e3c811

Please sign in to comment.