Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(493)

Side by Side Diff: chrome/common/extensions/extension_l10n_util.cc

Issue 671011: All platforms don't support same locales at the same time. Make locale check ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "chrome/common/extensions/extension_l10n_util.h" 5 #include "chrome/common/extensions/extension_l10n_util.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "app/l10n_util.h" 11 #include "app/l10n_util.h"
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/linked_ptr.h" 13 #include "base/linked_ptr.h"
14 #include "base/logging.h"
14 #include "base/string_util.h" 15 #include "base/string_util.h"
15 #include "base/values.h" 16 #include "base/values.h"
16 #include "chrome/common/extensions/extension.h" 17 #include "chrome/common/extensions/extension.h"
17 #include "chrome/common/extensions/extension_constants.h" 18 #include "chrome/common/extensions/extension_constants.h"
18 #include "chrome/common/extensions/extension_file_util.h" 19 #include "chrome/common/extensions/extension_file_util.h"
19 #include "chrome/common/extensions/extension_message_bundle.h" 20 #include "chrome/common/extensions/extension_message_bundle.h"
20 #include "chrome/common/json_value_serializer.h" 21 #include "chrome/common/json_value_serializer.h"
21 #include "chrome/common/url_constants.h" 22 #include "chrome/common/url_constants.h"
22 #include "unicode/uloc.h" 23 #include "unicode/uloc.h"
23 24
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 bool AddLocale(const std::set<std::string>& chrome_locales, 141 bool AddLocale(const std::set<std::string>& chrome_locales,
141 const FilePath& locale_folder, 142 const FilePath& locale_folder,
142 const std::string& locale_name, 143 const std::string& locale_name,
143 std::set<std::string>* valid_locales, 144 std::set<std::string>* valid_locales,
144 std::string* error) { 145 std::string* error) {
145 // Accept name that starts with a . but don't add it to the list of supported 146 // Accept name that starts with a . but don't add it to the list of supported
146 // locales. 147 // locales.
147 if (locale_name.find(".") == 0) 148 if (locale_name.find(".") == 0)
148 return true; 149 return true;
149 if (chrome_locales.find(locale_name) == chrome_locales.end()) { 150 if (chrome_locales.find(locale_name) == chrome_locales.end()) {
150 // Fail if there is an extension locale that's not in the Chrome list. 151 // Warn if there is an extension locale that's not in the Chrome list,
151 *error = StringPrintf("Supplied locale %s is not supported.", 152 // but don't fail.
152 locale_name.c_str()); 153 LOG(WARNING) << StringPrintf("Supplied locale %s is not supported.",
153 return false; 154 locale_name.c_str());
155 return true;
154 } 156 }
155 // Check if messages file is actually present (but don't check content). 157 // Check if messages file is actually present (but don't check content).
156 if (file_util::PathExists( 158 if (file_util::PathExists(
157 locale_folder.Append(Extension::kMessagesFilename))) { 159 locale_folder.Append(Extension::kMessagesFilename))) {
158 valid_locales->insert(locale_name); 160 valid_locales->insert(locale_name);
159 } else { 161 } else {
160 *error = StringPrintf("Catalog file is missing for locale %s.", 162 *error = StringPrintf("Catalog file is missing for locale %s.",
161 locale_name.c_str()); 163 locale_name.c_str());
162 return false; 164 return false;
163 } 165 }
(...skipping 25 matching lines...) Expand all
189 base::strlcpy(parent, locale.c_str(), kNameCapacity); 191 base::strlcpy(parent, locale.c_str(), kNameCapacity);
190 parent_locales->push_back(parent); 192 parent_locales->push_back(parent);
191 UErrorCode err = U_ZERO_ERROR; 193 UErrorCode err = U_ZERO_ERROR;
192 while (uloc_getParent(parent, parent, kNameCapacity, &err) > 0) { 194 while (uloc_getParent(parent, parent, kNameCapacity, &err) > 0) {
193 if (U_FAILURE(err)) 195 if (U_FAILURE(err))
194 break; 196 break;
195 parent_locales->push_back(parent); 197 parent_locales->push_back(parent);
196 } 198 }
197 } 199 }
198 200
199 // Extends list of Chrome locales to them and their parents, so we can do 201 void GetAllLocales(std::set<std::string>* all_locales) {
200 // proper fallback.
201 static void GetAllLocales(std::set<std::string>* all_locales) {
202 const std::vector<std::string>& available_locales = 202 const std::vector<std::string>& available_locales =
203 l10n_util::GetAvailableLocales(); 203 l10n_util::GetAvailableLocales();
204 // Add all parents of the current locale to the available locales set. 204 // Add all parents of the current locale to the available locales set.
205 // I.e. for sr_Cyrl_RS we add sr_Cyrl_RS, sr_Cyrl and sr. 205 // I.e. for sr_Cyrl_RS we add sr_Cyrl_RS, sr_Cyrl and sr.
206 for (size_t i = 0; i < available_locales.size(); ++i) { 206 for (size_t i = 0; i < available_locales.size(); ++i) {
207 std::vector<std::string> result; 207 std::vector<std::string> result;
208 GetParentLocales(available_locales[i], &result); 208 GetParentLocales(available_locales[i], &result);
209 all_locales->insert(result.begin(), result.end()); 209 all_locales->insert(result.begin(), result.end());
210 } 210 }
211 } 211 }
(...skipping 21 matching lines...) Expand all
233 } 233 }
234 } 234 }
235 235
236 if (valid_locales->empty()) { 236 if (valid_locales->empty()) {
237 *error = extension_manifest_errors::kLocalesNoValidLocaleNamesListed; 237 *error = extension_manifest_errors::kLocalesNoValidLocaleNamesListed;
238 return false; 238 return false;
239 } 239 }
240 240
241 return true; 241 return true;
242 } 242 }
243
244 // Loads contents of the messages file for given locale. If file is not found, 243 // Loads contents of the messages file for given locale. If file is not found,
245 // or there was parsing error we return NULL and set |error|. 244 // or there was parsing error we return NULL and set |error|.
246 // Caller owns the returned object. 245 // Caller owns the returned object.
247 static DictionaryValue* LoadMessageFile(const FilePath& locale_path, 246 static DictionaryValue* LoadMessageFile(const FilePath& locale_path,
248 const std::string& locale, 247 const std::string& locale,
249 std::string* error) { 248 std::string* error) {
250 std::string extension_locale = locale; 249 std::string extension_locale = locale;
251 FilePath file = locale_path.AppendASCII(extension_locale) 250 FilePath file = locale_path.AppendASCII(extension_locale)
252 .Append(Extension::kMessagesFilename); 251 .Append(Extension::kMessagesFilename);
253 JSONFileValueSerializer messages_serializer(file); 252 JSONFileValueSerializer messages_serializer(file);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 // an error. 285 // an error.
287 return false; 286 return false;
288 } else { 287 } else {
289 catalogs.push_back(catalog); 288 catalogs.push_back(catalog);
290 } 289 }
291 } 290 }
292 291
293 return ExtensionMessageBundle::Create(catalogs, error); 292 return ExtensionMessageBundle::Create(catalogs, error);
294 } 293 }
295 294
295 bool ShouldSkipValidation(const FilePath& locales_path,
296 const FilePath& locale_path,
297 const std::set<std::string>& all_locales) {
298 // Since we use this string as a key in a DictionaryValue, be paranoid about
299 // skipping any strings with '.'. This happens sometimes, for example with
300 // '.svn' directories.
301 FilePath relative_path;
302 if (!locales_path.AppendRelativePath(locale_path, &relative_path))
303 NOTREACHED();
304 std::wstring subdir(relative_path.ToWStringHack());
305 if (std::find(subdir.begin(), subdir.end(), L'.') != subdir.end())
306 return true;
307
308 if (all_locales.find(WideToASCII(subdir)) == all_locales.end())
309 return true;
310
311 return false;
312 }
313
296 } // namespace extension_l10n_util 314 } // namespace extension_l10n_util
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension_l10n_util.h ('k') | chrome/common/extensions/extension_l10n_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698