OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Helper tool that is built and run during a build to pull strings from | 5 // Helper tool that is built and run during a build to pull strings from |
6 // the GRD files and generate the InfoPlist.strings files needed for | 6 // the GRD files and generate the InfoPlist.strings files needed for |
7 // Mac OS X app bundles. | 7 // Mac OS X app bundles. |
8 | 8 |
9 #import <Foundation/Foundation.h> | 9 #import <Foundation/Foundation.h> |
10 | 10 |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 // put them final runtime encoding. | 259 // put them final runtime encoding. |
260 NSData* strings_file_contents_utf8 = | 260 NSData* strings_file_contents_utf8 = |
261 [strings_file_contents_string dataUsingEncoding:NSUTF8StringEncoding]; | 261 [strings_file_contents_string dataUsingEncoding:NSUTF8StringEncoding]; |
262 | 262 |
263 if ([strings_file_contents_utf8 length] == 0) { | 263 if ([strings_file_contents_utf8 length] == 0) { |
264 fprintf(stderr, "ERROR: failed to get the utf8 encoding of the strings " | 264 fprintf(stderr, "ERROR: failed to get the utf8 encoding of the strings " |
265 "file for language: %s\n", cur_lang); | 265 "file for language: %s\n", cur_lang); |
266 exit(1); | 266 exit(1); |
267 } | 267 } |
268 | 268 |
| 269 // For Cocoa to find the locale at runtime, it needs to use '_' instead of |
| 270 // '-' (http://crbug.com/20441). Also, 'en-US' should be represented |
| 271 // simply as 'en' (http://crbug.com/19165, http://crbug.com/25578). |
| 272 NSString* cur_lang_ns = [NSString stringWithUTF8String:cur_lang]; |
| 273 if ([cur_lang_ns isEqualToString:@"en-US"]) { |
| 274 cur_lang_ns = @"en"; |
| 275 } |
| 276 cur_lang_ns = [cur_lang_ns stringByReplacingOccurrencesOfString:@"-" |
| 277 withString:@"_"]; |
269 // Make sure the lproj we write to exists | 278 // Make sure the lproj we write to exists |
270 NSString *lproj_name = [NSString stringWithFormat:@"%s.lproj", cur_lang]; | 279 NSString *lproj_name = [NSString stringWithFormat:@"%@.lproj", cur_lang_ns]; |
271 // For Cocoa to find the locale at runtime, it needs to use '_' instead of | |
272 // '-'. (http://crbug.com/20441) | |
273 lproj_name = [lproj_name stringByReplacingOccurrencesOfString:@"-" | |
274 withString:@"_"]; | |
275 NSString *output_path = | 280 NSString *output_path = |
276 [[NSString stringWithUTF8String:output_dir] | 281 [[NSString stringWithUTF8String:output_dir] |
277 stringByAppendingPathComponent:lproj_name]; | 282 stringByAppendingPathComponent:lproj_name]; |
278 NSError* error = nil; | 283 NSError* error = nil; |
279 if (![fm fileExistsAtPath:output_path] && | 284 if (![fm fileExistsAtPath:output_path] && |
280 ![fm createDirectoryAtPath:output_path | 285 ![fm createDirectoryAtPath:output_path |
281 withIntermediateDirectories:YES | 286 withIntermediateDirectories:YES |
282 attributes:nil | 287 attributes:nil |
283 error:&error]) { | 288 error:&error]) { |
284 fprintf(stderr, "ERROR: '%s' didn't exist or we failed to create it\n", | 289 fprintf(stderr, "ERROR: '%s' didn't exist or we failed to create it\n", |
285 [output_path UTF8String]); | 290 [output_path UTF8String]); |
286 exit(1); | 291 exit(1); |
287 } | 292 } |
288 | 293 |
289 // Write out the file | 294 // Write out the file |
290 output_path = | 295 output_path = |
291 [output_path stringByAppendingPathComponent:@"InfoPlist.strings"]; | 296 [output_path stringByAppendingPathComponent:@"InfoPlist.strings"]; |
292 if (![strings_file_contents_utf8 writeToFile:output_path | 297 if (![strings_file_contents_utf8 writeToFile:output_path |
293 atomically:YES]) { | 298 atomically:YES]) { |
294 fprintf(stderr, "ERROR: Failed to write out '%s'\n", | 299 fprintf(stderr, "ERROR: Failed to write out '%s'\n", |
295 [output_path UTF8String]); | 300 [output_path UTF8String]); |
296 exit(1); | 301 exit(1); |
297 } | 302 } |
298 } | 303 } |
299 return 0; | 304 return 0; |
300 } | 305 } |
OLD | NEW |