-
Notifications
You must be signed in to change notification settings - Fork 9.4k
[IMP] core: Environment._ for translations #10421
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
Closed
Closed
Conversation
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
3aa31cc
to
b441a35
Compare
AntoineVDV
approved these changes
Jul 30, 2024
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.
@robodoo delegate+
2c0c820
to
9128522
Compare
7fb7524
to
9d728e7
Compare
339ee68
to
9f1194b
Compare
rco-odoo
reviewed
Sep 12, 2024
0ae18da
to
3c09a56
Compare
@robodoo r+ |
I'm sorry, @rco-odoo. I'm afraid I can't do that. |
@robodoo r+ |
@kmagusiak linked pull request(s) odoo/odoo#174844 not ready. Linked PRs are not staged until all of them are ready. |
3c09a56
to
5c968de
Compare
5c968de
to
c3faae2
Compare
@robodoo r+ |
robodoo
pushed a commit
that referenced
this pull request
Sep 15, 2024
odoo/odoo#174844 closes #10421 Related: odoo/enterprise#67528 Signed-off-by: Krzysztof Magusiak (krma) <krma@odoo.com>
robodoo
pushed a commit
to odoo/odoo
that referenced
this pull request
Sep 15, 2024
Python translations need to know the language and the module to find the translated term. Today's `_` function must resolve both of these values from the current stack by using some heuristics. These heuristics don't always work properly: to find the language we look in the caller's scope to find it in the context or to find the environment from which we can read `lang`. For the module, if the function is used outside of an addon, we default to 'base'. Note that `odoo.tools._` works only *directly* inside Model methods. We add a function `Environment._` for translations. That function uses its `lang` property for the language without resorting to inspecting the call stack. You can also pass the module, but we can still resolve it dynamically. The following list comprehension will work correctly: `[self.env._("something %s", x) for x in xs]` For lazy translations, we create a new `LazyTranslate` factory that you can use as `_lt = LazyTranslate(__name__)` in any addon. This will resolve the addon name once per file from the name of the package without going through `inspect`. You can then use `Environment._` to get the translation or `str()` to resolve the lanugage dynamically. Lazy translations should be used only for globally defined constants that will be translated using `env._(some_lazy_text_instance)`. task-4034999 closes #174844 Related: odoo/enterprise#67528 Related: odoo/documentation#10421 Signed-off-by: Krzysztof Magusiak (krma) <krma@odoo.com>
robodoo
pushed a commit
that referenced
this pull request
Sep 15, 2024
odoo/odoo#174844 closes #10421 Related: odoo/enterprise#67528 Signed-off-by: Krzysztof Magusiak (krma) <krma@odoo.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
odoo/odoo#174844