'Add possibly missing JOIN with translations table to ``query`` and
generate the expression for the translated field.
:return: the qualified field name (or expression) to use for ``field``'

@api.model
def _generate_translated_field(self, table_alias, field, query):

    if self.env.lang:
        unique_translation_subselect = '\n                                                                (SELECT    DISTINCT    ON    (res_id)    res_id,    value\n                                                                    FROM    "ir_translation"\n                                                                    WHERE    name=%s    AND    lang=%s    AND    value!=%s\n                                                                    ORDER    BY    res_id,    id    DESC)\n                                                '
        (alias, alias_statement) = query.add_join((table_alias, unique_translation_subselect, 'id', 'res_id', field), implicit=False, outer=True, extra_params=[('%s,%s' % (self._name, field)), self.env.lang, ''])
        return ('COALESCE("%s"."%s",    "%s"."%s")' % (alias, 'value', table_alias, field))
    else:
        return ('"%s"."%s"' % (table_alias, field))
