Skip to content
Snippets Groups Projects
Commit ddadf4095588 authored by Vincent Hatakeyama's avatar Vincent Hatakeyama
Browse files

:sparkles: port to Odoo 15

parent d940cb24f4ee
No related branches found
No related tags found
No related merge requests found
Pipeline #44245 passed
<?xml version="1.0" encoding="UTF-8" ?>
<svg xmlns="http://www.w3.org/2000/svg" width="114" height="20">
<linearGradient id="b" x2="0" y2="100%">
<stop offset="0" stop-color="#bbb" stop-opacity=".1" />
<stop offset="1" stop-opacity=".1" />
</linearGradient>
<mask id="anybadge_1">
<rect width="114" height="20" rx="3" fill="#fff" />
</mask>
<g mask="url(#anybadge_1)">
<path fill="#555" d="M0 0h72v20H0z" />
<path fill="#000000" d="M72 0h42v20H72z" />
<path fill="url(#b)" d="M0 0h114v20H0z" />
</g>
<g
fill="#fff"
text-anchor="middle"
font-family="DejaVu Sans,Verdana,Geneva,sans-serif"
font-size="11"
>
<text x="37.0" y="15" fill="#010101" fill-opacity=".3">code style</text>
<text x="36.0" y="14">code style</text>
</g>
<g
fill="#fff"
text-anchor="middle"
font-family="DejaVu Sans,Verdana,Geneva,sans-serif"
font-size="11"
>
<text x="94.0" y="15" fill="#010101" fill-opacity=".3">black</text>
<text x="93.0" y="14">black</text>
</g>
</svg>
<?xml version="1.0" encoding="UTF-8" ?>
<svg xmlns="http://www.w3.org/2000/svg" width="129" height="20">
<linearGradient id="b" x2="0" y2="100%">
<stop offset="0" stop-color="#bbb" stop-opacity=".1" />
<stop offset="1" stop-opacity=".1" />
</linearGradient>
<mask id="anybadge_1">
<rect width="129" height="20" rx="3" fill="#fff" />
</mask>
<g mask="url(#anybadge_1)">
<path fill="#555" d="M0 0h72v20H0z" />
<path fill="#ff69b4" d="M72 0h57v20H72z" />
<path fill="url(#b)" d="M0 0h129v20H0z" />
</g>
<g
fill="#fff"
text-anchor="middle"
font-family="DejaVu Sans,Verdana,Geneva,sans-serif"
font-size="11"
>
<text x="37.0" y="15" fill="#010101" fill-opacity=".3">code style</text>
<text x="36.0" y="14">code style</text>
</g>
<g
fill="#fff"
text-anchor="middle"
font-family="DejaVu Sans,Verdana,Geneva,sans-serif"
font-size="11"
>
<text x="101.5" y="15" fill="#010101" fill-opacity=".3">prettier</text>
<text x="100.5" y="14">prettier</text>
</g>
</svg>
<?xml version="1.0" encoding="UTF-8" ?>
<svg xmlns="http://www.w3.org/2000/svg" width="107" height="20">
<linearGradient id="b" x2="0" y2="100%">
<stop offset="0" stop-color="#bbb" stop-opacity=".1" />
<stop offset="1" stop-opacity=".1" />
</linearGradient>
<mask id="anybadge_1">
<rect width="107" height="20" rx="3" fill="#fff" />
</mask>
<g mask="url(#anybadge_1)">
<path fill="#555" d="M0 0h53v20H0z" />
<path fill="#0000FF" d="M53 0h54v20H53z" />
<path fill="url(#b)" d="M0 0h107v20H0z" />
</g>
<g
fill="#fff"
text-anchor="middle"
font-family="DejaVu Sans,Verdana,Geneva,sans-serif"
font-size="11"
>
<text x="27.5" y="15" fill="#010101" fill-opacity=".3">licence</text>
<text x="26.5" y="14">licence</text>
</g>
<g
fill="#fff"
text-anchor="middle"
font-family="DejaVu Sans,Verdana,Geneva,sans-serif"
font-size="11"
>
<text x="81.0" y="15" fill="#010101" fill-opacity=".3">AGPL-3</text>
<text x="80.0" y="14">AGPL-3</text>
</g>
</svg>
<?xml version="1.0" encoding="UTF-8" ?>
<svg xmlns="http://www.w3.org/2000/svg" width="177" height="20">
<linearGradient id="b" x2="0" y2="100%">
<stop offset="0" stop-color="#bbb" stop-opacity=".1" />
<stop offset="1" stop-opacity=".1" />
</linearGradient>
<mask id="anybadge_1">
<rect width="177" height="20" rx="3" fill="#fff" />
</mask>
<g mask="url(#anybadge_1)">
<path fill="#555" d="M0 0h61v20H0z" />
<path fill="#4c1" d="M61 0h116v20H61z" />
<path fill="url(#b)" d="M0 0h177v20H0z" />
</g>
<g
fill="#fff"
text-anchor="middle"
font-family="DejaVu Sans,Verdana,Geneva,sans-serif"
font-size="11"
>
<text x="31.5" y="15" fill="#010101" fill-opacity=".3">maturity</text>
<text x="30.5" y="14">maturity</text>
</g>
<g
fill="#fff"
text-anchor="middle"
font-family="DejaVu Sans,Verdana,Geneva,sans-serif"
font-size="11"
>
<text x="120.0" y="15" fill="#010101" fill-opacity=".3">Production/Stable</text>
<text x="119.0" y="14">Production/Stable</text>
</g>
</svg>
# Configuration for known file extensions
[*.{css,htm,html,js,json,jsx,less,markdown,md,py,rst,sass,scss,toml,xml,yaml,yml}]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
[*.{json,yml,yaml,rst,markdown,md,toml}]
indent_size = 2
# Do not configure editor for libs
[*/static/{lib,src/lib}/**]
charset = unset
end_of_line = unset
indent_size = unset
indent_style = unset
insert_final_newline = false
trim_trailing_whitespace = false
[flake8]
max-line-length = 88
include:
- project: xcg/ci-templates
file: /odoo/13.0/gitlab-ci.yaml
file: /odoo/15.0/gitlab-ci.yaml
# Defaults for all prettier-supported languages.
# Prettier will complete this with settings from .editorconfig file.
bracketSpacing: false
printWidth: 88
proseWrap: always
semi: true
trailingComma: "es5"
xmlWhitespaceSensitivity: "ignore"
rules:
document-start: disable
indentation:
indent-sequences: true
=======
Changes
=======
Changelog
=========
......@@ -4,9 +3,4 @@
13.0.1.1.1
----------
Fix reST in readme.
13.0.1.1.0
15.0.1.0.0
----------
......@@ -11,14 +5,3 @@
----------
Add code to handle currency formatting.
Stop using hook to add methods to base when inheriting works.
Add formatter class to ease creating compute methods.
Add more caches.
13.0.1.0.0
----------
Port to Odoo 13.0
Port to Odoo 15.0.
......@@ -2,6 +2,22 @@
ICU Format
==========
.. Update the badge below depending on status
.. |maturity| image:: .badges/maturity.svg
:target: https://odoo-community.org/page/development-status
:alt: Alpha
.. |license| image:: .badges/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |black| image:: .badges/code_style-black-000000.svg
:target: https://github.com/psf/black
:alt: Black
.. |prettier| image:: .badges/code_style-prettier-ff69b4.svg
:target: https://github.com/prettier/prettier
:alt: Prettier
|maturity| |license| |black| |prettier|
Provides methods that encapsulates PyICU, including at the model level.
ICU provides handling of plural and many other things that are not present in the gettext implementation of Odoo.
......
......@@ -21,7 +21,7 @@
{
"name": "ICU Format",
"summary": "Format message using ICU",
"version": "13.0.1.1.1",
"version": "15.0.1.0.0",
"category": "Technical",
"author": "XCG Consulting",
"website": "https://odoo.consulting/",
......
......@@ -37,9 +37,9 @@
change Odoo’s function odoo.tools.translate.trans_generate.
"""
__original_extract = extract.extract
__ICU_FORMAT_TRANSLATE = "icu_format_translate"
__icu_format_translate = "icu_format_translate"
# Same signature as babel.message.extract.extract
def _extract(
method,
fileobj,
......@@ -41,9 +41,9 @@
# Same signature as babel.message.extract.extract
def _extract(
method,
fileobj,
keywords={
keywords={ # noqa: B006
"N_": None,
"_": None,
"dgettext": (2,),
......@@ -61,8 +61,8 @@
strip_comment_tags=True,
):
if method == "python":
if __ICU_FORMAT_TRANSLATE not in keywords:
keywords[__ICU_FORMAT_TRANSLATE] = (1,)
if __icu_format_translate not in keywords:
keywords[__icu_format_translate] = (1,)
# changed to include this tag by default
if TRANSLATORS_TAG not in comment_tags:
comment_tags += (TRANSLATORS_TAG,)
......
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * icuformat
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 15.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-11-09 16:25+0000\n"
"PO-Revision-Date: 2022-11-09 17:27+0100\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
"X-Generator: Poedit 2.4.2\n"
"Last-Translator: Vincent Hatakeyama <vincent.hatakeyama@xcg-consulting.fr>\n"
"Language: fr\n"
#. module: icuformat
#. This is a test message, no need for translation
#: code:addons/icuformat/tests/test_icuformat.py:0
#, python-format
msgid "A message"
msgstr ""
#. module: icuformat
#: model:ir.model,name:icuformat.model_base
msgid "Base"
msgstr "Base"
#. module: icuformat
#: model:ir.model,name:icuformat.model_res_currency
msgid "Currency"
msgstr "Devise"
......@@ -21,6 +21,8 @@
import logging
from typing import Dict, Mapping, Optional, Union
# Disable the warning as the library name is pyicu
# pylint: disable=missing-manifest-dependency
from icu import Formattable, ICUError, ListFormatter, Locale, MessageFormat
_logger = logging.getLogger(__name__)
......@@ -40,8 +42,7 @@
"""Return an item, eventually created with the factory"""
# create a tuple out of args and kwargs
key = tuple(
tuple(arg.items()) if isinstance(arg, dict) else arg
for arg in args
tuple(arg.items()) if isinstance(arg, dict) else arg for arg in args
) + tuple(
(key, tuple(value.items()) if isinstance(value, dict) else value)
for key, value in kwargs.items()
......@@ -90,9 +91,7 @@
def format(
self,
args: Dict[
str, Union[int, str, datetime.date, datetime.datetime, bool, float]
],
args: Dict[str, Union[int, str, datetime.date, datetime.datetime, bool, float]],
raise_exception: bool = True,
):
"""Format a message with ICU.
......@@ -127,9 +126,7 @@
def icu_format(
lang: Optional[str],
msg: str,
args: Dict[
str, Union[int, str, datetime.date, datetime.datetime, bool, float]
],
args: Dict[str, Union[int, str, datetime.date, datetime.datetime, bool, float]],
raise_exception: bool = True,
locale_kwargs: Optional[Mapping[str, str]] = None,
) -> str:
......
......@@ -19,8 +19,6 @@
##############################################################################
import logging
from odoo.tools import GettextAlias
from .icu_format import icu_format
......@@ -39,9 +37,6 @@
(C) to format the messages
"""
# This will be used to call _get_lang (an instance is needed)
__gettext_alias = GettextAlias()
def log(self, level, msg, *args, **kwargs):
"""Changed to reformat the message according to the lang information,
and from the provided dictionary.
......@@ -51,7 +46,7 @@
args_dict = args[0]
args = args[1:]
else:
args_dict = dict()
args_dict = {}
msg = icu_format("C", msg, args_dict)
msg, kwargs = self.process(msg, kwargs)
......@@ -79,7 +74,7 @@
def get_logger(name: str = None) -> logging.LoggerAdapter:
"""Provide a way to get a Logger that will call :func:`icu_format` only
when needed (to avoid spending time formating a message that will not be
when needed (to avoid spending time formatting a message that will not be
displayed). This is similar to what is done in logging for formatting.
.. code-block:: python
......@@ -91,4 +86,4 @@
_logger.info("Value: {value, number}", {"value": 1000})
"""
logger = logging.getLogger(name)
return ICUFormatAdapter(logger, dict())
return ICUFormatAdapter(logger, {})
import inspect
import logging
MAGIC_KEY = "icuvalues"
class CustomAdapter(logging.LoggerAdapter):
def log(self, level, msg, *args, **kwargs):
"""
Delegate a log call to the underlying logger, after adding
contextual information from this adapter instance.
"""
if self.isEnabledFor(level):
# reuse _ way of finding the lang
lang = None
frame = inspect.currentframe()
if frame is not None:
frame = frame.f_back
if frame:
lang = "en"
# lang = GettextAlias._get_lang(frame)
# pdb.set_trace()
if args:
args_dict = args[0]
args = args[1:]
else:
args_dict = {}
msg = "icuformat(" + lang + ", " + msg + ", " + str(args_dict) + ")"
msg, kwargs = self.process(msg, kwargs)
self.logger.log(level, msg, *args, **kwargs)
logging.basicConfig(
level=logging.DEBUG,
format="%(relativeCreated)6d %(threadName)s %(message)s",
)
logger = logging.getLogger(__name__)
adapter = CustomAdapter(logger, {})
adapter.info("ABC", {"a": 123})
adapter.critical("Fatal")
brace_formatter = logging.Formatter(fmt="{message}", style="{")
logger_brace = logger.getChild("test_brace")
map(
lambda handler: handler.setFormatter(brace_formatter),
logger_brace.handlers,
)
logger_brace.debug("Test %s", "a")
##############################################################################
#
# ICU Format, a module for Odoo
# Copyright (C) 2021 XCG Consulting <https://odoo.consulting>
# Copyright (C) 2021, 2022 XCG Consulting (https://xcg-consulting.fr/)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
......@@ -21,5 +21,8 @@
import logging
from typing import Dict, Mapping, Union
# Disable the warning as the library name is pyicu
from icu import ICUError # pylint: disable=missing-manifest-dependency
from odoo import _, models
......@@ -24,15 +27,8 @@
from odoo import _, models
from ..icu_format import (
ICUFormatter,
_icu_formatter_cache,
icu_format,
icu_list_format,
)
from icu import ICUError
from ..icu_format import ICUFormatter, _icu_formatter_cache, icu_format, icu_list_format
_logger = logging.getLogger(__name__)
class BaseModel(models.AbstractModel):
......@@ -34,10 +30,9 @@
_logger = logging.getLogger(__name__)
class BaseModel(models.AbstractModel):
"""Add methods to BaseModel to use icu formatting.
"""
"""Add methods to BaseModel to use icu formatting."""
_inherit = "base"
......@@ -49,9 +44,7 @@
def icu_format(
self,
msg: str,
args: Dict[
str, Union[int, str, datetime.date, datetime.datetime, bool, float]
],
args: Dict[str, Union[int, str, datetime.date, datetime.datetime, bool, float]],
raise_exception: bool = False,
) -> str:
"""Provide a faster way to format the message, using the context lang,
......@@ -68,9 +61,7 @@
def icu_format_translate(
self,
untranslated_message: str,
args: Dict[
str, Union[int, str, datetime.date, datetime.datetime, bool, float]
],
args: Dict[str, Union[int, str, datetime.date, datetime.datetime, bool, float]],
raise_exception: bool = False,
) -> str:
"""Try to format and translate a message.
......
##############################################################################
#
# ICU Format, a module for Odoo
# Copyright (C) 2021 XCG Consulting <https://odoo.consulting>
# Copyright (C) 2021, 2022 XCG Consulting <https://xcg-consulting.fr/>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
......
[tool.isort]
py_version = 310
profile = "black"
known_odoo = ['odoo']
known_odoo_addons = ['odoo.addons']
sections = [
'FUTURE',
'STDLIB',
'THIRDPARTY',
'ODOO',
'ODOO_ADDONS',
'FIRSTPARTY',
'LOCALFOLDER'
]
[tool.black]
target = 3.10
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment