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
baadf6ca
Commit
baadf6ca
authored
Mar 01, 2013
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial implementation of file format classes (issue #184)
parent
b12790a1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
111 additions
and
64 deletions
+111
-64
trans/formats.py
trans/formats.py
+111
-64
No files found.
trans/formats.py
View file @
baadf6ca
...
...
@@ -26,17 +26,31 @@ import importlib
import
__builtin__
FILE_FORMATS
=
{}
def
register_fileformat
(
fileformat
):
'''
Registers fileformat in dictionary.
'''
FILE_FORMATS
[
fileformat
.
format_id
]
=
fileformat
()
class
FileFormat
(
object
):
'''
Simple
object defining file format loader.
Generic
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
name
=
''
format_id
=
''
loader
=
None
monolingual
=
None
mark_fuzzy
=
None
def
fixup
(
self
,
store
):
'''
Performs optional fixups on store.
'''
return
store
def
load
(
self
,
storefile
):
'''
...
...
@@ -44,10 +58,6 @@ class FileFormat(object):
'''
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
:
...
...
@@ -70,61 +80,98 @@ class FileFormat(object):
# 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
])
# Apply possible fixups and return
return
self
.
fixup
(
store
)
class
AutoFormat
(
FileFormat
):
name
=
_
(
'Automatic detection'
)
format_id
=
'auto'
def
load
(
self
,
storefile
):
'''
Directly loads using translate-toolkit.
'''
return
factory
.
getobject
(
storefile
)
register_fileformat
(
AutoFormat
)
class
PoFormat
(
FileFormat
):
name
=
_
(
'Gettext PO file'
)
format_id
=
'po'
loader
=
(
'po'
,
'pofile'
)
monolingual
=
False
register_fileformat
(
PoFormat
)
class
TSFormat
(
FileFormat
):
name
=
_
(
'Qt Linguist Translation File'
)
format_id
=
'ts'
loader
=
(
'ts2'
,
'tsfile'
)
register_fileformat
(
TSFormat
)
class
XliffFormat
(
FileFormat
):
name
=
_
(
'XLIFF Translation File'
)
format_id
=
'xliff'
loader
=
(
'xliff'
,
'xlifffile'
)
register_fileformat
(
XliffFormat
)
class
StringsFormat
(
FileFormat
):
name
=
_
(
'OS X Strings'
)
format_id
=
'strings'
loader
=
(
'properties'
,
'stringsfile'
)
monolingual
=
False
register_fileformat
(
StringsFormat
)
class
PropertiesFormat
(
FileFormat
):
name
=
_
(
'Java Properties'
)
format_id
=
'properties'
loader
=
(
'properties'
,
'javafile'
)
monolingual
=
True
def
fixup
(
self
,
store
):
'''
Java properties need to be iso-8859-1, but
ttkit converts them to utf-8.
'''
store
.
enncoding
=
'iso-8859-1'
register_fileformat
(
PropertiesFormat
)
class
PropertiesUtf8Format
(
FileFormat
):
name
=
_
(
'Java Properties (UTF-8)'
)
format_id
=
'properties-utf8'
loader
=
(
'properties'
,
'javautf8file'
)
monolingual
=
5
register_fileformat
(
PropertiesUtf8Format
)
class
PhpFormat
(
FileFormat
):
name
=
_
(
'PHP strings'
)
format_id
=
'php'
loader
=
(
'php'
,
'phpfile'
)
register_fileformat
(
PhpFormat
)
return
store
class
AndroidFormat
(
FileFormat
):
name
=
_
(
'Android String Resource'
)
format_id
=
'aresource'
loader
=
(
'aresource'
,
'AndroidResourceFile'
)
monolingual
=
True
mark_fuzzy
=
True
FILE_FORMATS
=
{
'auto'
:
FileFormat
(
_
(
'Automatic detection'
),
factory
.
getobject
,
),
'po'
:
FileFormat
(
_
(
'Gettext PO file'
),
(
'po'
,
'pofile'
),
False
,
),
'ts'
:
FileFormat
(
_
(
'Qt Linguist Translation File'
),
(
'ts2'
,
'tsfile'
),
),
'xliff'
:
FileFormat
(
_
(
'XLIFF Translation File'
),
(
'xliff'
,
'xlifffile'
),
),
'strings'
:
FileFormat
(
_
(
'OS X Strings'
),
(
'properties'
,
'stringsfile'
),
False
,
),
'properties'
:
FileFormat
(
_
(
'Java Properties'
),
(
'properties'
,
'javafile'
),
True
,
# Java properties need to be iso-8859-1, but
# ttkit converts them to utf-8
fixups
=
{
'encoding'
:
'iso-8859-1'
},
),
'properties-utf8'
:
FileFormat
(
_
(
'Java Properties (UTF-8)'
),
(
'properties'
,
'javautf8file'
),
True
,
),
'php'
:
FileFormat
(
_
(
'PHP strings'
),
(
'php'
,
'phpfile'
),
),
'aresource'
:
FileFormat
(
_
(
'Android String Resource'
),
(
'aresource'
,
'AndroidResourceFile'
),
True
,
mark_fuzzy
=
True
,
)
}
register_fileformat
(
AndroidFormat
)
FILE_FORMAT_CHOICES
=
[(
fmt
,
FILE_FORMATS
[
fmt
].
name
)
for
fmt
in
FILE_FORMATS
]
...
...
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