Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
4321 Lượt xem

Hello, I'm not clear about this code,

raise (_('Error!'), _('Not implemented.'))

Can anybody explain what it is to use "_" in the above code ?

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

This is a built-in tool from Odoo and it makes it possible to translate text in multiple languages.
Imagine that you want to show a warning to a user when something is wrong. Then you would do something like this:

raise ValidationError('At least one language must be active.')

This will work fine but what if you have one user in your system that is English and one that is Dutch? Well, both would get it in English in this case. When you use the "_" import from Odoo you'll be able to make the text translatable. Your code would look like this then:

raise ValidationError(_('At least one language must be active.'))

By using _() in the code it will be parsed by Odoo. If you then export your translations this string will be in the text values too and you'll be able to translate it in any language that you'd like.


See this: https://www.odoo.com/forum/help-1/question/what-is-the-meaning-of-the-underscore-in-the-python-odoo-import-statement-129061

Thanks

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 2 23
1907
0
thg 11 16
4589
1
thg 3 20
4624
3
thg 11 18
3824
0
thg 2 18
12129