cubicweb/i18n.py
changeset 12567 26744ad37953
parent 11767 432f87a63057
equal deleted inserted replaced
12566:6b3523f81f42 12567:26744ad37953
    14 # details.
    14 # details.
    15 #
    15 #
    16 # You should have received a copy of the GNU Lesser General Public License along
    16 # You should have received a copy of the GNU Lesser General Public License along
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    18 """Some i18n/gettext utilities."""
    18 """Some i18n/gettext utilities."""
    19 from __future__ import print_function
       
    20 
       
    21 
       
    22 
       
    23 import re
    19 import re
    24 import os
    20 import os
    25 from os.path import join, basename, splitext, exists
    21 from os.path import join, basename, splitext, exists
    26 from glob import glob
    22 from glob import glob
    27 
       
    28 from six import PY2
       
    29 
    23 
    30 from cubicweb.toolsutils import create_dir
    24 from cubicweb.toolsutils import create_dir
    31 
    25 
    32 def extract_from_tal(files, output_file):
    26 def extract_from_tal(files, output_file):
    33     """extract i18n strings from tal and write them into the given output file
    27     """extract i18n strings from tal and write them into the given output file
    40     output.close()
    34     output.close()
    41 
    35 
    42 
    36 
    43 def add_msg(w, msgid, msgctx=None):
    37 def add_msg(w, msgid, msgctx=None):
    44     """write an empty pot msgid definition"""
    38     """write an empty pot msgid definition"""
    45     if PY2 and isinstance(msgid, unicode):
       
    46         msgid = msgid.encode('utf-8')
       
    47     if msgctx:
    39     if msgctx:
    48         if PY2 and isinstance(msgctx, unicode):
       
    49             msgctx = msgctx.encode('utf-8')
       
    50         w('msgctxt "%s"\n' % msgctx)
    40         w('msgctxt "%s"\n' % msgctx)
    51     msgid = msgid.replace('"', r'\"').splitlines()
    41     msgid = msgid.replace('"', r'\"').splitlines()
    52     if len(msgid) > 1:
    42     if len(msgid) > 1:
    53         w('msgid ""\n')
    43         w('msgid ""\n')
    54         for line in msgid:
    44         for line in msgid: