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

[IMP] Add warning for direct '_' import in translations #113

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lef-adhoc
Copy link
Contributor

More info here: odoo/odoo#174844

@pedrobaeza
Copy link
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.

@lef-adhoc
Copy link
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"

Choose a reason for hiding this comment

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

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"

Copy link

@trisdoan trisdoan left a comment

Choose a reason for hiding this comment

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants