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
ae9adeca
Commit
ae9adeca
authored
8 years ago
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add script to remove obsolete units from Android resource strings.
Fixes #113 Signed-off-by:
Michal Čihař
<
michal@cihar.com
>
parent
779bcc87
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
80 additions
and
0 deletions
+80
-0
docs/admin/config.rst
docs/admin/config.rst
+3
-0
examples/hook-cleanup-android
examples/hook-cleanup-android
+77
-0
No files found.
docs/admin/config.rst
View file @
ae9adeca
...
...
@@ -550,6 +550,9 @@ Weblate comes with few example hook scripts which you might find useful:
Updates resx file to match template by adding new translations and removing
obsolete ones.
:file:`examples/hook-cleanup-android`
Removes obsolete units from Android resource strings.
.. seealso::
:ref:`processing`
...
...
This diff is collapsed.
Click to expand it.
examples/hook-cleanup-android
0 → 100755
View file @
ae9adeca
#! /usr/bin/env python
"""
Post update hook script to update message IDs in the Android strings file.
"""
from
__future__
import
print_function
import
glob
import
os
import
subprocess
import
sys
from
translate.storage.aresource
import
AndroidResourceFile
def
build_index
(
storage
):
index
=
{}
for
unit
in
storage
.
units
:
index
[
unit
.
getid
()]
=
unit
return
index
def
update_file
(
template
,
index
,
filename
):
storage
=
AndroidResourceFile
.
parsefile
(
filename
)
changed
=
False
# Remove extra units
for
unit
in
storage
.
units
:
if
unit
.
getid
()
not
in
index
:
storage
.
body
.
remove
(
unit
.
xmlelement
)
changed
=
True
if
changed
:
storage
.
save
()
def
main
():
if
os
.
environ
.
get
(
'WL_FILE_FORMAT'
)
!=
'aresource'
:
print
(
'Invalid file format!'
)
sys
.
exit
(
1
)
if
not
os
.
environ
.
get
(
'WL_TEMPLATE'
):
print
(
'Missing template!'
)
sys
.
exit
(
1
)
if
not
os
.
environ
.
get
(
'WL_FILEMASK'
):
print
(
'Missing filemask!'
)
sys
.
exit
(
1
)
if
not
os
.
environ
.
get
(
'WL_PATH'
):
print
(
'Missing path!'
)
sys
.
exit
(
1
)
os
.
chdir
(
os
.
environ
.
get
(
'WL_PATH'
))
templatename
=
os
.
environ
.
get
(
'WL_TEMPLATE'
)
template
=
AndroidResourceFile
.
parsefile
(
templatename
)
index
=
build_index
(
template
)
for
filename
in
glob
.
glob
(
os
.
environ
.
get
(
'WL_FILEMASK'
)):
if
filename
!=
templatename
:
update_file
(
template
,
index
,
filename
)
if
subprocess
.
call
([
'git'
,
'commit'
,
'--dry-run'
,
'-a'
])
==
0
:
ret
=
subprocess
.
call
(
[
'git'
,
'commit'
,
'-a'
,
'-m'
,
'Updated translation files'
]
)
if
ret
==
0
:
ret
=
subprocess
.
call
([
'git'
,
'push'
])
sys
.
exit
(
ret
)
if
__name__
==
'__main__'
:
main
()
This diff is collapsed.
Click to expand it.
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