~chromium-team/chromium-browser/translations-pump

« back to all changes in this revision

Viewing changes to fileformats/gettext.py

  • Committer: Chad Miller
  • Date: 2013-08-16 14:10:56 UTC
  • Revision ID: chad.miller@canonical.com-20130816141056-v51xndsustwcjg6i
Fix exporting gettext placeholders.

Move testing to top of main run function.

Make getting upstream sources a seperate step than running the exporter.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
 
4
4
from io import StringIO
5
 
 
 
5
import re
 
6
import logging
6
7
 
7
8
def gettext_file_sorting_function(item):
8
9
    r"""Used to sort .items of txln_info pairs so gettext output files are
25
26
    string literals are concatenated together. We cater to that by making each
26
27
    line into a "-delimited line with the newline encoded into the string.
27
28
 
28
 
    >>> f = StringIO(); grd_msg_write_in_po("asdf", "123\n456", f).getvalue()
29
 
    'asdf ""\n"123\\n"\n"456"\n'
 
29
    >>> f = StringIO(); grd_msg_write_in_po("asdf", "12<ph name=\"AB\" />3\n4<ph name=\"C\"/>56", f).getvalue()
 
30
    'asdf ""\n"12%{AB}3\\n"\n"4%{C}56"\n'
30
31
    """
 
32
 
 
33
    if "%{" in text:
 
34
        logging.warn("Text from GRD, %r, looks like it has percent-openbrace already, which would be confusing later.", text)
 
35
 
 
36
    text = re.sub(r'<ph\s+name="([^"]+)"\s*/>', r"%{\1}", text)
31
37
    outfile.write('{0} ""\n'.format(header))
32
38
    outfile.write('"' + '\\n"\n"'.join(line.replace("\\", "\\\\") for line in text.split("\n")) + '"\n')
33
39