'Write a translation CSV containing messages from streams.
Streams should be ordered by priority, from highest to lowest.
Any official translations (from the main database) are added automatically.'

def write_translations(self, lang, *streams):

    writer = self.writer_for_lang(lang)
    writer.writerow('language_id    table    id    column    source_crc    string'.split())
    messages = merge_translations(self.source, self.official_messages(lang), *streams)
    warnings = {}
    for (source, sourcehash, string, exact) in messages:
        if (string and (sourcehash != 'OFFICIAL')):
            utf8len = len(string.encode('utf-8'))
            if (source.colsize and (utf8len > source.colsize)):
                key = (source.cls, source.colname)
                warnings[key] = max(warnings.get(key, (0,)), (utf8len, source, string))
            else:
                writer.writerow((self.language_ids[lang], source.cls, source.id, source.colname, sourcehash, string.encode('utf-8')))
    for (utf8len, source, string) in warnings.values():
        template = u'Error:    {size}B    value    for    {colsize}B    column!    {key[0]}.{key[2]}:{key[1]}:    {string}'
        warning = template.format(key=source.merge_key, string=string, size=utf8len, colsize=source.colsize)
        if (len(warning) > 79):
            warning = (warning[:76] + u'...')
        print(warning)
