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
c411ec0b
Commit
c411ec0b
authored
Apr 25, 2014
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move all template validation to single block
Signed-off-by:
Michal Čihař
<
michal@cihar.com
>
parent
d3975afa
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
39 deletions
+40
-39
weblate/trans/models/subproject.py
weblate/trans/models/subproject.py
+40
-39
No files found.
weblate/trans/models/subproject.py
View file @
c411ec0b
...
...
@@ -848,26 +848,6 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
_
(
'Export URL is not used when repository is linked!'
)
)
def
clean_template
(
self
):
'''
Validates whether template can be loaded.
'''
full_path
=
os
.
path
.
join
(
self
.
get_path
(),
self
.
template
)
if
not
os
.
path
.
exists
(
full_path
):
raise
ValidationError
(
_
(
'Template file not found!'
))
try
:
self
.
load_template_store
()
except
ValueError
:
raise
ValidationError
(
_
(
'Format of translation base file could not be recognized.'
)
)
except
Exception
as
exc
:
raise
ValidationError
(
_
(
'Failed to parse translation base file: %s'
)
%
str
(
exc
)
)
def
clean_lang_codes
(
self
,
matches
):
'''
Validates that there are no double language codes found in the files.
...
...
@@ -951,6 +931,44 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
'project settings.'
))
def
clean_template
(
self
):
"""
Validates template value.
"""
# Test for unexpected template usage
if
self
.
template
!=
''
and
self
.
file_format_cls
.
monolingual
is
False
:
raise
ValidationError
(
_
(
'You can not base file with bilingual translation!'
)
)
# Special case for Gettext
if
self
.
template
.
endswith
(
'.pot'
)
and
self
.
filemask
.
endswith
(
'.po'
):
raise
ValidationError
(
_
(
'You can not base file with bilingual translation!'
)
)
# Validate template loading
if
self
.
has_template
():
full_path
=
os
.
path
.
join
(
self
.
get_path
(),
self
.
template
)
if
not
os
.
path
.
exists
(
full_path
):
raise
ValidationError
(
_
(
'Template file not found!'
))
try
:
self
.
load_template_store
()
except
ValueError
:
raise
ValidationError
(
_
(
'Format of translation base file could not be recognized.'
)
)
except
Exception
as
exc
:
raise
ValidationError
(
_
(
'Failed to parse translation base file: %s'
)
%
str
(
exc
)
)
elif
self
.
file_format_cls
.
monolingual
:
raise
ValidationError
(
_
(
'You can not use monolingual translation without base file!'
)
)
def
clean
(
self
):
'''
Validator fetches repository and tries to find translation files.
...
...
@@ -983,25 +1001,8 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
# Try parsing files
self
.
clean_files
(
matches
)
# Test for unexpected template usage
if
self
.
template
!=
''
and
self
.
file_format_cls
.
monolingual
is
False
:
raise
ValidationError
(
_
(
'You can not base file with bilingual translation!'
)
)
# Special case for Gettext
if
self
.
template
.
endswith
(
'.pot'
)
and
self
.
filemask
.
endswith
(
'.po'
):
raise
ValidationError
(
_
(
'You can not base file with bilingual translation!'
)
)
# Validate template
if
self
.
has_template
():
self
.
clean_template
()
elif
self
.
file_format_cls
.
monolingual
:
raise
ValidationError
(
_
(
'You can not use monolingual translation without base file!'
)
)
# Template validation
self
.
clean_template
()
# New language options
self
.
clean_new_lang
()
...
...
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