diff options
| author | P. Christeas <p_christ@hol.gr> | 2010-12-29 13:33:06 +0200 |
|---|---|---|
| committer | P. Christeas <p_christ@hol.gr> | 2010-12-29 13:33:06 +0200 |
| commit | b0e2c850651b476108b287a1126d63be29ffe5fd (patch) | |
| tree | 6eb39cc0a777a482494dbd8a2888a9b3ee856a21 /bin/tools | |
| parent | 263b4524fbf33189d7bed85757863b8c80e3685c (diff) | |
translate: implement a counter to export the code line number
Before this, all code sources were like "#: code:foo/bar.py:0", now
they will have line no like "#: code:foo/bar.py:123".
Note that the gettext() wouldn't be affected, since it doesn't consult
the file name or line so far.
bzr revid: p_christ@hol.gr-20101229113306-vo3gflwunq2f75qm
Diffstat (limited to 'bin/tools')
| -rw-r--r-- | bin/tools/translate.py | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/bin/tools/translate.py b/bin/tools/translate.py index 47cd24cfd16..8cf09f96fef 100644 --- a/bin/tools/translate.py +++ b/bin/tools/translate.py @@ -772,6 +772,8 @@ def trans_generate(lang, modules, dbname=None): if module in installed_modules: frelativepath = str("addons" + frelativepath) ite = re_dquotes.finditer(code_string) + code_offset = 0 + code_line = 1 for i in ite: src = i.group(1) if src.startswith('""'): @@ -779,11 +781,18 @@ def trans_generate(lang, modules, dbname=None): src = src[2:-2] else: src = join_dquotes.sub(r'\1', src) + # try to count the lines from the last pos to our place: + code_line += code_string[code_offset:i.start(1)].count('\n') # now, since we did a binary read of a python source file, we # have to expand pythonic escapes like the interpreter does. src = src.decode('string_escape') - push_translation(module, terms_type, frelativepath, 0, encode(src)) + push_translation(module, terms_type, frelativepath, code_line, encode(src)) + code_line += i.group(1).count('\n') + code_offset = i.end() # we have counted newlines up to the match end + ite = re_quotes.finditer(code_string) + code_offset = 0 #reset counters + code_line = 1 for i in ite: src = i.group(1) if src.startswith("''"): @@ -791,8 +800,11 @@ def trans_generate(lang, modules, dbname=None): src = src[2:-2] else: src = join_quotes.sub(r'\1', src) + code_line += code_string[code_offset:i.start(1)].count('\n') src = src.decode('string_escape') - push_translation(module, terms_type, frelativepath, 0, encode(src)) + push_translation(module, terms_type, frelativepath, code_line, encode(src)) + code_line += i.group(1).count('\n') + code_offset = i.end() # we have counted newlines up to the match end for path in path_list: logger.debug("Scanning files of modules at %s", path) |
