[IMP] Add warning for direct '_' import in translations#113
Open
lef-adhoc wants to merge 1 commit intoOCA:masterfrom
Open
[IMP] Add warning for direct '_' import in translations#113lef-adhoc wants to merge 1 commit intoOCA:masterfrom
lef-adhoc wants to merge 1 commit intoOCA:masterfrom
Conversation
Member
|
It's not true that it should be avoided. It's just that the other expression may be (not always) more performant, so I would rephrase the warning. |
Contributor
Author
|
@pedrobaeza Got it! Can you tell me how would you reformulate it to add it? |
| @@ -0,0 +1,2 @@ | |||
| .py: | |||
| from odoo import .*_: "[18] The '_' symbol should no longer be imported directly for translations. Remove '_' from the 'from odoo import' statement, and replace any instances of '_('text')' with 'self.env._('text')'. This change is required for better context handling. More details: https://github.com/odoo/odoo/pull/174844" | |||
There was a problem hiding this comment.
Suggested change
| from odoo import .*_: "[18] The '_' symbol should no longer be imported directly for translations. Remove '_' from the 'from odoo import' statement, and replace any instances of '_('text')' with 'self.env._('text')'. This change is required for better context handling. More details: https://github.com/odoo/odoo/pull/174844" | |
| from odoo(\.tools(\.translate)?)? import .*_: "[18] When possible, it is better to rely on `Env._`: replace '_('text')' by 'self.env._('text')' and remove '_' from the imports. More details: https://github.com/odoo/odoo/pull/174844" |
ebc864d to
ac9151b
Compare
nilshamerlinck
approved these changes
Nov 11, 2024
trisdoan
suggested changes
Dec 9, 2024
trisdoan
left a comment
There was a problem hiding this comment.
Hi, there is no translation in my py file but it still produces the Warning
The file has these lines
from odoo import api, fields, models
from odoo.tools import float_compare, float_round
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
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.
More info here: odoo/odoo#174844