Skip to content

Commit 60cd3a3

Browse files
author
Nikos Vasileiou
authored
Merge pull request #103 from transifex/cds-delete-strings-tags
Delete translations, replace tags when pushing content
2 parents 056df76 + 9afdb0d commit 60cd3a3

5 files changed

Lines changed: 39 additions & 10 deletions

File tree

tests/native/core/test_core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,8 @@ def test_push_strings_reaches_cds_handler(
380380

381381
strings = [SourceString('a'), SourceString('b')]
382382
mytx = self._get_tx()
383-
mytx.push_source_strings(strings, False)
384-
mock_push_strings.assert_called_once_with(strings, False)
383+
mytx.push_source_strings(strings, False, True, True)
384+
mock_push_strings.assert_called_once_with(strings, False, True, True)
385385

386386
@patch('transifex.native.core.MemoryCache.update')
387387
@patch('transifex.native.core.CDSHandler.fetch_translations')

tests/native/django/test_commands/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ def get_transifex_command():
3030
'with_tags_only',
3131
'without_tags_only',
3232
'dry_run',
33+
'override_tags',
34+
'do_not_keep_translations',
3335
'symlinks',
3436

3537
# Invalidate

transifex/native/cds.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,20 @@ def fetch_translations(self, language_code=None):
202202

203203
return translations
204204

205-
def push_source_strings(self, strings, purge=False):
205+
def push_source_strings(self, strings, purge=False,
206+
do_not_keep_translations=False,
207+
override_tags=False):
206208
"""Push source strings to CDS.
207209
208210
:param list(SourceString) strings: a list of `SourceString` objects
209211
holding source strings
210212
:param bool purge: True deletes destination source content not included
211213
in pushed content. False appends the pushed content to destination
212214
source content.
215+
:param bool do_not_keep_translations: True deletes translations when the
216+
source strings of existing keys are updated. False preserves them.
217+
:param bool override_tags: True replaces all the tags of pushed strings.
218+
False appends them to existing tags.
213219
:return: the HTTP response object
214220
:rtype: requests.Response
215221
"""
@@ -228,7 +234,11 @@ def push_source_strings(self, strings, purge=False):
228234
headers=self._get_headers(use_secret=True),
229235
json={
230236
'data': data,
231-
'meta': {'purge': purge},
237+
'meta': {
238+
'purge': purge,
239+
'keep_translations': not do_not_keep_translations,
240+
'override_tags': override_tags,
241+
},
232242
}
233243
)
234244
response.raise_for_status()

transifex/native/core.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,20 +196,26 @@ def fetch_translations(self):
196196
self._check_initialization()
197197
self._cache.update(self._cds_handler.fetch_translations())
198198

199-
def push_source_strings(self, strings, purge=False):
199+
def push_source_strings(self, strings, purge=False,
200+
do_not_keep_translations=False,
201+
override_tags=False):
200202
"""Push the given source strings to the CDS.
201203
202204
:param list strings: a list of SourceString objects
203205
:param bool purge: True deletes destination source content not included
204-
in pushed content.
205-
False appends the pushed content to destination
206-
source content.
206+
in pushed content. False appends the pushed content to destination
207+
source content.
208+
:param bool do_not_keep_translations: True deletes translations when the
209+
source strings of existing keys are updated. False preserves them.
210+
:param bool override_tags: True replaces all the tags of pushed strings.
211+
False appends them to existing tags.
207212
:return: a tuple containing the status code and the content of the
208213
response
209214
:rtype: tuple
210215
"""
211216
self._check_initialization()
212-
response = self._cds_handler.push_source_strings(strings, purge)
217+
response = self._cds_handler.push_source_strings(
218+
strings, purge, do_not_keep_translations, override_tags)
213219
return response.status_code, json.loads(response.content)
214220

215221
def get_push_status(self, job_path):

transifex/native/django/management/utils/push.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ def add_arguments(self, subparsers):
6363
'--no-wait', action='store_true', dest='no_wait', default=False,
6464
help=('Disable polling for upload results'),
6565
)
66+
parser.add_argument(
67+
'--override-tags', action='store_true', dest='override_tags', default=False,
68+
help=('Override tags when pushing content'),
69+
)
70+
parser.add_argument(
71+
'--do-not-keep-translations', action='store_true', dest='do_not_keep_translations', default=False,
72+
help=('Remove translations when source strings change'),
73+
)
6674
parser.add_argument(
6775
'--verbose', '-v', action='store_true',
6876
dest='verbose_output', default=False,
@@ -90,6 +98,8 @@ def handle(self, *args, **options):
9098
self.with_tags_only = options['with_tags_only']
9199
self.without_tags_only = options['without_tags_only']
92100
self.dry_run = options['dry_run']
101+
self.override_tags = options['override_tags']
102+
self.do_not_keep_translations = options['do_not_keep_translations']
93103
self.no_wait = options['no_wait']
94104
self.key_generator = options['key_generator']
95105
extensions = options['extensions']
@@ -182,7 +192,8 @@ def push_strings(self):
182192
'to Transifex...'.format(total)
183193
)
184194
status_code, response_content = tx.push_source_strings(
185-
self.string_collection.strings.values(), self.purge
195+
self.string_collection.strings.values(), self.purge,
196+
self.do_not_keep_translations, self.override_tags
186197
)
187198

188199
if self.no_wait:

0 commit comments

Comments
 (0)