def csv_to_po(trans_csv_path, meta_csv_path, locale_root,
              po_files_path, header=None):
    """
    Converts GDocs spreadsheet generated csv file into po file.
    :param trans_csv_path: path to temporary file with translations
    :param meta_csv_path: path to temporary file with meta information
    :param locale_root: path to locale root folder containing directories
                        with languages
    :param po_files_path: path from lang directory to po file
    """
    pattern = "^\w+.*po$"
    for root, dirs, files in os.walk(locale_root):
        for f in filter(lambda x: re.match(pattern, x), files):
            os.remove(os.path.join(root, f))

    # read title row and prepare descriptors for po files in each lang
    trans_reader = UnicodeReader(trans_csv_path)
    meta_reader = UnicodeReader(meta_csv_path)
    try:
        title_row = trans_reader.next()
    except StopIteration:
        # empty file
        return

    trans_languages = _prepare_locale_dirs(title_row[3:], locale_root)

    po_files = {}

    meta_reader.next()
    # go through every row in downloaded csv file
    for trans_row, meta_row in izip_longest(trans_reader, meta_reader):
        filename = trans_row[0].rstrip()
        metadata = meta_row[0].rstrip() if meta_row else METADATA_EMPTY
        comment = trans_row[1]
        msgid = trans_row[2]

        if filename not in po_files:
            _prepare_polib_files(po_files, filename, trans_languages,
                                 locale_root, po_files_path, header)

        _write_entries(po_files[filename], trans_languages, msgid,
                       trans_row[3:], metadata, comment)
    for filename in po_files:
        for lang in po_files[filename]:
            po_files[filename][lang].save()

    trans_reader.close()
    meta_reader.close()
def csv_to_po(trans_csv_path, meta_csv_path, locale_root,
              po_files_path, header=None):
    """
    Converts GDocs spreadsheet generated csv file into po file.
    :param trans_csv_path: path to temporary file with translations
    :param meta_csv_path: path to temporary file with meta information
    :param locale_root: path to locale root folder containing directories
                        with languages
    :param po_files_path: path from lang directory to po file
    """
    pattern = "^\w+.*po$"
    for root, dirs, files in os.walk(locale_root):
        for f in filter(lambda x: re.match(pattern, x), files):
            os.remove(os.path.join(root, f))

    # read title row and prepare descriptors for po files in each lang
    trans_reader = UnicodeReader(trans_csv_path)
    meta_reader = UnicodeReader(meta_csv_path)
    try:
        title_row = trans_reader.next()
    except StopIteration:
        # empty file
        return

    trans_languages = _prepare_locale_dirs(title_row[3:], locale_root)

    po_files = {}

    meta_reader.next()
    # go through every row in downloaded csv file
    for trans_row, meta_row in izip_longest(trans_reader, meta_reader):
        filename = trans_row[0].rstrip()
        metadata = meta_row[0].rstrip() if meta_row else METADATA_EMPTY
        comment = trans_row[1]
        msgid = trans_row[2]

        if filename not in po_files:
            _prepare_polib_files(po_files, filename, trans_languages,
                                 locale_root, po_files_path, header)

        _write_entries(po_files[filename], trans_languages, msgid,
                       trans_row[3:], metadata, comment)
    for filename in po_files:
        for lang in po_files[filename]:
            po_files[filename][lang].save()

    trans_reader.close()
    meta_reader.close()
def csv_to_po ( trans_csv_path , meta_csv_path , locale_root , po_files_path , header = None ) : pattern = "^\w+.*po$" for root , dirs , files in os . walk ( locale_root ) : for f in filter ( lambda x : re . match ( pattern , x ) , files ) : os . remove ( os . path . join ( root , f ) ) # read title row and prepare descriptors for po files in each lang trans_reader = UnicodeReader ( trans_csv_path ) meta_reader = UnicodeReader ( meta_csv_path ) try : title_row = trans_reader . next ( ) except StopIteration : # empty file return trans_languages = _prepare_locale_dirs ( title_row [ 3 : ] , locale_root ) po_files = { } meta_reader . next ( ) # go through every row in downloaded csv file for trans_row , meta_row in izip_longest ( trans_reader , meta_reader ) : filename = trans_row [ 0 ] . rstrip ( ) metadata = meta_row [ 0 ] . rstrip ( ) if meta_row else METADATA_EMPTY comment = trans_row [ 1 ] msgid = trans_row [ 2 ] if filename not in po_files : _prepare_polib_files ( po_files , filename , trans_languages , locale_root , po_files_path , header ) _write_entries ( po_files [ filename ] , trans_languages , msgid , trans_row [ 3 : ] , metadata , comment ) for filename in po_files : for lang in po_files [ filename ] : po_files [ filename ] [ lang ] . save ( ) trans_reader . close ( ) meta_reader . close ( )
Converts GDocs spreadsheet generated csv file into po file.
    :param trans_csv_path: path to temporary file with translations
    :param meta_csv_path: path to temporary file with meta information
    :param locale_root: path to locale root folder containing directories
                        with languages
    :param po_files_path: path from lang directory to po file
Converts GDocs spreadsheet generated csv file into po file . : param trans_csv_path : path to temporary file with translations : param meta_csv_path : path to temporary file with meta information : param locale_root : path to locale root folder containing directories with languages : param po_files_path : path from lang directory to po file