i18n.py
changeset 10776 b1834143fec8
parent 10589 7c23b7de2b8d
equal deleted inserted replaced
10775:4b3c1069bd4e 10776:b1834143fec8
    23 import re
    23 import re
    24 import os
    24 import os
    25 from os.path import join, basename, splitext, exists
    25 from os.path import join, basename, splitext, exists
    26 from glob import glob
    26 from glob import glob
    27 
    27 
       
    28 from six import PY2
       
    29 
    28 from cubicweb.toolsutils import create_dir
    30 from cubicweb.toolsutils import create_dir
    29 
    31 
    30 def extract_from_tal(files, output_file):
    32 def extract_from_tal(files, output_file):
    31     """extract i18n strings from tal and write them into the given output file
    33     """extract i18n strings from tal and write them into the given output file
    32     using standard python gettext marker (_)
    34     using standard python gettext marker (_)
    38     output.close()
    40     output.close()
    39 
    41 
    40 
    42 
    41 def add_msg(w, msgid, msgctx=None):
    43 def add_msg(w, msgid, msgctx=None):
    42     """write an empty pot msgid definition"""
    44     """write an empty pot msgid definition"""
    43     if isinstance(msgid, unicode):
    45     if PY2 and isinstance(msgid, unicode):
    44         msgid = msgid.encode('utf-8')
    46         msgid = msgid.encode('utf-8')
    45     if msgctx:
    47     if msgctx:
    46         if isinstance(msgctx, unicode):
    48         if PY2 and isinstance(msgctx, unicode):
    47             msgctx = msgctx.encode('utf-8')
    49             msgctx = msgctx.encode('utf-8')
    48         w('msgctxt "%s"\n' % msgctx)
    50         w('msgctxt "%s"\n' % msgctx)
    49     msgid = msgid.replace('"', r'\"').splitlines()
    51     msgid = msgid.replace('"', r'\"').splitlines()
    50     if len(msgid) > 1:
    52     if len(msgid) > 1:
    51         w('msgid ""\n')
    53         w('msgid ""\n')