def join_with_locale(self, alias, fallback=None):
        # This is all lifted from the real sql.compiler.get_from_clause(),
        # except for the extra AND clause.  Fun project: fix Django to use Q
        # objects here instead of a bunch of strings.
        qn = self.quote_name_unless_alias
        qn2 = self.connection.ops.quote_name
        mapping = self.query.alias_map[alias]
        # name, alias, join_type, lhs, lhs_col, col, nullable = mapping
        name, alias, join_type, lhs, join_cols, _, join_field = mapping
        lhs_col = join_field.column
        rhs_col = join_cols
        alias_str = '' if alias == name else (' %s' % alias)

        if isinstance(fallback, models.Field):
            fallback_str = '%s.%s' % (qn(self.query.model._meta.db_table),
                                      qn(fallback.column))
        else:
            fallback_str = '%s'

        return ('%s %s%s ON (%s.%s = %s.%s AND %s.%s = %s)' %
                (join_type, qn(name), alias_str,
                 qn(lhs), qn2(lhs_col), qn(alias), qn2(rhs_col),
                 qn(alias), qn('locale'), fallback_str))
dataset/ETHPy150Open mozilla/addons-server/src/olympia/translations/query.py/SQLCompiler.join_with_locale/original