Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
4228225e
Commit
4228225e
authored
Jul 08, 2015
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve filemask language code extraction
Issue #153 Signed-off-by:
Michal Čihař
<
michal@cihar.com
>
parent
e6230d4c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
12 deletions
+35
-12
weblate/trans/models/subproject.py
weblate/trans/models/subproject.py
+24
-10
weblate/trans/tests/test_models.py
weblate/trans/tests/test_models.py
+11
-2
No files found.
weblate/trans/models/subproject.py
View file @
4228225e
...
...
@@ -30,6 +30,8 @@ from glob import glob
import
os
import
time
import
subprocess
import
fnmatch
import
re
from
weblate.trans.formats
import
FILE_FORMAT_CHOICES
,
FILE_FORMATS
from
weblate.trans.mixins
import
PercentMixin
,
URLMixin
,
PathMixin
from
weblate.trans.filelock
import
FileLock
...
...
@@ -393,6 +395,15 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
self
.
_all_flags
=
None
self
.
_linked_subproject
=
None
self
.
_repository
=
None
self
.
_filemask_re
=
None
@
property
def
filemask_re
(
self
):
if
self
.
_filemask_re
is
None
:
self
.
_filemask_re
=
re
.
compile
(
fnmatch
.
translate
(
self
.
filemask
).
replace
(
'.*'
,
'(.*)'
)
)
return
self
.
_filemask_re
@
property
def
log_prefix
(
self
):
...
...
@@ -958,16 +969,19 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
'''
# No * in mask?
if
'*'
not
in
self
.
filemask
:
return
'INVALID'
parts
=
self
.
filemask
.
split
(
'*'
,
1
)
# Assume English language for template
if
path
==
self
.
template
:
return
'en'
# Get part matching to first wildcard
if
len
(
parts
[
1
])
==
0
:
code
=
path
[
len
(
parts
[
0
]):].
split
(
'/'
)[
0
]
else
:
code
=
path
[
len
(
parts
[
0
]):
-
len
(
parts
[
1
])].
split
(
'/'
)[
0
]
return
''
# Parse filename
matches
=
self
.
filemask_re
.
match
(
path
)
if
not
matches
:
# Assume English language for template
if
path
==
self
.
template
:
return
'en'
return
''
code
=
matches
.
group
(
1
)
# Remove possible encoding part
if
'.'
in
code
and
(
'.utf'
in
code
.
lower
()
or
'.iso'
in
code
.
lower
()):
return
code
.
split
(
'.'
)[
0
]
...
...
weblate/trans/tests/test_models.py
View file @
4228225e
...
...
@@ -691,10 +691,10 @@ class SubProjectTest(RepoTestCase):
def
test_lang_code
(
self
):
subproject
=
SubProject
()
subproject
.
filemask
=
'Solution/Project/Resources*.resx'
subproject
.
filemask
=
'Solution/Project/Resources
.
*.resx'
self
.
assertEqual
(
subproject
.
get_lang_code
(
'Solution/Project/Resources.es-mx.resx'
),
'
.
es-mx'
'es-mx'
)
self
.
assertEqual
(
subproject
.
get_lang_code
(
'Solution/Project/Resources.resx'
),
...
...
@@ -715,6 +715,15 @@ class SubProjectTest(RepoTestCase):
]
)
def
test_lang_code_template
(
self
):
subproject
=
SubProject
()
subproject
.
filemask
=
'Solution/Project/Resources.*.resx'
subproject
.
template
=
'Solution/Project/Resources.resx'
self
.
assertEqual
(
subproject
.
get_lang_code
(
'Solution/Project/Resources.resx'
),
'en'
)
class
TranslationTest
(
RepoTestCase
):
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment