| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "extensions/common/extension_l10n_util.h" | 5 #include "extensions/common/extension_l10n_util.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 // Loads contents of the messages file for given locale. If file is not found, | 33 // Loads contents of the messages file for given locale. If file is not found, |
| 34 // or there was parsing error we return NULL and set |error|. | 34 // or there was parsing error we return NULL and set |error|. |
| 35 // Caller owns the returned object. | 35 // Caller owns the returned object. |
| 36 base::DictionaryValue* LoadMessageFile(const base::FilePath& locale_path, | 36 base::DictionaryValue* LoadMessageFile(const base::FilePath& locale_path, |
| 37 const std::string& locale, | 37 const std::string& locale, |
| 38 std::string* error) { | 38 std::string* error) { |
| 39 base::FilePath file = | 39 base::FilePath file = |
| 40 locale_path.AppendASCII(locale).Append(extensions::kMessagesFilename); | 40 locale_path.AppendASCII(locale).Append(extensions::kMessagesFilename); |
| 41 JSONFileValueDeserializer messages_deserializer(file); | 41 JSONFileValueDeserializer messages_deserializer(file); |
| 42 base::Value* dictionary = messages_deserializer.Deserialize(NULL, error); | 42 scoped_ptr<base::Value> dictionary = |
| 43 messages_deserializer.Deserialize(NULL, error); |
| 43 if (!dictionary) { | 44 if (!dictionary) { |
| 44 if (error->empty()) { | 45 if (error->empty()) { |
| 45 // JSONFileValueSerializer just returns NULL if file cannot be found. It | 46 // JSONFileValueSerializer just returns NULL if file cannot be found. It |
| 46 // doesn't set the error, so we have to do it. | 47 // doesn't set the error, so we have to do it. |
| 47 *error = base::StringPrintf("Catalog file is missing for locale %s.", | 48 *error = base::StringPrintf("Catalog file is missing for locale %s.", |
| 48 locale.c_str()); | 49 locale.c_str()); |
| 49 } else { | 50 } else { |
| 50 *error = extensions::ErrorUtils::FormatErrorMessage( | 51 *error = extensions::ErrorUtils::FormatErrorMessage( |
| 51 errors::kLocalesInvalidLocale, | 52 errors::kLocalesInvalidLocale, |
| 52 base::UTF16ToUTF8(file.LossyDisplayName()), | 53 base::UTF16ToUTF8(file.LossyDisplayName()), |
| 53 *error); | 54 *error); |
| 54 } | 55 } |
| 55 } | 56 } |
| 56 | 57 |
| 57 return static_cast<base::DictionaryValue*>(dictionary); | 58 return static_cast<base::DictionaryValue*>(dictionary.release()); |
| 58 } | 59 } |
| 59 | 60 |
| 60 // Localizes manifest value of string type for a given key. | 61 // Localizes manifest value of string type for a given key. |
| 61 bool LocalizeManifestValue(const std::string& key, | 62 bool LocalizeManifestValue(const std::string& key, |
| 62 const extensions::MessageBundle& messages, | 63 const extensions::MessageBundle& messages, |
| 63 base::DictionaryValue* manifest, | 64 base::DictionaryValue* manifest, |
| 64 std::string* error) { | 65 std::string* error) { |
| 65 std::string result; | 66 std::string result; |
| 66 if (!manifest->GetString(key, &result)) | 67 if (!manifest->GetString(key, &result)) |
| 67 return true; | 68 return true; |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 ScopedLocaleForTest::ScopedLocaleForTest(const std::string& locale) | 456 ScopedLocaleForTest::ScopedLocaleForTest(const std::string& locale) |
| 456 : locale_(extension_l10n_util::CurrentLocaleOrDefault()) { | 457 : locale_(extension_l10n_util::CurrentLocaleOrDefault()) { |
| 457 extension_l10n_util::SetProcessLocale(locale); | 458 extension_l10n_util::SetProcessLocale(locale); |
| 458 } | 459 } |
| 459 | 460 |
| 460 ScopedLocaleForTest::~ScopedLocaleForTest() { | 461 ScopedLocaleForTest::~ScopedLocaleForTest() { |
| 461 extension_l10n_util::SetProcessLocale(locale_); | 462 extension_l10n_util::SetProcessLocale(locale_); |
| 462 } | 463 } |
| 463 | 464 |
| 464 } // namespace extension_l10n_util | 465 } // namespace extension_l10n_util |
| OLD | NEW |