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
45d6d678
Commit
45d6d678
authored
Oct 18, 2012
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use object based file format types
parent
608a7756
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
91 additions
and
73 deletions
+91
-73
weblate/trans/models.py
weblate/trans/models.py
+91
-73
No files found.
weblate/trans/models.py
View file @
45d6d678
...
@@ -60,64 +60,105 @@ from distutils.version import LooseVersion
...
@@ -60,64 +60,105 @@ from distutils.version import LooseVersion
logger
=
logging
.
getLogger
(
'weblate'
)
logger
=
logging
.
getLogger
(
'weblate'
)
class
FileFormat
(
object
):
'''
Simple object defining file format loader.
'''
def
__init__
(
self
,
name
,
loader
,
monolingual
=
None
,
mark_fuzzy
=
False
,
fixups
=
None
):
self
.
name
=
name
self
.
loader
=
loader
self
.
monolingual
=
monolingual
self
.
mark_fuzzy
=
mark_fuzzy
self
.
fixups
=
fixups
def
load
(
self
,
storefile
):
'''
Loads file using defined loader.
'''
loader
=
self
.
loader
# If loader is callable call it directly
if
callable
(
loader
):
return
loader
(
storefile
)
# Tuple style loader, import from translate toolkit
module_name
,
class_name
=
loader
if
'.'
in
module_name
:
module
=
importlib
.
import_module
(
module_name
)
else
:
module
=
importlib
.
import_module
(
'translate.storage.%s'
%
module_name
)
# Get the class
storeclass
=
getattr
(
module
,
class_name
)
# Parse file
store
=
storeclass
.
parsefile
(
storefile
)
# Apply possible fixups
if
self
.
fixups
is
not
None
:
for
fix
in
self
.
fixups
:
setattr
(
store
,
fix
,
self
.
fixups
[
fix
])
return
store
FILE_FORMATS
=
{
FILE_FORMATS
=
{
'auto'
:
{
'auto'
:
FileFormat
(
'name'
:
ugettext_lazy
(
'Automatic detection'
),
ugettext_lazy
(
'Automatic detection'
),
'loader'
:
factory
.
getobject
,
factory
.
getobject
,
'monolingual'
:
None
,
# Depends on actual format
),
},
'po'
:
FileFormat
(
'po'
:
{
ugettext_lazy
(
'Gettext PO file'
),
'name'
:
ugettext_lazy
(
'Gettext PO file'
),
(
'po'
,
'pofile'
),
'loader'
:
(
'po'
,
'pofile'
),
False
,
'monolingual'
:
False
,
),
},
'ts'
:
FileFormat
(
'ts'
:
{
ugettext_lazy
(
'XLIFF Translation File'
),
'name'
:
ugettext_lazy
(
'XLIFF Translation File'
),
(
'ts2'
,
'tsfile'
),
'loader'
:
(
'ts2'
,
'tsfile'
),
),
'monolingual'
:
None
,
# Can be both
'xliff'
:
FileFormat
(
},
ugettext_lazy
(
'Qt Linguist Translation File'
),
'xliff'
:
{
(
'xliff'
,
'xlifffile'
),
'name'
:
ugettext_lazy
(
'Qt Linguist Translation File'
),
),
'loader'
:
(
'xliff'
,
'xlifffile'
),
'strings'
:
FileFormat
(
'monolingual'
:
None
,
# Can be both
ugettext_lazy
(
'OS X Strings'
),
},
(
'properties'
,
'stringsfile'
),
'strings'
:
{
False
,
'name'
:
ugettext_lazy
(
'OS X Strings'
),
),
'loader'
:
(
'properties'
,
'stringsfile'
),
'properties'
:
FileFormat
(
'monolingual'
:
False
,
ugettext_lazy
(
'Java Properties'
),
},
(
'properties'
,
'javafile'
),
'properties'
:
{
True
,
'name'
:
ugettext_lazy
(
'Java Properties'
),
'loader'
:
(
'properties'
,
'javafile'
),
'monolingual'
:
True
,
# Java properties need to be iso-8859-1, but
# Java properties need to be iso-8859-1, but
# ttkit converts them to utf-8
# ttkit converts them to utf-8
'fixups'
:
{
'encoding'
:
'iso-8859-1'
},
fixups
=
{
'encoding'
:
'iso-8859-1'
},
}
,
)
,
'properties-utf8'
:
{
'properties-utf8'
:
FileFormat
(
'name'
:
ugettext_lazy
(
'Java Properties (UTF-8)'
),
ugettext_lazy
(
'Java Properties (UTF-8)'
),
'loader'
:
(
'properties'
,
'javautf8file'
),
(
'properties'
,
'javautf8file'
),
'monolingual'
:
True
,
True
,
}
,
)
,
}
}
# Check if there is support for Android resources
# Check if there is support for Android resources
# Available as patch at https://github.com/translate/translate/pull/2
# Available as patch at https://github.com/translate/translate/pull/2
try
:
try
:
from
translate.storage
import
aresource
from
translate.storage
import
aresource
FILE_FORMATS
[
'aresource'
]
=
{
FILE_FORMATS
[
'aresource'
]
=
FileFormat
(
'name'
:
ugettext_lazy
(
'Android String Resource'
),
ugettext_lazy
(
'Android String Resource'
),
'loader'
:
(
'aresource'
,
'AndroidResourceFile'
),
(
'aresource'
,
'AndroidResourceFile'
),
'monolingual'
:
True
,
True
,
}
mark_fuzzy
=
True
,
)
except
ImportError
:
except
ImportError
:
FILE_FORMATS
[
'aresource'
]
=
{
FILE_FORMATS
[
'aresource'
]
=
FileFormat
(
'name'
:
ugettext_lazy
(
'Android String Resource'
),
ugettext_lazy
(
'Android String Resource'
),
'loader'
:
(
'ttkit.aresource'
,
'AndroidResourceFile'
),
(
'ttkit.aresource'
,
'AndroidResourceFile'
),
'monolingual'
:
True
,
True
,
}
mark_fuzzy
=
True
,
)
FILE_FORMAT_CHOICES
=
[(
fmt
,
FILE_FORMATS
[
fmt
]
[
'name'
]
)
for
fmt
in
FILE_FORMATS
]
FILE_FORMAT_CHOICES
=
[(
fmt
,
FILE_FORMATS
[
fmt
]
.
name
)
for
fmt
in
FILE_FORMATS
]
def
ttkit
(
storefile
,
file_format
=
'auto'
):
def
ttkit
(
storefile
,
file_format
=
'auto'
):
'''
'''
...
@@ -137,32 +178,9 @@ def ttkit(storefile, file_format = 'auto'):
...
@@ -137,32 +178,9 @@ def ttkit(storefile, file_format = 'auto'):
raise
Exception
(
'Not supported file format: %s'
%
file_format
)
raise
Exception
(
'Not supported file format: %s'
%
file_format
)
# Get loader
# Get loader
loader
=
FILE_FORMATS
[
file_format
][
'loader'
]
format_obj
=
FILE_FORMATS
[
file_format
]
# If loader is callable call it directly
if
callable
(
loader
):
return
loader
(
storefile
)
# Tuple style loader, import from translate toolkit
module_name
,
class_name
=
loader
if
'.'
in
module_name
:
module
=
importlib
.
import_module
(
module_name
)
else
:
module
=
importlib
.
import_module
(
'translate.storage.%s'
%
module_name
)
# Get the class
storeclass
=
getattr
(
module
,
class_name
)
# Parse file
store
=
storeclass
.
parsefile
(
storefile
)
# Apply possible fixups
if
'fixups'
in
FILE_FORMATS
[
file_format
]:
for
fix
in
FILE_FORMATS
[
file_format
][
'fixups'
]:
setattr
(
store
,
fix
,
FILE_FORMATS
[
file_format
][
'fixups'
][
fix
])
return
store
return
format_obj
.
load
(
storefile
)
def
validate_repoweb
(
val
):
def
validate_repoweb
(
val
):
try
:
try
:
...
@@ -1069,7 +1087,7 @@ class SubProject(models.Model):
...
@@ -1069,7 +1087,7 @@ class SubProject(models.Model):
'''
'''
Returns true if subproject is using template for translation
Returns true if subproject is using template for translation
'''
'''
return
FILE_FORMATS
[
self
.
file_format
]
[
'monolingual'
]
!=
False
and
self
.
template
!=
''
return
FILE_FORMATS
[
self
.
file_format
]
.
monolingual
!=
False
and
self
.
template
!=
''
def
get_template_store
(
self
):
def
get_template_store
(
self
):
'''
'''
...
...
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