Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Figure out how to streamline merging translations from Crowdin #1724

Open
toolness opened this issue Oct 19, 2020 · 0 comments
Open

Figure out how to streamline merging translations from Crowdin #1724

toolness opened this issue Oct 19, 2020 · 0 comments
Labels
code snippet Temporary code that we only need to run once and don't need to merge for long-term use.

Comments

@toolness
Copy link
Collaborator

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.

@toolness toolness added the code snippet Temporary code that we only need to run once and don't need to merge for long-term use. label Oct 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code snippet Temporary code that we only need to run once and don't need to merge for long-term use.
Projects
None yet
Development

No branches or pull requests

1 participant