Skip to content

[IMP] t9n: human-readable paths for actions #2969

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

Open
wants to merge 3 commits into
base: master-translation-module
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions addons/t9n/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
19 changes: 19 additions & 0 deletions addons/t9n/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "Translations",
"version": "1.0",
"category": "TODO: find the appropriate category",
"description": "TODO: write a description of the module",
"depends": ["base", "web"],
"application": True,
"assets": {
"web.assets_backend": [
"t9n/static/src/**/*",
],
},
"data": [
"security/ir.model.access.csv",
"views/t9n_project_views.xml",
"views/t9n_menu_views.xml",
],
"license": "LGPL-3",
}
5 changes: 5 additions & 0 deletions addons/t9n/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from . import language
from . import message
from . import project
from . import resource
from . import translation
8 changes: 8 additions & 0 deletions addons/t9n/models/language.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from odoo import fields, models


class Language(models.Model):
_name = "t9n.language"
_description = "Language"

name = fields.Char("Language", required=True)
24 changes: 24 additions & 0 deletions addons/t9n/models/message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from odoo import fields, models


class Message(models.Model):
"""Models a localizable message, i.e. any textual content to be translated.
Messages are retrieved from a Resource.
A Message localized to a specific Language becomes a Translation.
"""

_name = "t9n.message"
_description = "Localizable message"

body = fields.Text(
help="The actual, textual content to be translated.",
)
resource_id = fields.Many2one(
comodel_name="t9n.resource",
help="The resource (typically a file) from which the entry is coming from.",
)
translation_ids = fields.One2many(
comodel_name="t9n.translation",
inverse_name="source_id",
string="Translations",
)
36 changes: 36 additions & 0 deletions addons/t9n/models/project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from odoo import fields, models, api, _
from odoo.exceptions import ValidationError


class Project(models.Model):
"""A project is a collection of Resources to be localized into a given set
of Languages.
"""

_name = "t9n.project"
_description = "Translation project"

name = fields.Char("Project", required=True)
src_lang_id = fields.Many2one(
comodel_name="t9n.language",
string="Source Language",
help="The original language of the messages you want to translate.",
)
resource_ids = fields.One2many(
comodel_name="t9n.resource",
inverse_name="project_id",
string="Resources",
)
target_lang_ids = fields.Many2many(
comodel_name="t9n.language",
string="Languages",
help="The list of languages into which the project can be translated.",
)

@api.constrains("src_lang_id", "target_lang_ids")
def _check_source_and_target_languages(self):
for record in self:
if record.src_lang_id in record.target_lang_ids:
raise ValidationError(
_("Target languages must be different from source language.")
)
16 changes: 16 additions & 0 deletions addons/t9n/models/resource.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from odoo import fields, models


class Resource(models.Model):
_name = "t9n.resource"
_description = "Resource file"

name = fields.Char("Resource")
message_ids = fields.One2many(
comodel_name="t9n.message",
inverse_name="resource_id",
string="Entries to translate",
)
project_id = fields.Many2one(
comodel_name="t9n.project",
)
20 changes: 20 additions & 0 deletions addons/t9n/models/translation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from odoo import fields, models


class Translation(models.Model):
_name = "t9n.translation"
_description = "Message translated into a language"

body = fields.Text(
help="The actual content of the translation.",
)
source_id = fields.Many2one(
comodel_name="t9n.message",
string="Source message",
help="The original text, the source of the translation.",
)
lang_id = fields.Many2one(
comodel_name="t9n.language",
string="Language",
help="The language to which the translation translates the original message.",
)
6 changes: 6 additions & 0 deletions addons/t9n/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_t9n_project_system,t9n.project.system,t9n.model_t9n_project,base.group_system,1,1,1,1
access_t9n_language_system,t9n.language.system,t9n.model_t9n_language,base.group_system,1,1,1,1
access_t9n_message_system,t9n.message.system,t9n.model_t9n_message,base.group_system,1,1,1,1
access_t9n_resource_system,t9n.resource.system,t9n.model_t9n_resource,base.group_system,1,1,1,1
access_t9n_translation_system,t9n.translation.system,t9n.model_t9n_translation,base.group_system,1,1,1,1
10 changes: 10 additions & 0 deletions addons/t9n/static/src/core/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Component } from "@odoo/owl";

/**
* The "root", the "homepage" of the translation application.
*/
export class App extends Component {
static components = {};
static props = {};
static template = "t9n.App";
}
8 changes: 8 additions & 0 deletions addons/t9n/static/src/core/app.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<templates xml:space="preserve">

<t t-name="t9n.App">
Hello World!
</t>

</templates>
18 changes: 18 additions & 0 deletions addons/t9n/static/src/web/open_app_action.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Component, xml } from "@odoo/owl";

import { App } from "@t9n/core/app";

import { registry } from "@web/core/registry";
import { standardActionServiceProps } from "@web/webclient/actions/action_service";

/**
* Wraps the application root, allowing us to open the application as a result
* of a call to the "t9n.open_app" client action.
*/
export class OpenApp extends Component {
static components = { App };
static props = { ...standardActionServiceProps };
static template = xml`<App/>`;
}

registry.category("actions").add("t9n.open_app", OpenApp);
11 changes: 11 additions & 0 deletions addons/t9n/views/t9n_menu_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<odoo>
<record id="t9n.open_app" model="ir.actions.client">
<field name="name">Translate</field>
<field name="path">translate</field>
<field name="tag">t9n.open_app</field>
<field name="target">main</field>
</record>
<menuitem id="t9n.menu_root" name="Translations" action="t9n.open_app"/>
<menuitem id="t9n.project_menu" name="Projects" action="t9n.project_action" parent="t9n.menu_root"/>
</odoo>
35 changes: 35 additions & 0 deletions addons/t9n/views/t9n_project_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0"?>
<odoo>
<record id="t9n.project_action" model="ir.actions.act_window">
<field name="name">Projects</field>
<field name="res_model">t9n.project</field>
<field name="view_mode">tree,form</field>
</record>

<record id="t9n.project_view_form" model="ir.ui.view">
<field name="name">t9n.project.form</field>
<field name="model">t9n.project</field>
<field name="arch" type="xml">
<form>
<sheet>
<h1>
<field name="name"/>
</h1>
<notebook>
<page string="Resources">
<field name="resource_ids"/>
</page>
<page string="Description">
<group>
<group>
<field name="src_lang_id" domain="[('id', 'not in', target_lang_ids)]"/>
<field name="target_lang_ids" domain="[('id', '!=', src_lang_id)]"/>
</group>
</group>
</page>
</notebook>
</sheet>
</form>
</field>
</record>
</odoo>