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

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

Issue 7744017: Updated *.pak file format to support both UTF8 and UTF16 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Modified mac-specific parts of the code. Created 9 years, 3 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
« no previous file with comments | « tools/grit/grit/node/include.py ('k') | ui/base/resource/data_pack.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/grit/grit/node/message.py
diff --git a/tools/grit/grit/node/message.py b/tools/grit/grit/node/message.py
index a48a645fd4ba2ce489bf2c6794f4b6c751539c73..3c5ac645f1137a4b75a5d49a99808601fbb081f3 100644
--- a/tools/grit/grit/node/message.py
+++ b/tools/grit/grit/node/message.py
@@ -1,5 +1,5 @@
#!/usr/bin/python2.4
-# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+# Copyright (c) 2011 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.
@@ -19,6 +19,7 @@ from grit import exception
from grit import tclib
from grit import util
+BINARY, UTF8, UTF16 = range(3)
# Finds whitespace at the start and end of a string which can be multiline.
_WHITESPACE = re.compile('(?P<start>\s*)(?P<body>.+?)(?P<end>\s*)\Z',
@@ -186,7 +187,7 @@ class MessageNode(base.ContentNode):
else:
return self.attrs['offset']
- def GetDataPackPair(self, lang):
+ def GetDataPackPair(self, lang, encoding):
'''Returns a (id, string) pair that represents the string id and the string
in utf8. This is used to generate the data pack data file.
'''
@@ -199,10 +200,15 @@ class MessageNode(base.ContentNode):
# Windows automatically translates \n to a new line, but GTK+ doesn't.
# Manually do the conversion here rather than at run time.
message = message.replace("\\n", "\n")
- # |message| is a python unicode string, so convert to a utf16 byte stream
- # because that's the format of datapacks. We skip the first 2 bytes
- # because it is the BOM.
- return id, message.encode('utf16')[2:]
+ # |message| is a python unicode string, so convert to a byte stream that
+ # has the correct encoding requested for the datapacks. We skip the first
+ # 2 bytes of text resources because it is the BOM.
+ if encoding == UTF8:
+ return id, message.encode('utf8')
+ if encoding == UTF16:
+ return id, message.encode('utf16')[2:]
+ # Default is BINARY
+ return id, message
# static method
def Construct(parent, message, name, desc='', meaning='', translateable=True):
« no previous file with comments | « tools/grit/grit/node/include.py ('k') | ui/base/resource/data_pack.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698