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
941aa974
Commit
941aa974
authored
Feb 27, 2012
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Actual parsing of po files and loading to database
parent
b68fd172
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
7 deletions
+43
-7
trans/managers.py
trans/managers.py
+13
-0
trans/models.py
trans/models.py
+30
-7
No files found.
trans/managers.py
View file @
941aa974
...
...
@@ -14,3 +14,16 @@ class TranslationManager(models.Manager):
filename
=
path
)
trans
.
update_from_blob
(
blob
)
class
UnitManager
(
models
.
Manager
):
def
update_from_unit
(
self
,
translation
,
unit
):
'''
Process translation toolkit unit and stores/updates database entry.
'''
src
=
'
\
x00
\
x00
'
.
join
(
unit
.
source
.
strings
)
ctx
=
unit
.
getcontext
()
dbunit
,
created
=
self
.
get_or_create
(
translation
=
translation
,
source
=
src
,
context
=
ctx
)
dbunit
.
update_from_unit
(
unit
)
return
dbunit
trans/models.py
View file @
941aa974
...
...
@@ -7,7 +7,7 @@ import os.path
import
git
from
translate.storage
import
factory
from
trans.managers
import
TranslationManager
from
trans.managers
import
TranslationManager
,
UnitManager
PLURAL_SEPARATOR
=
'
\
x00
\
x00
'
...
...
@@ -175,20 +175,43 @@ class Translation(models.Model):
# Load po file
store
=
factory
.
getobject
(
os
.
path
.
join
(
self
.
subproject
.
get_path
(),
self
.
filename
))
for
unit
in
store
.
units
:
print
unit
newunit
=
Unit
.
objects
.
update_from_unit
(
self
,
unit
)
try
:
oldunits
.
remove
(
newunit
.
id
)
except
:
pass
# Delete not used units
Unit
.
objects
.
filter
(
translation
=
self
,
id__in
=
oldunits
).
delete
()
# Update revision
self
.
revision
=
blob
.
hexsha
#
self.save()
self
.
save
()
class
Unit
(
models
.
Model
):
translation
=
models
.
ForeignKey
(
Translation
)
location
=
models
.
TextField
()
context
=
models
.
TextField
()
flags
=
models
.
TextField
()
location
=
models
.
TextField
(
default
=
''
,
blank
=
True
)
context
=
models
.
TextField
(
default
=
''
,
blank
=
True
)
flags
=
models
.
TextField
(
default
=
''
,
blank
=
True
)
source
=
models
.
TextField
()
target
=
models
.
TextField
()
target
=
models
.
TextField
(
default
=
''
,
blank
=
True
)
fuzzy
=
models
.
BooleanField
(
default
=
False
)
objects
=
UnitManager
()
def
update_from_unit
(
self
,
unit
):
location
=
', '
.
join
(
unit
.
getlocations
())
flags
=
''
# FIXME
target
=
PLURAL_SEPARATOR
.
join
(
unit
.
target
.
strings
)
fuzzy
=
unit
.
isfuzzy
()
if
location
==
self
.
location
and
flags
==
self
.
flags
and
target
==
self
.
target
and
fuzzy
==
self
.
fuzzy
:
return
self
.
location
=
location
self
.
flags
=
flags
self
.
target
=
target
self
.
fuzzy
=
fuzzy
self
.
save
()
def
is_plural
(
self
):
return
self
.
source
.
find
(
PLURAL_SEPARATOR
)
!=
-
1
...
...
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