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

Unified Diff: grit/format/rc_unittest.py

Issue 9965022: Allow substitution of messages as variables in other messages. (Closed) Base URL: https://grit-i18n.googlecode.com/svn/trunk
Patch Set: Fix unit tests for policy writers. Created 8 years, 9 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 | « grit/format/rc_header.py ('k') | grit/format/resource_map.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: grit/format/rc_unittest.py
diff --git a/grit/format/rc_unittest.py b/grit/format/rc_unittest.py
index c255856b800dc787c7bfc8a661f0343a65f66a93..aedf3ffec387fe5099caf928b84aece50e9d9e78 100644
--- a/grit/format/rc_unittest.py
+++ b/grit/format/rc_unittest.py
@@ -87,7 +87,7 @@ BEGIN
MENUITEM "This be ""Klonk"" me like", ID_FILE_THISBE
POPUP "gonk"
BEGIN
- MENUITEM "Klonk && is ""good""", ID_GONK_KLONKIS
+ MENUITEM "Klonk && is [good]", ID_GONK_KLONKIS
END
END
POPUP "&Help"
@@ -246,6 +246,37 @@ END'''.strip()
self.failUnless(contents.find('Hello!') == -1) # should be translated
+ def testSubstitutionHtml(self):
+ input_file = util.PathFromRoot('grit/testdata/toolbar_about.html')
+ root = grd_reader.Parse(StringIO.StringIO('''<?xml version="1.0" encoding="UTF-8"?>
+ <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir=".">
+ <release seq="1" allow_pseudo="False">
+ <structures fallback_to_english="True">
+ <structure type="tr_html" name="IDR_HTML" file="%s" expand_variables="true"/>
+ </structures>
+ </release>
+ </grit>
+ ''' % input_file), util.PathFromRoot('.'))
+ util.FixRootForUnittest(root, '.')
+ root.SetOutputContext('ar', {})
+ # We must run the gatherers since we'll be wanting the translation of the
+ # file. The file exists in the location pointed to.
+ root.RunGatherers(recursive=True)
+
+ output_dir = tempfile.gettempdir()
+ import grit.node.structure
+ structure = root.GetChildrenOfType(grit.node.structure.StructureNode)[0]
+ ar_file = structure.FileForLanguage('ar', output_dir)
+ self.failUnless(ar_file == os.path.join(output_dir,
+ 'ar_toolbar_about.html'))
+
+ fo = file(ar_file)
+ contents = fo.read()
+ fo.close()
+
+ self.failUnless(contents.find('dir="RTL"') != -1)
+
+
def testFallbackToEnglish(self):
root = grd_reader.Parse(StringIO.StringIO('''<?xml version="1.0" encoding="UTF-8"?>
<grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir=".">
@@ -256,6 +287,7 @@ END'''.strip()
</release>
</grit>'''), util.PathFromRoot('.'))
util.FixRootForUnittest(root)
+ root.SetOutputContext('en', {})
root.RunGatherers(recursive = True)
node = root.GetNodeById("IDD_ABOUTBOX")
@@ -276,5 +308,73 @@ BEGIN
END''')
+ def testSubstitutionRc(self):
+ root = grd_reader.Parse(StringIO.StringIO('''<?xml version="1.0" encoding="UTF-8"?>
+ <grit latest_public_release="2" source_lang_id="en-US" current_release="3"
+ base_dir=".">
+ <outputs>
+ <output lang="en" type="rc_all" filename="grit\\testdata\klonk_resources.rc"/>
+ </outputs>
+
+ <release seq="1" allow_pseudo="False">
+ <structures>
+ <structure type="menu" name="IDC_KLONKMENU"
+ file="grit\\testdata\klonk.rc" encoding="utf-16"
+ expand_variables="true" />
+ </structures>
+ <messages>
+ <message name="good" sub_variable="true">
+ excellent
+ </message>
+ </messages>
+ </release>
+ </grit>
+ '''), util.PathFromRoot('.'))
+ util.FixRootForUnittest(root)
+ root.SetOutputContext('en', {})
+ root.RunGatherers(recursive=True)
+
+ buf = StringIO.StringIO()
+ build.RcBuilder.ProcessNode(root, DummyOutput('rc_all', 'en'), buf)
+ output = buf.getvalue()
+ self.failUnless(output.strip() == '''
+// Copyright (c) Google Inc. 2012
+// All rights reserved.
+// This file is automatically generated by GRIT. Do not edit.
+
+#include "resource.h"
+#include <winresrc.h>
+#ifdef IDC_STATIC
+#undef IDC_STATIC
+#endif
+#define IDC_STATIC (-1)
+
+LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
+
+
+IDC_KLONKMENU MENU
+BEGIN
+ POPUP "&File"
+ BEGIN
+ MENUITEM "E&xit", IDM_EXIT
+ MENUITEM "This be ""Klonk"" me like", ID_FILE_THISBE
+ POPUP "gonk"
+ BEGIN
+ MENUITEM "Klonk && is excellent", ID_GONK_KLONKIS
+ END
+ END
+ POPUP "&Help"
+ BEGIN
+ MENUITEM "&About ...", IDM_ABOUT
+ END
+END
+
+STRINGTABLE
+BEGIN
+ good "excellent"
+END
+'''.strip())
+
+
if __name__ == '__main__':
unittest.main()
« no previous file with comments | « grit/format/rc_header.py ('k') | grit/format/resource_map.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698