Skip to content

Commit

Permalink
feat: bulk_update translation and reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
OmarIthawi committed Jan 9, 2025
1 parent c2d24e9 commit 82dc946
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
2 changes: 2 additions & 0 deletions scripts/fix_transifex_resource_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
- "b8933764bdb3063ca09d6aa20341102f"
This script updates slugs to be like names.
Transifex Python API docs: https://github.com/transifex/transifex-python/blob/devel/transifex/api/README.md
"""

import configparser
Expand Down
32 changes: 22 additions & 10 deletions scripts/release_project_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- main_translation: translation in the main "open-edx/openedx-translations" project
- release_translation: translation in the release project "open-edx/openedx-translations-<release-name>"
Python API docs: https://github.com/transifex/transifex-python/blob/devel/transifex/api/README.md
"""

import argparse
Expand Down Expand Up @@ -107,24 +108,36 @@ def sync_translations(self, lang_id, main_resource, release_resource):
for translation in self.get_translations(lang_id=lang_id, resource=main_resource)
}

updates_to_apply = []
for release_translation in self.get_translations(lang_id=lang_id, resource=release_resource):
translation_id = self.get_translation_id(release_translation)
if translation_from_main_project := translations_from_main_project.get(translation_id):
self.sync_translation_entry(
status, updates = self.sync_translation_entry(
translation_from_main_project=translation_from_main_project,
release_translation=release_translation,
)
if updates and status == 'update':
updates_to_apply.append({
'id': release_translation.id,
'attributes': updates,
})

if updates_to_apply and not self.is_dry_run():
self.tx_api.ResourceTranslation.bulk_update(updates_to_apply)

print(' finished', lang_id)

def sync_translation_entry(self, translation_from_main_project, release_translation):
"""
Sync translation review from the main project to the release one.
Return:
str: status code
- updated: if the entry was updated
- no-op: if the entry don't need any updates
- updated-dry-run: if the entry was updated in dry-run mode
tuple: status code, updates
- status code:
- updated: if the entry was updated
- no-op: if the entry don't need any updates
- updated-dry-run: if the entry was updated in dry-run mode
- updates: dict of updates to be applied to the release translation
"""
translation_id = self.get_translation_id(release_translation)

Expand All @@ -139,17 +152,16 @@ def sync_translation_entry(self, translation_from_main_project, release_translat
updates[attr] = main_attr_value
else:
print(translation_id, 'has different translations will not update it')
return 'no-op'
return 'no-op', updates

if updates:
print(translation_id, updates, '[Dry run]' if self.is_dry_run() else '')
if self.is_dry_run():
return 'updated-dry-run'
return 'update-dry-run', updates
else:
release_translation.save(**updates)
return 'updated'
return 'update', updates

return 'no-op'
return 'no-op', updates

def sync_tags(self, main_resource, release_resource):
"""
Expand Down

0 comments on commit 82dc946

Please sign in to comment.