OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 the | 5 // Helper tool that is built and run during a build to pull strings from the |
6 // GRD files and generate a localized string files needed for iOS app bundles. | 6 // GRD files and generate a localized string files needed for iOS app bundles. |
7 // Arguments: | 7 // Arguments: |
8 // -p dir_to_data_pak | 8 // -p dir_to_data_pak |
9 // -o output_dir | 9 // -o output_dir |
10 // -c config_file | 10 // -c config_file |
(...skipping 23 matching lines...) Expand all Loading... |
34 #include "base/mac/scoped_nsautorelease_pool.h" | 34 #include "base/mac/scoped_nsautorelease_pool.h" |
35 #include "base/strings/string_piece.h" | 35 #include "base/strings/string_piece.h" |
36 #include "base/strings/sys_string_conversions.h" | 36 #include "base/strings/sys_string_conversions.h" |
37 #include "ui/base/resource/data_pack.h" | 37 #include "ui/base/resource/data_pack.h" |
38 #include "ui/base/resource/resource_handle.h" | 38 #include "ui/base/resource/resource_handle.h" |
39 | 39 |
40 namespace { | 40 namespace { |
41 | 41 |
42 // Load the packed resource data pack for |locale| from |packed_data_pack_dir|. | 42 // Load the packed resource data pack for |locale| from |packed_data_pack_dir|. |
43 // If loading fails, null is returned. | 43 // If loading fails, null is returned. |
44 scoped_ptr<ui::DataPack> LoadResourceDataPack(NSString* packed_data_pack_dir, | 44 std::unique_ptr<ui::DataPack> LoadResourceDataPack( |
45 NSString* locale_name) { | 45 NSString* packed_data_pack_dir, |
46 scoped_ptr<ui::DataPack> resource_data_pack; | 46 NSString* locale_name) { |
| 47 std::unique_ptr<ui::DataPack> resource_data_pack; |
47 NSString* resource_path = | 48 NSString* resource_path = |
48 [NSString stringWithFormat:@"%@/%@.lproj/locale.pak", | 49 [NSString stringWithFormat:@"%@/%@.lproj/locale.pak", |
49 packed_data_pack_dir, locale_name]; | 50 packed_data_pack_dir, locale_name]; |
50 | 51 |
51 if (!resource_path) | 52 if (!resource_path) |
52 return resource_data_pack; | 53 return resource_data_pack; |
53 | 54 |
54 // FilePath may contain components that references parent directory | 55 // FilePath may contain components that references parent directory |
55 // (".."). DataPack disallows paths with ".." for security reasons. | 56 // (".."). DataPack disallows paths with ".." for security reasons. |
56 base::FilePath resources_pak_path([resource_path fileSystemRepresentation]); | 57 base::FilePath resources_pak_path([resource_path fileSystemRepresentation]); |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 } | 330 } |
330 | 331 |
331 NSArray* outputs = [config objectForKey:@"outputs"]; | 332 NSArray* outputs = [config objectForKey:@"outputs"]; |
332 | 333 |
333 if (![outputs count]) { | 334 if (![outputs count]) { |
334 fprintf(stderr, "ERROR: No output in config file\n"); | 335 fprintf(stderr, "ERROR: No output in config file\n"); |
335 exit(1); | 336 exit(1); |
336 } | 337 } |
337 | 338 |
338 for (NSString* locale in locales) { | 339 for (NSString* locale in locales) { |
339 scoped_ptr<ui::DataPack> data_pack = | 340 std::unique_ptr<ui::DataPack> data_pack = |
340 LoadResourceDataPack(data_pack_dir, locale); | 341 LoadResourceDataPack(data_pack_dir, locale); |
341 if (!data_pack) { | 342 if (!data_pack) { |
342 fprintf(stderr, "ERROR: Failed to load branded pak for language: %s\n", | 343 fprintf(stderr, "ERROR: Failed to load branded pak for language: %s\n", |
343 [locale UTF8String]); | 344 [locale UTF8String]); |
344 exit(1); | 345 exit(1); |
345 } | 346 } |
346 | 347 |
347 for (NSDictionary* output : [config objectForKey:@"outputs"]) { | 348 for (NSDictionary* output : [config objectForKey:@"outputs"]) { |
348 NSString* output_name = [output objectForKey:@"name"]; | 349 NSString* output_name = [output objectForKey:@"name"]; |
349 if (!output_name) { | 350 if (!output_name) { |
(...skipping 14 matching lines...) Expand all Loading... |
364 output_name); | 365 output_name); |
365 } else { | 366 } else { |
366 fprintf(stderr, "ERROR: Unable to create %s.\n", | 367 fprintf(stderr, "ERROR: Unable to create %s.\n", |
367 [output_name UTF8String]); | 368 [output_name UTF8String]); |
368 exit(1); | 369 exit(1); |
369 } | 370 } |
370 } | 371 } |
371 } | 372 } |
372 return 0; | 373 return 0; |
373 } | 374 } |
OLD | NEW |