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

Unified Diff: chrome/browser/resources/options/chromeos_language_list.js

Issue 5895005: Add 'en' in addition to 'en-US' as Accept-Language. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rework comments Created 10 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/options/chromeos_language_list.js
diff --git a/chrome/browser/resources/options/chromeos_language_list.js b/chrome/browser/resources/options/chromeos_language_list.js
index f1c18c351e84c9b81c0528817d5af57484b1d80a..df47550dc497aec5bd228880a230da9a0b6aebc1 100644
--- a/chrome/browser/resources/options/chromeos_language_list.js
+++ b/chrome/browser/resources/options/chromeos_language_list.js
@@ -288,17 +288,42 @@ cr.define('options.language', function() {
// Encode the language codes into a CSV string.
Preferences.setStringPref(this.preferredLanguagesPref,
this.dataModel.slice().join(','));
- // Save the same language list as accept languages preference. In
- // theory, we don't need two separate preferences but we keep these
- // separate, as these are conceptually different. In other words,
- // using "intl.accept_languages" for preferred languages in Chrome
- // OS is a bit awkward.
+ // Save the same language list as accept languages preference as
+ // well, but we need to expand the language list, to make it more
+ // acceptable. For instance, some web sites don't understand 'en-US'
+ // but 'en'. See crosbug.com/9884.
+ var acceptLanguages = this.expandLanguageCodes(this.dataModel.slice());
Preferences.setStringPref(this.acceptLanguagesPref,
- this.dataModel.slice().join(','));
+ acceptLanguages.join(','));
cr.dispatchSimpleEvent(this, 'save');
},
/**
+ * Expands language codes to make these more suitable for Accept-Language.
+ * Example: ['en-US', 'ja', 'en-CA'] => ['en-US', 'en', 'ja', 'en-CA'].
+ * 'en' won't appear twice as this function eliminates duplicates.
+ * @param {Array} languageCodes List of language codes.
+ * @private
+ */
+ expandLanguageCodes: function(languageCodes) {
+ var expandedLanguageCodes = [];
+ var seen = {}; // Used to eliminiate duplicates.
+ for (var i = 0; i < languageCodes.length; i++) {
+ var languageCode = languageCodes[i];
+ if (!(languageCode in seen)) {
+ expandedLanguageCodes.push(languageCode);
+ seen[languageCode] = true;
+ }
+ var parts = languageCode.split('-');
+ if (!(parts[0] in seen)) {
+ expandedLanguageCodes.push(parts[0]);
+ seen[parts[0]] = true;
+ }
+ }
+ return expandedLanguageCodes;
+ },
+
+ /**
* Filters bad language codes in case bad language codes are
* stored in the preference. Removes duplicates as well.
* @param {Array} languageCodes List of language codes.
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698