[IMP] base: Clean language usability

1. base: Load translation when language is activated

Purpose
------
Settings > Translations > Languages > I find the language I want
and I click on stat button to activate it.
Now I set it up on my user, it still doesn't work > the langage has not been loaded !!!

Specification
-------
When activating a language load the translation (and open the load translation wizard)

2. base: Add shortcut button to load language

Pupose
-------
On the res.partner and res.user form view if you want to change
the language, it's not easy to know where I can activate more
langages.

Specification
-----------
Add a small icon next to the language field to activate more
languages (similar interface than to send an SMS).

3. base: Clean res.lang tree view

1. Set limit to 200 to display all current 82 languages
in one page (current limit is 80/82).

2. Move some fields to debug mode.

3. Add a button to directly load a language.

4. base: Remove Load a Translation menu

Activating a language automatically load the translation,
hence the menu is no longer necessary.

5. base: Don't show language if only one active

If only one language is active, don't show in the contact
form view (`res.partner`) the language field. Changing the language is
not possible since there is only one language.
Hence the field is useless and therefore hidden.

TaskID: 2026150

closes odoo/odoo#34661

Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
This commit is contained in:
Robot Odoo
2019-07-17 09:10:03 +02:00
committed by GitHub
7 changed files with 64 additions and 17 deletions
+1 -1
View File
@@ -37,7 +37,7 @@ translation tool like POEdit_ or by simply copying the template to a new file
called :file:`{language}.po`. Translation files should be put in
:file:`{yourmodule}/i18n/`, next to :file:`{yourmodule}.pot`, and will be
automatically loaded by Odoo when the corresponding language is installed (via
:menuselection:`Settings --> Translations --> Load a Translation`)
:menuselection:`Settings --> Translations --> Languages`)
.. note:: translations for all loaded languages are also installed or updated
when installing or updating a module
+14
View File
@@ -212,6 +212,20 @@ class Lang(models.Model):
langs = self.with_context(active_test=True).search([])
return sorted([(lang.code, lang.name) for lang in langs], key=itemgetter(1))
def toggle_active(self):
super().toggle_active()
# Automatically load translation
if len(self) == 1 and self.active:
return {
'name': "Load a Translation",
'type': 'ir.actions.act_window',
'res_model': 'base.language.install',
'context': {'default_lang': self.code},
'view_mode': 'form',
'target': 'new',
'views': [[False, 'form']],
}
@api.model_create_multi
def create(self, vals_list):
self.clear_caches()
+6
View File
@@ -154,6 +154,7 @@ class Partner(models.Model):
ref = fields.Char(string='Reference', index=True)
lang = fields.Selection(_lang_get, string='Language', default=lambda self: self.env.lang,
help="All the emails and documents sent to this contact will be translated in this language.")
active_lang_count = fields.Integer(compute='_compute_active_lang_count')
tz = fields.Selection(_tz_get, string='Timezone', default=lambda self: self._context.get('tz'),
help="When printing documents and exporting/importing data, time values are computed according to this timezone.\n"
"If the timezone is not set, UTC (Coordinated Universal Time) is used.\n"
@@ -253,6 +254,11 @@ class Partner(models.Model):
for partner in self:
partner.display_name = names.get(partner.id)
def _compute_active_lang_count(self):
lang_count = len(self.env['res.lang'].get_installed())
for partner in self:
partner.active_lang_count = lang_count
@api.depends('tz')
def _compute_tz_offset(self):
for partner in self:
+6 -7
View File
@@ -5,16 +5,15 @@
<field name="name">res.lang.tree</field>
<field name="model">res.lang</field>
<field name="arch" type="xml">
<tree string="Languages">
<tree string="Languages" limit="200">
<field name="name"/>
<field name="code"/>
<field name="iso_code"/>
<field name="direction"/>
<field name="translatable"/>
<field name="code" groups="base.group_no_one"/>
<field name="iso_code" groups="base.group_no_one"/>
<field name="direction" groups="base.group_no_one"/>
<field name="translatable" groups="base.group_no_one"/>
<field name="active"/>
<button name="%(base.action_view_base_language_install)d"
string="Update Terms" type="action" icon="fa-refresh" help="Update Language Terms"
attrs="{'invisible': [('active', '=', False)]}"/>
string="Download and Update Translation" type="action" icon="fa-refresh" help="Download and Update Translation"/>
</tree>
</field>
</record>
+13 -1
View File
@@ -262,7 +262,19 @@
<field name="website" widget="url" placeholder="e.g. www.odoo.com"/>
<field name="title" options='{"no_open": True}'
attrs="{'invisible': [('is_company', '=', True)]}"/>
<field name="lang"/>
<field name="active_lang_count" invisible="1"/>
<label for="lang" attrs="{'invisible': [('active_lang_count', '&lt;=', 1)]}"/>
<div class="o_row" attrs="{'invisible': [('active_lang_count', '&lt;=', 1)]}">
<field name="lang" placeholder="System (English)"/>
<button
type="action"
name="%(base.res_lang_act_window)d"
class="btn-sm btn-link mb4 fa fa-globe"
aria-label="More languages"
groups="base.group_system"
title="More languages"
/>
</div>
<field name="category_id" widget="many2many_tags" options="{'color_field': 'color', 'no_create_edit': True}" placeholder="Tags..."/>
</group>
</group>
+24 -2
View File
@@ -213,8 +213,19 @@
<page string="Preferences">
<group>
<group string="Localization" name="preferences">
<field name="lang"/>
<label for="lang" placeholder="System (English)"/>
<field name="active" invisible="1"/>
<div class="o_row">
<field name="lang"/>
<button
type="action"
name="%(base.res_lang_act_window)d"
class="btn-sm btn-link mb4 fa fa-globe"
aria-label="More languages"
groups="base.group_system"
title="More languages"
/>
</div>
<field name="tz" widget="timezone_mismatch" options="{'tz_offset_field': 'tz_offset'}" />
<field name="tz_offset" invisible="1"/>
</group>
@@ -344,7 +355,18 @@
groups="base.group_multi_company"/>
</group>
<group>
<field name="lang" readonly="0" placeholder="System (English)"/>
<label for="lang"/>
<div class="o_row">
<field name="lang" placeholder="System (English)"/>
<button
type="action"
name="%(base.res_lang_act_window)d"
class="btn-sm btn-link mb4 fa fa-globe"
aria-label="More languages"
groups="base.group_system"
title="More languages"
/>
</div>
<field name="tz" widget="timezone_mismatch" options="{'tz_offset_field': 'tz_offset'}" readonly="0"/>
<field name="tz_offset" invisible="1"/>
</group>
@@ -34,12 +34,6 @@ You must change the preferences of the user to view the changes.</span>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
<menuitem
name="Load a Translation"
action="action_view_base_language_install"
id="menu_view_base_language_install"
parent="menu_translation" sequence="2"/>
</data>
</odoo>