Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork5.3k
Translatable objects#14240
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Translatable objects#14240
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
29 changes: 28 additions & 1 deletionreference/twig_reference.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletionstranslation.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -292,6 +292,41 @@ To manage these situations, Symfony follows the `ICU MessageFormat`_ syntax by | ||
| using PHP's :phpclass:`MessageFormatter` class. Read more about this in | ||
| :doc:`/translation/message_format`. | ||
| Translatable Objects | ||
javiereguiluz marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| -------------------- | ||
| .. versionadded:: 5.2 | ||
| Translatable objects were introduced in Symfony 5.2. | ||
| Sometimes you may want to create a message, but at the time of creation aren't | ||
| sure how it would be translated. For example, it could be translated multiple | ||
| times if intended to be displayed to multiple users. | ||
javiereguiluz marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| Using translatable objects also allows preparing translations without having a | ||
| dependency on an entrypoint (such as a router) where the context for performing | ||
| the translation is provided. For example, entities could prepare translatable | ||
| strings (such as labels) without the need for a translator. | ||
| Instead of translating a string at the time of creation, a ``Translatable`` | ||
| object can be created that can then be translated when used. Later this message | ||
| can be translated with a translator in either PHP or in Twig. | ||
| PHP:: | ||
| $message = new Translatable('Symfony is great!'); | ||
| $message = t('Symfony is great!'); | ||
| Translatable::trans($translator, $message); | ||
| Twig: | ||
| .. code-block:: html+twig | ||
| {% set message = t('Symfony is great!') %} | ||
| <h1>{{ message|trans }}</h1> | ||
| .. _translation-in-templates: | ||
| Translations in Templates | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.