diff --git a/base/templatetags/seahub_tags.py b/base/templatetags/seahub_tags.py index d3165c7529..cf632e2d3e 100644 --- a/base/templatetags/seahub_tags.py +++ b/base/templatetags/seahub_tags.py @@ -32,16 +32,41 @@ def file_icon_filter(value): else: return FILEEXT_ICON_MAP.get('default') -def desc_repl(matchobj): - if TRANSLATION_MAP.has_key(matchobj.group(0)): - return TRANSLATION_MAP.get(matchobj.group(0)) - @register.filter(name='translate_commit_desc') def translate_commit_desc(value): - reg = '|'.join(TRANSLATION_MAP.keys()) + """Translate commit description.""" + if value.startswith('Reverted'): + return value.replace('Reverted repo to status at', u'同步目录内容还原到') + elif value.startswith('Merged'): + return u'合并了其他人的修改' + else: + operations = '|'.join(TRANSLATION_MAP.keys()) + patt = r'(%s) "(.*)"\s?(and ([0-9]+) more files)?' % operations - return re.sub(reg, desc_repl, value) + ret_list = [] + for e in value.split('.\n'): + if not e: + continue + m = re.match(patt, e) + if not m: + ret_list.append(e) + continue + + op = m.group(1) + op_trans = TRANSLATION_MAP.get(op) + file_name = m.group(2) + more_files = m.group(3) + n_files = m.group(4) + + if not more_files: + ret = op_trans + u' "' + file_name + u'".' + else: + ret = op_trans + u' "' + file_name + u'"以及另外' + n_files + u'个文件.' + ret_list.append(ret) + + return ' '.join(ret_list) + @register.filter(name='translate_commit_time') def translate_commit_time(value): """Translate commit time to human frindly format instead of timestamp""" diff --git a/po.py b/po.py index 8109c694e7..a41f2db7ee 100644 --- a/po.py +++ b/po.py @@ -6,11 +6,6 @@ TRANSLATION_MAP = { 'Deleted' : u'删除了', 'Modified' : u'修改了', 'Renamed' : u'重命名或移动了', - 'and' : u'以及另外', - 'more files' : u'个文件', - 'Reverted repo to status at' : u'同步目录内容还原到', - 'Merged ' : u'合并了', - '\'s changes' : u' 的修改', - 'other' : u'其他人', - 'Merged others\' changes' : u'合并了其他人的修改', + 'Added directory' : u'新建了目录', + 'Removed directory' : u'删除了目录', }