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
0010a54a
Commit
0010a54a
authored
Aug 21, 2015
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for CSV file format
Issue #644 Signed-off-by:
Michal Čihař
<
michal@cihar.com
>
parent
f34e8a38
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
0 deletions
+74
-0
docs/changes.rst
docs/changes.rst
+1
-0
docs/formats.rst
docs/formats.rst
+17
-0
weblate/trans/formats.py
weblate/trans/formats.py
+56
-0
No files found.
docs/changes.rst
View file @
0010a54a
...
@@ -28,6 +28,7 @@ Released on ? 2015.
...
@@ -28,6 +28,7 @@ Released on ? 2015.
* Improved layout of most of pages.
* Improved layout of most of pages.
* Support for adding words to dictionary while translating.
* Support for adding words to dictionary while translating.
* Added support for filtering languages to be managed by Weblate.
* Added support for filtering languages to be managed by Weblate.
* Added support for translating and importing CSV files.
weblate 2.3
weblate 2.3
-----------
-----------
...
...
docs/formats.rst
View file @
0010a54a
...
@@ -310,6 +310,23 @@ Example file:
...
@@ -310,6 +310,23 @@ Example file:
You need translate-toolkit 1.13.0 or newer to include support for this format.
You need translate-toolkit 1.13.0 or newer to include support for this format.
CSV files
---------
.. index::
pair: CSV; file format
pair: Comma separated values; file format
.. versionadded:: 2.4
CSV files can contain simple list of source and translation. Weblate supports
following files:
* Files with header defining fields (source, translation, location, ...)
* Files with two fileld - source and translation (in this order)
* Files with fields as defined by translate-toolkit: location, source,
target, id, fuzzy, context, translator_comments, developer_comments
Others
Others
------
------
...
...
weblate/trans/formats.py
View file @
0010a54a
...
@@ -36,6 +36,7 @@ import weblate
...
@@ -36,6 +36,7 @@ import weblate
import
subprocess
import
subprocess
import
os.path
import
os.path
import
re
import
re
import
csv
import
traceback
import
traceback
import
importlib
import
importlib
from
StringIO
import
StringIO
from
StringIO
import
StringIO
...
@@ -1059,6 +1060,61 @@ class JSONFormat(FileFormat):
...
@@ -1059,6 +1060,61 @@ class JSONFormat(FileFormat):
return
'json'
return
'json'
@
register_fileformat
class
CSVFormat
(
FileFormat
):
name
=
_
(
'CSV file'
)
format_id
=
'csv'
loader
=
(
'csvl10n'
,
'csvfile'
)
unit_class
=
JSONUnit
autoload
=
(
'.csv'
,)
@
property
def
mimetype
(
self
):
'''
Returns most common mime type for format.
'''
return
'text/csv'
@
property
def
extension
(
self
):
'''
Returns most common file extension for format.
'''
return
'csv'
@
classmethod
def
parse_store
(
cls
,
storefile
):
"""
Parses the store.
"""
storeclass
=
cls
.
get_class
()
# Read content for fixups
content
=
storefile
.
read
()
storefile
.
seek
(
0
)
# Parse file
store
=
storeclass
.
parsefile
(
storefile
)
# Did headers detection work?
if
store
.
fieldnames
!=
[
'location'
,
'source'
,
'target'
]:
return
store
fileobj
=
StringIOMode
(
storefile
.
name
,
content
)
# Try reading header
reader
=
csv
.
reader
(
fileobj
,
store
.
dialect
)
header
=
reader
.
next
()
# We seem to have match
if
len
(
header
)
!=
2
:
fileobj
.
close
()
return
store
fileobj
.
seek
(
0
)
return
storeclass
(
fileobj
,
[
'source'
,
'target'
])
FILE_FORMAT_CHOICES
=
[
FILE_FORMAT_CHOICES
=
[
(
fmt
,
FILE_FORMATS
[
fmt
].
name
)
for
fmt
in
sorted
(
FILE_FORMATS
)
(
fmt
,
FILE_FORMATS
[
fmt
].
name
)
for
fmt
in
sorted
(
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