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

Side by Side Diff: chrome/installer/util/prebuild/create_string_rc.py

Issue 4139010: The UI language rather than the locale is now used to pick Chrome's language ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2009 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2009 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """This script generates an rc file and header (setup_strings.{rc,h}) to be 6 """This script generates an rc file and header (setup_strings.{rc,h}) to be
7 included in setup.exe. The rc file includes translations for strings pulled 7 included in setup.exe. The rc file includes translations for strings pulled
8 from generated_resource.grd and the localized .xtb files. 8 from generated_resource.grd and the localized .xtb files.
9 9
10 The header file includes IDs for each string, but also has values to allow 10 The header file includes IDs for each string, but also has values to allow
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 translation)) 168 translation))
169 lines.append(kFooterText) 169 lines.append(kFooterText)
170 outfile = open(out_filename + '.rc', 'wb') 170 outfile = open(out_filename + '.rc', 'wb')
171 outfile.write(''.join(lines).encode('utf-16')) 171 outfile.write(''.join(lines).encode('utf-16'))
172 outfile.close() 172 outfile.close()
173 173
174 def WriteHeaderFile(translated_strings, out_filename): 174 def WriteHeaderFile(translated_strings, out_filename):
175 """Writes a .h file with resource ids. This file can be included by the 175 """Writes a .h file with resource ids. This file can be included by the
176 executable to refer to identifiers.""" 176 executable to refer to identifiers."""
177 lines = [] 177 lines = []
178 do_languages_lines = ['#define DO_LANGUAGES']
178 179
179 # Write the values for how the languages ids are offset. 180 # Write the values for how the languages ids are offset.
180 seen_languages = set() 181 seen_languages = set()
181 offset_id = 0 182 offset_id = 0
182 for translation_struct in translated_strings: 183 for translation_struct in translated_strings:
183 lang = translation_struct.language 184 lang = translation_struct.language
184 if lang not in seen_languages: 185 if lang not in seen_languages:
185 seen_languages.add(lang) 186 seen_languages.add(lang)
186 lines.append(u'#define IDS_L10N_OFFSET_%s %s' % (lang, offset_id)) 187 lines.append('#define IDS_L10N_OFFSET_%s %s' % (lang, offset_id))
188 do_languages_lines.append(' HANDLE_LANGUAGE(%s, IDS_L10N_OFFSET_%s)'
189 % (lang.replace('_', '-').lower(), lang))
187 offset_id += 1 190 offset_id += 1
188 else: 191 else:
189 break 192 break
190 193
191 # Write the resource ids themselves. 194 # Write the resource ids themselves.
192 resource_id = kFirstResourceID 195 resource_id = kFirstResourceID
193 for translation_struct in translated_strings: 196 for translation_struct in translated_strings:
194 lines.append(u'#define %s %s' % (translation_struct.resource_id_str, 197 lines.append('#define %s %s' % (translation_struct.resource_id_str,
195 resource_id)) 198 resource_id))
196 resource_id += 1 199 resource_id += 1
197 200
198 # Write out base ID values. 201 # Write out base ID values.
199 for string_id in kStringIds: 202 for string_id in kStringIds:
200 lines.append(u'#define %s_BASE %s_%s' % (string_id, 203 lines.append('#define %s_BASE %s_%s' % (string_id,
201 string_id, 204 string_id,
202 translated_strings[0].language)) 205 translated_strings[0].language))
203 206
204 outfile = open(out_filename + '.h', 'wb') 207 outfile = open(out_filename + '.h', 'wb')
205 outfile.write('\n'.join(lines)) 208 outfile.write('\n'.join(lines))
206 outfile.write('\n') # .rc files must end in a new line 209 outfile.write('\n#ifndef RC_INVOKED\n')
210 outfile.write(' \\\n'.join(do_languages_lines))
211 # .rc files must end in a new line
212 outfile.write('\n#endif // ndef RC_INVOKED\n')
207 outfile.close() 213 outfile.close()
208 214
209 def main(argv): 215 def main(argv):
210 branding = '' 216 branding = ''
211 if (len(sys.argv) > 2): 217 if (len(sys.argv) > 2):
212 branding = argv[2] 218 branding = argv[2]
213 translated_strings = CollectTranslatedStrings(branding) 219 translated_strings = CollectTranslatedStrings(branding)
214 kFilebase = os.path.join(argv[1], 'installer_util_strings') 220 kFilebase = os.path.join(argv[1], 'installer_util_strings')
215 WriteRCFile(translated_strings, kFilebase) 221 WriteRCFile(translated_strings, kFilebase)
216 WriteHeaderFile(translated_strings, kFilebase) 222 WriteHeaderFile(translated_strings, kFilebase)
217 223
218 if '__main__' == __name__: 224 if '__main__' == __name__:
219 if len(sys.argv) < 2: 225 if len(sys.argv) < 2:
220 print 'Usage:\n %s <output_directory> [branding]' % sys.argv[0] 226 print 'Usage:\n %s <output_directory> [branding]' % sys.argv[0]
221 sys.exit(1) 227 sys.exit(1)
222 # Use optparse to parse command line flags. 228 # Use optparse to parse command line flags.
223 main(sys.argv) 229 main(sys.argv)
OLDNEW
« no previous file with comments | « chrome/installer/util/language_selector_unittest.cc ('k') | chrome_frame/simple_resource_loader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698