-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Translation custom loaders #4166
Translation custom loaders #4166
Conversation
new class that implements the | ||
:class:`Symfony\\Component\\Translation\\Loader\\LoaderInterface` interface, | ||
which defines a | ||
:method:`Symfony\\Component\\Translation\\Loader\\LoaderInterface::load` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think listing the methods of the interface is needed in this paragraph. Implementing an inteface involves implementing all its methods.
the new page should be added to the map.rst.inc in the components folder. And in the DIC tag reference presenting the |
|
||
Let's imagine you have a custom format where translation messages are defined | ||
using one line for each translation and parenthesis to wrap the key and the | ||
message. A translation file would look like this:: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using ::
at the end of this paragraph would make the code listing be interpreted as PHP code. Maybe its better to create a proper code listing:
[...]
message. A translation file would look like this:
.. code-block:: text
(welcome)(Bienvenido)
(goodbye)(Adios)
(hello)(Hola)
@raulfraile thanks for completing the documentation of the translator component. I really like it! |
Does it make sense to have this in the components part? What about moving this to the cookbook? |
@stof @javiereguiluz just pushed some changes based on your comments, but I am not sure about linking it from the |
@raulfraile I would remove everything after the first sentence there and add a link to your new article instead. So, it would then look something like this: translation.loader
------------------
**Purpose**: To register a custom service that loads translations
By default, translations are loaded from the filesystem in a variety of different
formats (YAML, XLIFF, PHP, etc).
.. seealso::
Learn how to :doc:`load custom formats </components/translation/custom_format>`
in the components section. But let's wait what the others think. |
Loader too. The default loaders are: | ||
The component comes with some default loaders and you can | ||
:doc:`create your own Loader too </components/translation/custom_formats>`. The | ||
default loaders are: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not mention the custom loaders here, but add a sentence after the list of default loaders instead.
@raulfraile I didn't meant to shock you. The things I commented on are mainly minor issues. I basically really like the work you did. 👍 |
.. code-block:: text | ||
|
||
(welcome)(Bienvenido) | ||
(goodbye)(Adios) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Little type: adiós ;)
@xabbuh thank you for the suggestions! I fixed all the issues (except the DIC tag docs, waiting what others think). |
We also have a |
+1 for keeping this in the component section: It is related to the component, not the framework. |
|
||
Sometimes, you need to deal with custom formats for translation files. The | ||
Translation component is flexible enough to support this. Just create a | ||
loader (to load translations) and, optionally, a dumper (to dump translations). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and what about an extractor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
totally unrelated. The extractor does not care about the format of your translation files. It relies on the loader and dumper for it (it would be great to add a cookbook about adding extractors though)
apart from some minor comments, it looks good. Thank you for submitting! |
@wouterj I pushed some changes based on your comments, except for the extractor, as I would need to do some additional research. Can we leave it for another PR? |
@raulfraile As @stof mentioned here, the extractor is not really related to this article and I agree with him in that. @wouterj What do you think about the proposed change in the reference (I think something like that should be added for the |
Creating a Custom Loader | ||
------------------------ | ||
|
||
To define a custom loader that is able to read this kind of files, you must create a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... these kind of files ...
Hey Raul! I've decided to merge this because it's very nice! There is one little type that I just commented on and will fix myself. @xabbuh, if you'd like to create the note on the DI tags page, that would be great - I agree that it's a good idea. Thanks everyone! |
This PR was merged into the 2.3 branch. Discussion ---------- Translation custom loaders | Q | A | ------------- | --- | Doc fix? | no | New docs? | yes | Applies to | all | Fixed tickets | #4156 This PR adds a documentation section for creating custom loaders and dumpers to support other formats. Commits ------- 69491ae Improved custom formats article based on comments c0f3b0a Fixed wrong indentation 629a008 Extra improvements based on comments bfd78b3 Improvements based on comments 105a168 Cleanups e2fd5fa Small fixes dee7fb2 Link from introduction section 8b6c584 Added custom format page to translation component
* 2.3: (29 commits) [#4166] Fixing small typo Fixed all the errors found by Ryan Removed two highlight formats which are "experimental" and not used by end users Reworded the explanation about the limitation of enablin PHP templates Improved the explanation thanks to @stof comments More and more fixes and improvements Added another bunch of fixes suggested by reviewers Added lots of fixes suggested by reviewers Added a note about not using relative internal links in the doc Switched another relative link into an absolute reference lways use absolute links instead of relative for internal doc links Added missing link Revamped the documentation about "Contributing Docs" do not reference services in parameters Fix reference label Add label book-security-roles Add formatting, links, and clarity Added a note about the side effects of enabling both PHP and Twig Caution that roles should start with ROLE_ Added note about exporting SYMFONY_ENV ... Conflicts: components/translation/introduction.rst
* 2.4: (30 commits) [#4166] Fixing small typo caution on `null` values in Expression constraint Fixed all the errors found by Ryan Removed two highlight formats which are "experimental" and not used by end users Reworded the explanation about the limitation of enablin PHP templates Improved the explanation thanks to @stof comments More and more fixes and improvements Added another bunch of fixes suggested by reviewers Added lots of fixes suggested by reviewers Added a note about not using relative internal links in the doc Switched another relative link into an absolute reference lways use absolute links instead of relative for internal doc links Added missing link Revamped the documentation about "Contributing Docs" do not reference services in parameters Fix reference label Add label book-security-roles Add formatting, links, and clarity Added a note about the side effects of enabling both PHP and Twig Caution that roles should start with ROLE_ ...
* 2.5: (30 commits) [#4166] Fixing small typo caution on `null` values in Expression constraint Fixed all the errors found by Ryan Removed two highlight formats which are "experimental" and not used by end users Reworded the explanation about the limitation of enablin PHP templates Improved the explanation thanks to @stof comments More and more fixes and improvements Added another bunch of fixes suggested by reviewers Added lots of fixes suggested by reviewers Added a note about not using relative internal links in the doc Switched another relative link into an absolute reference lways use absolute links instead of relative for internal doc links Added missing link Revamped the documentation about "Contributing Docs" do not reference services in parameters Fix reference label Add label book-security-roles Add formatting, links, and clarity Added a note about the side effects of enabling both PHP and Twig Caution that roles should start with ROLE_ ...
…on (xabbuh) This PR was merged into the 2.3 branch. Discussion ---------- [Reference] link translation DIC tags to components section | Q | A | ------------- | --- | Doc fix? | yes | New docs? | no | Applies to | all | Fixed tickets | The `translation.loader` and `translation.dumper` DIC tags link to the respective sections in the Translation component documentation (in addition to the changes done in #4166). Commits ------- 9790975 link translation DIC tags to components section
This PR adds a documentation section for creating custom loaders and dumpers to support other formats.