Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
ICU Format
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package Registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
XCG
Odoo modules
ICU Format
Commits
2651c5a8904d
Commit
2651c5a8904d
authored
4 years ago
by
Vincent Hatakeyama
Browse files
Options
Downloads
Patches
Plain Diff
black
parent
4c6bf2470d3e
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
__manifest__.py
+10
-16
10 additions, 16 deletions
__manifest__.py
icuformat.py
+3
-5
3 additions, 5 deletions
icuformat.py
tests/test_icuformat.py
+12
-11
12 additions, 11 deletions
tests/test_icuformat.py
with
25 additions
and
32 deletions
__manifest__.py
+
10
−
16
View file @
2651c5a8
...
...
@@ -18,20 +18,14 @@
##############################################################################
{
'
name
'
:
'
ICU Format
'
,
'
summary
'
:
'
Format message using ICU
'
,
'
version
'
:
'
11.0.1.0
'
,
'
category
'
:
'
Technical
'
,
'
author
'
:
'
XCG Consulting
'
,
'
website
'
:
'
http://odoo.consulting/
'
,
'
license
'
:
'
AGPL-3
'
,
'
depends
'
:
[
'
base
'
,
],
'
external_dependencies
'
:
{
'
python
'
:
[
'
PyICU
'
,
],
},
'
installable
'
:
True
,
"
name
"
:
"
ICU Format
"
,
"
summary
"
:
"
Format message using ICU
"
,
"
version
"
:
"
11.0.1.0
"
,
"
category
"
:
"
Technical
"
,
"
author
"
:
"
XCG Consulting
"
,
"
website
"
:
"
http://odoo.consulting/
"
,
"
license
"
:
"
AGPL-3
"
,
"
depends
"
:
[
"
base
"
],
"
external_dependencies
"
:
{
"
python
"
:
[
"
PyICU
"
]},
"
installable
"
:
True
,
}
This diff is collapsed.
Click to expand it.
icuformat.py
+
3
−
5
View file @
2651c5a8
...
...
@@ -30,10 +30,10 @@
key_list
.
append
(
key
)
value_list
.
append
(
Formattable
(
value
))
if
not
lang
:
lang
=
'
en
'
lang
=
"
en
"
locale
=
Locale
(
lang
)
return
MessageFormat
(
msg
,
locale
).
format
(
key_list
,
value_list
)
def
_icuformat
(
self
,
msg
:
str
,
args
:
Dict
[
str
,
Union
[
int
,
str
]])
->
str
:
return
icuformat
(
...
...
@@ -34,12 +34,10 @@
locale
=
Locale
(
lang
)
return
MessageFormat
(
msg
,
locale
).
format
(
key_list
,
value_list
)
def
_icuformat
(
self
,
msg
:
str
,
args
:
Dict
[
str
,
Union
[
int
,
str
]])
->
str
:
return
icuformat
(
self
.
env
.
context
.
get
(
'
lang
'
)
or
self
.
env
.
user
.
lang
,
msg
,
args
,
self
.
env
.
context
.
get
(
"
lang
"
)
or
self
.
env
.
user
.
lang
,
msg
,
args
)
...
...
@@ -43,4 +41,4 @@
)
setattr
(
BaseModel
,
'
icuformat
'
,
_icuformat
)
setattr
(
BaseModel
,
"
icuformat
"
,
_icuformat
)
This diff is collapsed.
Click to expand it.
tests/test_icuformat.py
+
12
−
11
View file @
2651c5a8
...
...
@@ -24,9 +24,9 @@
class
Test
(
tests
.
TransactionCase
):
def
test_simple
(
self
):
msg
=
'
{test}
'
d
=
{
'
test
'
:
'
foobar
'
}
expected
=
'
foobar
'
self
.
assertEqual
(
expected
,
icuformat
(
'
en
'
,
msg
,
d
))
msg
=
"
{test}
"
d
=
{
"
test
"
:
"
foobar
"
}
expected
=
"
foobar
"
self
.
assertEqual
(
expected
,
icuformat
(
"
en
"
,
msg
,
d
))
def
test_nothing_to_format
(
self
):
...
...
@@ -31,4 +31,4 @@
def
test_nothing_to_format
(
self
):
msg
=
'
test
'
msg
=
"
test
"
d
=
dict
()
...
...
@@ -34,5 +34,5 @@
d
=
dict
()
self
.
assertEqual
(
msg
,
icuformat
(
'
en
'
,
msg
,
d
))
self
.
assertEqual
(
msg
,
icuformat
(
"
en
"
,
msg
,
d
))
def
test_nested_plural_select
(
self
):
msg
=
(
...
...
@@ -58,5 +58,5 @@
"
}}}
"
)
d
=
dict
(
gender_of_host
=
'
female
'
,
gender_of_host
=
"
female
"
,
num_guests
=
1005
,
...
...
@@ -62,4 +62,5 @@
num_guests
=
1005
,
host
=
'
Ms. Marple
'
,
guest
=
'
Robert
'
)
host
=
"
Ms. Marple
"
,
guest
=
"
Robert
"
,
)
expected
=
(
...
...
@@ -65,3 +66,3 @@
expected
=
(
'
Ms. Marple invites Robert and 1,004 other people to her party.
'
"
Ms. Marple invites Robert and 1,004 other people to her party.
"
)
...
...
@@ -67,2 +68,2 @@
)
self
.
assertEqual
(
expected
,
icuformat
(
'
en
'
,
msg
,
d
))
self
.
assertEqual
(
expected
,
icuformat
(
"
en
"
,
msg
,
d
))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment