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

Unified Diff: tools/grit/grit/format/js_map_format.py

Issue 1410853008: Move grit from DEPS into src. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: webview licenses Created 5 years, 1 month 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
« no previous file with comments | « tools/grit/grit/format/html_inline_unittest.py ('k') | tools/grit/grit/format/js_map_format_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/grit/grit/format/js_map_format.py
diff --git a/tools/grit/grit/format/js_map_format.py b/tools/grit/grit/format/js_map_format.py
new file mode 100755
index 0000000000000000000000000000000000000000..8cc8eb25e729282b54de8594fde1578f03b17fa2
--- /dev/null
+++ b/tools/grit/grit/format/js_map_format.py
@@ -0,0 +1,44 @@
+#!/usr/bin/env python
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Formats as a .js file using a map: <english text> -> <localized text>.
+"""
+
+import re
+
+from grit import util
+
+
+"""The required preamble for JS files."""
+_HEADER = '// This file is automatically generated by GRIT. Do not edit.\n'
+
+
+def Format(root, lang='en', output_dir='.'):
+ from grit.node import empty, message
+ yield _HEADER
+ for item in root.ActiveDescendants():
+ with item:
+ if isinstance(item, message.MessageNode):
+ yield _FormatMessage(item, lang)
+ elif isinstance(item, empty.MessagesNode):
+ yield '\n'
+
+
+def _FormatMessage(item, lang):
+ """Format a single message."""
+
+ en_message = item.ws_at_start + item.Translate('en') + item.ws_at_end
+ # Remove position numbers from placeholders.
+ en_message = re.sub(r'%\d\$([a-z])', r'%\1', en_message)
+ # Escape double quotes.
+ en_message = re.sub(r'\\', r'\\\\', en_message)
+ en_message = re.sub(r'"', r'\"', en_message)
+
+ loc_message = item.ws_at_start + item.Translate(lang) + item.ws_at_end
+ # Escape double quotes.
+ loc_message = re.sub(r'\\', r'\\\\', loc_message)
+ loc_message = re.sub(r'"', r'\"', loc_message)
+
+ return '\nlocalizedStrings["%s"] = "%s";' % (en_message, loc_message)
« no previous file with comments | « tools/grit/grit/format/html_inline_unittest.py ('k') | tools/grit/grit/format/js_map_format_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698