diff options
author | László Németh <nemeth@numbertext.org> | 2014-02-04 19:56:57 +0100 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2014-02-04 22:04:02 +0100 |
commit | 3e6969d8a26c443bf5729eab640de92aa95ec4ee (patch) | |
tree | a3293f9e7ccfaab0cc571f5a024fec7e219073f3 /librelogo | |
parent | a831930986166a8c5cb231821426f5cf4d976df2 (diff) |
librelogo: keep comments at translation
Bug report: http://openscope.org/browse/OOO-837
Change-Id: I5c17ed6059107ec8fc12bf9f411e52b22f131065
Diffstat (limited to 'librelogo')
-rw-r--r-- | librelogo/source/LibreLogo/LibreLogo.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/librelogo/source/LibreLogo/LibreLogo.py b/librelogo/source/LibreLogo/LibreLogo.py index 8fc0c0c6218c..c1a35b1f9dbd 100644 --- a/librelogo/source/LibreLogo/LibreLogo.py +++ b/librelogo/source/LibreLogo/LibreLogo.py @@ -56,7 +56,9 @@ __MM10_TO_TWIP__ = 1/(2540.0/72/20) # 0.01 mm to twentieth point __FILLCOLOR__ = 0x8000cc00 __LINEWIDTH__ = 0.5 * __PT_TO_TWIP__ __ENCODED_STRING__ = "_s_%s___" +__ENCODED_COMMENT__ = "_c_%s___" __DECODE_STRING_REGEX__ = "_s_([0-9]+)___" +__DECODE_COMMENT_REGEX__ = "_c_([0-9]+)___" __LINEBREAK__ = "#_@L_i_N_e@_#" __TURTLE__ = "turtle" __ACTUAL__ = "actual" @@ -345,8 +347,10 @@ def __translate__(arg = None): rq = '\'' + lang['RIGHTSTRING'].replace("|", "") __strings__ = [] + text = re.sub(r"^(([ \t]*[;#][^\n]*))", __encodecomment__, text) text = re.sub("(?u)([%s])([^\n%s]*)(?<!\\\\)[%s]" % (lq, rq, rq), __encodestring__, selection.getString()) text = re.sub('(?u)(?<![0-9])(")(~?\w*)', __encodestring__, text) + text = re.sub(r";(([^\n]*))", __encodecomment__, text) # translate the program to the language of the document FIXME space/tab exception = ['DECIMAL'] @@ -364,11 +368,12 @@ def __translate__(arg = None): text = re.sub(r'(?ui)(?<!:)\b(%s)\b' % lang[i], __l12n__(_.lng)[i].split("|")[0].upper(), text) text = re.sub(r"(?<=\d)[%s](?=\d)" % lang['DECIMAL'], __l12n__(_.lng)['DECIMAL'], text) - # decode strings + # decode strings and comments quoted = u"(?ui)(?<=%s)(%%s)(?=%s)" % (__l12n__(_.lng)['LEFTSTRING'][0], __l12n__(_.lng)['RIGHTSTRING'][0]) text = re.sub(__DECODE_STRING_REGEX__, __decodestring2__, text) for i in __STRCONST__: text = re.sub(quoted % lang[i], __l12n__(_.lng)[i].split("|")[0].upper(), text) + text = re.sub(__DECODE_COMMENT_REGEX__, __decodecomment__, text) selection.setString(text) # convert to paragraphs __dispatcher__(".uno:ExecuteSearch", (__getprop__("SearchItem.SearchString", r"\n"), __getprop__("SearchItem.ReplaceString", r"\n"), \ @@ -438,12 +443,19 @@ def __encodestring__(m): __strings__.append(re.sub("\\[^\\]", "", m.group(2))) return __ENCODED_STRING__ % (len(__strings__) - 1) +def __encodecomment__(m): + __strings__.append(re.sub("\\[^\\]", "", m.group(2))) + return __ENCODED_COMMENT__ % (len(__strings__) - 1) + def __decodestring__(m): return "u'%s'" % __strings__[int(m.group(1))] def __decodestring2__(m): return __l12n__(_.lng)['LEFTSTRING'][0] + __strings__[int(m.group(1))] + __l12n__(_.lng)['RIGHTSTRING'][0] +def __decodecomment__(m): + return ";" + __strings__[int(m.group(1))] + def __initialize__(): global __halt__, __thread__ __getdocument__() |