@transaction.atomic
    def handle_project_locale(self, project, locale):
        # Match locale code inconsistencies
        pootle_locale = locale.replace('-', '_')
        if pootle_locale == 'ga_IE':
            pootle_locale = 'ga'

        # Match project slug inconsistencies
        pootle_project = {
            'amo': 'amo',
            'find-my-device': 'findmydevice',
            'firefox-accounts': 'accounts',
            'firefox-accounts-payments': 'payments',
            'firefox-hello': 'loop',
            'firefox-input': 'input',
            'marketplace': 'marketplace',
            'marketplace-commbadge': 'commbadge',
            'marketplace-fireplace': 'fireplace',
            'marketplace-spartacus': 'spartacus',
            'marketplace-stats': 'marketplace_stats',
            'marketplace-zippy': 'zippy',
            'master-firefox-os': 'masterfirefoxos',
            'mdn': 'mdn',
            'mozillians': 'mozillians',
            'social-api-directory': 'socialapi-directory',
            'sumo': 'sumo',
        }.get(project)

        if not pootle_project:
            return

        # Get Pootle data
        filename = pootle_locale + '_' + pootle_project + '.json'
        url = 'http://svn.mozilla.org/projects/l10n-misc/trunk/pontoon/verbatim/' + filename

        try:
            pootle = requests.get(url).json()
        except __HOLE__:
            return self.stdout.write("--- Skipping missing file {}.".format(filename))

        # Get all Pontoon translations matching Pootle data
        paths = pootle.keys()
        entities = []
        strings = []
        emails = []

        for path in paths:
            for entity in pootle[path].keys():
                entities.append(entity)
                strings.append(pootle[path][entity]["translation"])
                emails.append(pootle[path][entity]["author"])

        translations = Translation.objects.filter(
            entity__resource__project__slug=project,
            entity__resource__path__in=paths,
            entity__string__in=entities,
            locale__code=locale,
            user=None,
            string__in=strings
        )

        # Save user permissions and create dict to avoid hitting the DB later
        users_dict = {}
        users = User.objects.filter(email__in=emails)
        missing_users_list = []
        locale_translators_map = dict(Locale.objects.values_list('code', 'translators_group'))
        for u in users:
            users_dict[u.email] = u

            if 'base.can_translate_locale' not in u.get_all_permissions():
                u.groups.add(locale_translators_map[locale])
                self.stdout.write("Permission granted to user {} to locale: {}.".format(u.email, locale))

        if users:
            bulk_update(users)

        for t in translations:
            try:
                pootle_translation = pootle[t.entity.resource.path][t.entity.string]
            # Path - entity mismatch, skip to next translation
            except KeyError:
                continue

            # Save user
            email = pootle_translation["author"]
            user = users_dict.get(email)

            if not user:
                missing_users_list.append(email)

            t.user = user
            t.approved_user = user

            # Save date
            date = pootle_translation["date"].split("+")[0]
            dateObj = timezone.make_aware(datetime.strptime(date, "%Y-%m-%d %H:%M:%S"))
            t.date = dateObj
            t.approved_date = dateObj

        if translations:
            bulk_update(translations)

        missing_users = Counter(missing_users_list)
        for missing_user in missing_users.keys():
            self.stdout.write("Pontoon user {} not found: {} translations.".format(missing_user, missing_users[missing_user]))

        self.stdout.write("+++ Imported data from file {}.".format(filename))
dataset/ETHPy150Open mozilla/pontoon/pontoon/sync/management/commands/import_pootle.py/Command.handle_project_locale