OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/common/extensions/extension_l10n_util.h" | 5 #include "chrome/common/extensions/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 30 matching lines...) Expand all Loading... |
41 std::string* error) { | 41 std::string* error) { |
42 std::string default_locale; | 42 std::string default_locale; |
43 if (manifest.GetString(keys::kDefaultLocale, &default_locale)) | 43 if (manifest.GetString(keys::kDefaultLocale, &default_locale)) |
44 return default_locale; | 44 return default_locale; |
45 | 45 |
46 *error = errors::kInvalidDefaultLocale; | 46 *error = errors::kInvalidDefaultLocale; |
47 return ""; | 47 return ""; |
48 | 48 |
49 } | 49 } |
50 | 50 |
51 bool ShouldRelocalizeManifest(const ExtensionInfo& info) { | 51 bool ShouldRelocalizeManifest(const extensions::ExtensionInfo& info) { |
52 DictionaryValue* manifest = info.extension_manifest.get(); | 52 DictionaryValue* manifest = info.extension_manifest.get(); |
53 if (!manifest) | 53 if (!manifest) |
54 return false; | 54 return false; |
55 | 55 |
56 if (!manifest->HasKey(keys::kDefaultLocale)) | 56 if (!manifest->HasKey(keys::kDefaultLocale)) |
57 return false; | 57 return false; |
58 | 58 |
59 std::string manifest_current_locale; | 59 std::string manifest_current_locale; |
60 manifest->GetString(keys::kCurrentLocale, &manifest_current_locale); | 60 manifest->GetString(keys::kCurrentLocale, &manifest_current_locale); |
61 return manifest_current_locale != CurrentLocaleOrDefault(); | 61 return manifest_current_locale != CurrentLocaleOrDefault(); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 return true; | 199 return true; |
200 if (chrome_locales.find(locale_name) == chrome_locales.end()) { | 200 if (chrome_locales.find(locale_name) == chrome_locales.end()) { |
201 // Warn if there is an extension locale that's not in the Chrome list, | 201 // Warn if there is an extension locale that's not in the Chrome list, |
202 // but don't fail. | 202 // but don't fail. |
203 DLOG(WARNING) << base::StringPrintf("Supplied locale %s is not supported.", | 203 DLOG(WARNING) << base::StringPrintf("Supplied locale %s is not supported.", |
204 locale_name.c_str()); | 204 locale_name.c_str()); |
205 return true; | 205 return true; |
206 } | 206 } |
207 // Check if messages file is actually present (but don't check content). | 207 // Check if messages file is actually present (but don't check content). |
208 if (file_util::PathExists( | 208 if (file_util::PathExists( |
209 locale_folder.Append(Extension::kMessagesFilename))) { | 209 locale_folder.Append(extensions::Extension::kMessagesFilename))) { |
210 valid_locales->insert(locale_name); | 210 valid_locales->insert(locale_name); |
211 } else { | 211 } else { |
212 *error = base::StringPrintf("Catalog file is missing for locale %s.", | 212 *error = base::StringPrintf("Catalog file is missing for locale %s.", |
213 locale_name.c_str()); | 213 locale_name.c_str()); |
214 return false; | 214 return false; |
215 } | 215 } |
216 | 216 |
217 return true; | 217 return true; |
218 } | 218 } |
219 | 219 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 } | 272 } |
273 | 273 |
274 // Loads contents of the messages file for given locale. If file is not found, | 274 // Loads contents of the messages file for given locale. If file is not found, |
275 // or there was parsing error we return NULL and set |error|. | 275 // or there was parsing error we return NULL and set |error|. |
276 // Caller owns the returned object. | 276 // Caller owns the returned object. |
277 static DictionaryValue* LoadMessageFile(const FilePath& locale_path, | 277 static DictionaryValue* LoadMessageFile(const FilePath& locale_path, |
278 const std::string& locale, | 278 const std::string& locale, |
279 std::string* error) { | 279 std::string* error) { |
280 std::string extension_locale = locale; | 280 std::string extension_locale = locale; |
281 FilePath file = locale_path.AppendASCII(extension_locale) | 281 FilePath file = locale_path.AppendASCII(extension_locale) |
282 .Append(Extension::kMessagesFilename); | 282 .Append(extensions::Extension::kMessagesFilename); |
283 JSONFileValueSerializer messages_serializer(file); | 283 JSONFileValueSerializer messages_serializer(file); |
284 Value *dictionary = messages_serializer.Deserialize(NULL, error); | 284 Value *dictionary = messages_serializer.Deserialize(NULL, error); |
285 if (!dictionary && error->empty()) { | 285 if (!dictionary && error->empty()) { |
286 // JSONFileValueSerializer just returns NULL if file cannot be found. It | 286 // JSONFileValueSerializer just returns NULL if file cannot be found. It |
287 // doesn't set the error, so we have to do it. | 287 // doesn't set the error, so we have to do it. |
288 *error = base::StringPrintf("Catalog file is missing for locale %s.", | 288 *error = base::StringPrintf("Catalog file is missing for locale %s.", |
289 extension_locale.c_str()); | 289 extension_locale.c_str()); |
290 } | 290 } |
291 | 291 |
292 return static_cast<DictionaryValue*>(dictionary); | 292 return static_cast<DictionaryValue*>(dictionary); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 if (std::find(subdir.begin(), subdir.end(), '.') != subdir.end()) | 341 if (std::find(subdir.begin(), subdir.end(), '.') != subdir.end()) |
342 return true; | 342 return true; |
343 | 343 |
344 if (all_locales.find(subdir) == all_locales.end()) | 344 if (all_locales.find(subdir) == all_locales.end()) |
345 return true; | 345 return true; |
346 | 346 |
347 return false; | 347 return false; |
348 } | 348 } |
349 | 349 |
350 } // namespace extension_l10n_util | 350 } // namespace extension_l10n_util |
OLD | NEW |