| 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 20 matching lines...) Expand all Loading... |
| 31 namespace { | 31 namespace { |
| 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 JSONFileValueSerializer messages_serializer(file); | 41 JSONFileValueDeserializer messages_deserializer(file); |
| 42 base::Value* dictionary = messages_serializer.Deserialize(NULL, error); | 42 base::Value* dictionary = messages_deserializer.Deserialize(NULL, error); |
| 43 if (!dictionary) { | 43 if (!dictionary) { |
| 44 if (error->empty()) { | 44 if (error->empty()) { |
| 45 // JSONFileValueSerializer just returns NULL if file cannot be found. It | 45 // JSONFileValueSerializer just returns NULL if file cannot be found. It |
| 46 // doesn't set the error, so we have to do it. | 46 // doesn't set the error, so we have to do it. |
| 47 *error = base::StringPrintf("Catalog file is missing for locale %s.", | 47 *error = base::StringPrintf("Catalog file is missing for locale %s.", |
| 48 locale.c_str()); | 48 locale.c_str()); |
| 49 } else { | 49 } else { |
| 50 *error = extensions::ErrorUtils::FormatErrorMessage( | 50 *error = extensions::ErrorUtils::FormatErrorMessage( |
| 51 errors::kLocalesInvalidLocale, | 51 errors::kLocalesInvalidLocale, |
| 52 base::UTF16ToUTF8(file.LossyDisplayName()), | 52 base::UTF16ToUTF8(file.LossyDisplayName()), |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 ScopedLocaleForTest::ScopedLocaleForTest(const std::string& locale) | 453 ScopedLocaleForTest::ScopedLocaleForTest(const std::string& locale) |
| 454 : locale_(extension_l10n_util::CurrentLocaleOrDefault()) { | 454 : locale_(extension_l10n_util::CurrentLocaleOrDefault()) { |
| 455 extension_l10n_util::SetProcessLocale(locale); | 455 extension_l10n_util::SetProcessLocale(locale); |
| 456 } | 456 } |
| 457 | 457 |
| 458 ScopedLocaleForTest::~ScopedLocaleForTest() { | 458 ScopedLocaleForTest::~ScopedLocaleForTest() { |
| 459 extension_l10n_util::SetProcessLocale(locale_); | 459 extension_l10n_util::SetProcessLocale(locale_); |
| 460 } | 460 } |
| 461 | 461 |
| 462 } // namespace extension_l10n_util | 462 } // namespace extension_l10n_util |
| OLD | NEW |