@@ -65,6 +65,10 @@ may also be tags in other bundles you use that aren't listed here.
65
65
+-----------------------------------+---------------------------------------------------------------------------+
66
66
| `translation.loader `_ | Register a custom service that loads translations |
67
67
+-----------------------------------+---------------------------------------------------------------------------+
68
+ | `translation.extractor `_ | Register a custom service that extracts translation messages from a file |
69
+ +-----------------------------------+---------------------------------------------------------------------------+
70
+ | `translation.dumper `_ | Register a custom service that dumps translation messages |
71
+ +-----------------------------------+---------------------------------------------------------------------------+
68
72
| `twig.extension `_ | Register a custom Twig Extension |
69
73
+-----------------------------------+---------------------------------------------------------------------------+
70
74
| `validator.constraint_validator `_ | Create your own custom validation constraint |
@@ -916,6 +920,130 @@ file, but it might either be blank or contain a little bit of information
916
920
about loading those resources from the database. The file is key to trigger
917
921
the ``load`` method on your custom loader.
918
922
923
+ translation.extractor
924
+ ---------------------
925
+
926
+ **Purpose**: To register a custom service that extracts messages from a file
927
+
928
+ .. versionadded:: 2.1
929
+ The ability to add message extractors is new in 2.1
930
+
931
+ When executing the ``translation:update`` command, it uses extractors to
932
+ extract translation messages from a file. By default, the Symfony2 framework
933
+ has a :class:`Symfony\\Bridge\\TwigBridge\\Translation\\TwigExtractor` and a
934
+ :class:`Symfony\\Bundle\\FrameworkBundle\\Translation\\PhpExtractor`.
935
+
936
+ You can create your own extractor by creating a class which implements
937
+ :class:`Symfony\\Component\\Translation\\Extractor\\ExtractorInterface` and
938
+ tagging the service with ``translation.extractor``. The tag has one required
939
+ option: ``alias``, this defines the name of the extractor.
940
+
941
+ // src/Acme/DemoBundle/Translation/FooExtractor.php
942
+ namespace Acme\DemoBundle\Translation;
943
+
944
+ use Symfony\Component\Translation\Extractor\ExtractorInterface;
945
+ use Symfony\Component\Translation\MessageCatalogue;
946
+
947
+ class FooExtractor implements ExtractorInterface
948
+ {
949
+ protected $prefix;
950
+
951
+ /**
952
+ * Extracts translation messages from a template directory to the catalogue.
953
+ */
954
+ public function extract($directory, MessageCatalogue $catalogue)
955
+ {
956
+ // ...
957
+ }
958
+
959
+ /**
960
+ * Sets the prefix that should be used for new found messages.
961
+ */
962
+ public function setPrefix($prefix)
963
+ {
964
+ $this->prefix = $prefix;
965
+ }
966
+ }
967
+
968
+ .. configuration-block::
969
+
970
+ .. code-block:: yaml
971
+
972
+ services:
973
+ acme_demo.translation.extractor.foo:
974
+ class: Acme\DemoBundle\Translation\FooExtractor
975
+ tags:
976
+ - { name: translation.extractor, alias: foo }
977
+
978
+ .. code-block:: xml
979
+
980
+ <service id=" acme_demo.translation.extractor.foo"
981
+ class=" Acme\DemoBundle\Translation\FooExtractor" >
982
+ <tag name=" translation.extractor" alias=" foo" />
983
+ </service>
984
+
985
+ .. code-block:: php
986
+
987
+ $container->register(
988
+ 'acme_demo.translation.extractor.foo',
989
+ 'Acme\DemoBundle\Translation\FooExtractor'
990
+ )
991
+ ->addTag('translation.extractor', array('alias' => 'foo'));
992
+
993
+ translation.dumper
994
+ ------------------
995
+
996
+ **Purpose**: To register a custom service that dumps messages to a file
997
+
998
+ .. versionadded:: 2.1
999
+ The ability to add message dumpers is new to 2.1
1000
+
1001
+ After an `Extractor <translation.extractor>`_ has extracted all messages from
1002
+ the templates, the dumpers are executed to dump the messages to a translation
1003
+ file in a specific format.
1004
+
1005
+ Symfony2 comes already with many dumpers:
1006
+
1007
+ * :class:`Symfony\\Component\\Translation\\Dumper\\CsvFileDumper`
1008
+ * :class:`Symfony\\Component\\Translation\\Dumper\\IcuResFileDumper`
1009
+ * :class:`Symfony\\Component\\Translation\\Dumper\\IniFileDumper`
1010
+ * :class:`Symfony\\Component\\Translation\\Dumper\\MoFileDumper`
1011
+ * :class:`Symfony\\Component\\Translation\\Dumper\\PoFileDumper`
1012
+ * :class:`Symfony\\Component\\Translation\\Dumper\\QtFileDumper`
1013
+ * :class:`Symfony\\Component\\Translation\\Dumper\\XliffFileDumper`
1014
+ * :class:`Symfony\\Component\\Translation\\Dumper\\YamlFileDumper`
1015
+
1016
+ You can create your own dumper by extending
1017
+ :class:`Symfony\\Component\\Translation\\DumperFileDumper` or implementing
1018
+ :class:`Symfony\\Component\\Translation\\Dumper\\DumperInterface` and tagging
1019
+ the service with ``translation.dumper``. The tag has one option: ``alias``
1020
+ This is the name that's used to determine which dumper should be used.
1021
+
1022
+ .. configuration-block::
1023
+
1024
+ .. code-block:: yaml
1025
+
1026
+ services:
1027
+ acme_demo.translation.dumper.json:
1028
+ class: Acme\DemoBundle\Translation\JsonFileDumper
1029
+ tags:
1030
+ - { name: translation.dumper, alias: json }
1031
+
1032
+ .. code-block:: xml
1033
+
1034
+ <service id=" acme_demo.translation.dumper.json"
1035
+ class=" Acme\DemoBundle\Translation\JsonFileDumper" >
1036
+ <tag name=" translation.dumper" alias=" json" />
1037
+ </service>
1038
+
1039
+ .. code-block:: php
1040
+
1041
+ $container->register(
1042
+ 'acme_demo.translation.dumper.json',
1043
+ 'Acme\DemoBundle\Translation\JsonFileDumper'
1044
+ )
1045
+ ->addTag('translation.dumper', array('alias' => 'json'));
1046
+
919
1047
.. _reference-dic-tags-twig-extension:
920
1048
921
1049
twig.extension
0 commit comments