tenants2
tenants2 copied to clipboard
Figure out how to streamline merging translations from Crowdin
I'm noticing that crowdin regularly somehow has its l10n_master
have merge conflicts with our master
branch. This requires some git gymnastics to resolve, since we want to merge but have all the PO files from 10n_master
"win" in the merge.
The following Python script essentially automates this process:
import sys
import subprocess
MASTER = 'master'
L10N_MASTER = 'l10n_master'
LOCALES_DIR = 'locales/**/*.po'
def git(*args: str, ignore_errors: bool = False, expect_errors: bool = False):
if expect_errors:
ignore_errors = True
cmdline = ['git', *args]
print(f"Running \"{' '.join(cmdline)}\".")
retval = subprocess.call(cmdline)
if retval:
if ignore_errors:
if not expect_errors:
print(f"git exited abnormally, but ignoring errors.")
else:
print(f"git returned exit code {retval}, exiting.")
sys.exit(retval)
elif expect_errors:
print(f"Expected git to exit abnormally but it didn't!")
sys.exit(1)
if __name__ == '__main__':
git('checkout', MASTER)
git('pull')
print()
print(f"Deleting existing {L10N_MASTER} branch if it exists.")
git('branch', '-D', L10N_MASTER, ignore_errors=True)
print()
print(f"Checking out latest {L10N_MASTER} and merging {MASTER} into")
print(f"it, keeping files in {LOCALES_DIR} from {L10N_MASTER}.")
git('checkout', L10N_MASTER)
git('merge', MASTER, expect_errors=True)
git('checkout', '--ours', LOCALES_DIR)
git('add', LOCALES_DIR)
git('commit', '-m', f"Merge into {MASTER}.")
print()
print(f"Done. Run 'git push' to push the merged {L10N_MASTER}.")
But I'm not sure if regularly running this script is the best option, or if there's something far simpler that I'm somehow missing.