common/i18n.py
changeset 3293 69c0ba095536
parent 3230 1d25e928c299
parent 3275 5247789df541
child 3369 7b88d12b4ee2
equal deleted inserted replaced
3230:1d25e928c299 3293:69c0ba095536
    24         for match in re.finditer('i18n:(content|replace)="([^"]+)"', open(filepath).read()):
    24         for match in re.finditer('i18n:(content|replace)="([^"]+)"', open(filepath).read()):
    25             print >> output, '_("%s")' % match.group(2)
    25             print >> output, '_("%s")' % match.group(2)
    26     output.close()
    26     output.close()
    27 
    27 
    28 
    28 
    29 def add_msg(w, msgid):
    29 def add_msg(w, msgid, msgctx=None):
    30     """write an empty pot msgid definition"""
    30     """write an empty pot msgid definition"""
    31     if isinstance(msgid, unicode):
    31     if isinstance(msgid, unicode):
    32         msgid = msgid.encode('utf-8')
    32         msgid = msgid.encode('utf-8')
       
    33     if msgctx:
       
    34         if isinstance(msgctx, unicode):
       
    35             msgctx = msgctx.encode('utf-8')
       
    36         w('msgctxt "%s"\n' % msgctx)
    33     msgid = msgid.replace('"', r'\"').splitlines()
    37     msgid = msgid.replace('"', r'\"').splitlines()
    34     if len(msgid) > 1:
    38     if len(msgid) > 1:
    35         w('msgid ""\n')
    39         w('msgid ""\n')
    36         for line in msgid:
    40         for line in msgid:
    37             w('"%s"' % line.replace('"', r'\"'))
    41             w('"%s"' % line.replace('"', r'\"'))