Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Unified Diff: tools/grit/grit/node/message.py

Issue 2177963002: Reland of grit: Automatically replace ... with … (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebaseline Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/grit/grit/node/message.py
diff --git a/tools/grit/grit/node/message.py b/tools/grit/grit/node/message.py
index 48cd1c79519bfe87a294eef03074b10526341ac5..e3024fb9530bc2d0e6dee8777c68d812fec53009 100755
--- a/tools/grit/grit/node/message.py
+++ b/tools/grit/grit/node/message.py
@@ -11,15 +11,16 @@ import types
from grit.node import base
-import grit.format.rc_header
-import grit.format.rc
-
from grit import clique
from grit import exception
from grit import lazy_re
from grit import tclib
from grit import util
+
+# Matches exactly three dots ending a line or followed by whitespace.
+_ELLIPSIS_PATTERN = lazy_re.compile(r'(?<!\.)\.\.\.(?=$|\s)')
+_ELLIPSIS_SYMBOL = u'\u2026' # Ellipsis
# Finds whitespace at the start and end of a string which can be multiline.
_WHITESPACE = lazy_re.compile('(?P<start>\s*)(?P<body>.+?)(?P<end>\s*)\Z',
re.DOTALL | re.MULTILINE)
@@ -54,6 +55,9 @@ class MessageNode(base.ContentNode):
# Example: "foo=5 bar baz=100"
self.formatter_data = {}
+ # Whether or not to convert ... -> U+2026 within Translate().
+ self._replace_ellipsis = False
+
def _IsValidChild(self, child):
return isinstance(child, (PhNode))
@@ -68,6 +72,11 @@ class MessageNode(base.ContentNode):
return False
return True
+ def SetReplaceEllipsis(self, value):
+ '''Sets whether to replace ... with \u2026.
+ '''
+ self._replace_ellipsis = value
+
def MandatoryAttributes(self):
return ['name|offset']
@@ -200,6 +209,8 @@ class MessageNode(base.ContentNode):
self.PseudoIsAllowed(),
self.ShouldFallbackToEnglish()
).GetRealContent()
+ if self._replace_ellipsis:
+ msg = _ELLIPSIS_PATTERN.sub(_ELLIPSIS_SYMBOL, msg)
return msg.replace('[GRITLANGCODE]', lang)
def NameOrOffset(self):

Powered by Google App Engine
This is Rietveld 408576698