Skip to content
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

Merged
merged 8 commits into from
Sep 16, 2014
Merged

Translation custom loaders #4166

merged 8 commits into from
Sep 16, 2014

Conversation

raulfraile
Copy link
Contributor

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.

new class that implements the
:class:`Symfony\\Component\\Translation\\Loader\\LoaderInterface` interface,
which defines a
:method:`Symfony\\Component\\Translation\\Loader\\LoaderInterface::load`
Copy link
Member

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.

@stof
Copy link
Member

stof commented Aug 23, 2014

the new page should be added to the map.rst.inc in the components folder.

And in the DIC tag reference presenting the translation.loader tag, you should add a link to this page


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::
Copy link
Member

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)

@javiereguiluz
Copy link
Member

@raulfraile thanks for completing the documentation of the translator component. I really like it!

@xabbuh
Copy link
Member

xabbuh commented Aug 23, 2014

Does it make sense to have this in the components part? What about moving this to the cookbook?

@raulfraile
Copy link
Contributor Author

@stof @javiereguiluz just pushed some changes based on your comments, but I am not sure about linking it from the translation.loader DIC tag. Should we remove the small introduction about custom loaders from there and just link here?

@xabbuh
Copy link
Member

xabbuh commented Aug 23, 2014

@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:
Copy link
Member

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.

@xabbuh
Copy link
Member

xabbuh commented Aug 23, 2014

@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)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Little type: adiós ;)

@raulfraile
Copy link
Contributor Author

@xabbuh thank you for the suggestions! I fixed all the issues (except the DIC tag docs, waiting what others think).

@xabbuh
Copy link
Member

xabbuh commented Aug 24, 2014

We also have a translation.dumper tag which can also be linked the same way like translation.loader.

@wouterj
Copy link
Member

wouterj commented Aug 24, 2014

+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).
Copy link
Member

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?

Copy link
Member

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)

@wouterj
Copy link
Member

wouterj commented Aug 24, 2014

apart from some minor comments, it looks good.

Thank you for submitting!

@raulfraile
Copy link
Contributor Author

@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?

@xabbuh
Copy link
Member

xabbuh commented Aug 26, 2014

@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 translation.dumper tag too)?

Creating a Custom Loader
------------------------

To define a custom loader that is able to read this kind of files, you must create a
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... these kind of files ...

@weaverryan
Copy link
Member

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!

@weaverryan weaverryan merged commit 69491ae into symfony:2.3 Sep 16, 2014
weaverryan added a commit that referenced this pull request Sep 16, 2014
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
weaverryan added a commit that referenced this pull request Sep 16, 2014
weaverryan added a commit that referenced this pull request Sep 16, 2014
* 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
weaverryan added a commit that referenced this pull request Sep 16, 2014
* 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_
  ...
weaverryan added a commit that referenced this pull request Sep 16, 2014
* 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_
  ...
weaverryan added a commit that referenced this pull request Sep 22, 2014
…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
daFish pushed a commit to daFish/symfony-docs that referenced this pull request Sep 28, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants