summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-17 06:01:56 +0000
committersatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-17 06:01:56 +0000
commit161edaf25848c8a50d943ee6e7b862d2b3a6d18f (patch)
tree8fe5951b8e92bc447ffb256f3815d76c768caf7c
parent2e34ab3ffcc704e298037c7584fc8174d8206a36 (diff)
downloadchromium_src-161edaf25848c8a50d943ee6e7b862d2b3a6d18f.zip
chromium_src-161edaf25848c8a50d943ee6e7b862d2b3a6d18f.tar.gz
chromium_src-161edaf25848c8a50d943ee6e7b862d2b3a6d18f.tar.bz2
Add 'en' in addition to 'en-US' as Accept-Language.
Some web sites don't understand 'en-US' but 'en' in Accept-Language header. Hence we should add 'en' in addition to 'en-US'. BUG=chromium-os:9884 TEST=Added Finnish and confirmed that Accept-Language looked like "en-US,en;q=0.8,fi;q=0.6" using http://pgl.yoyo.org/http/browser-headers.php. Also visited sidneyspage.blogspot.com and confirmed that English contents were shown. Review URL: http://codereview.chromium.org/5895005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69521 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/resources/options/chromeos_language_list.js37
1 files changed, 31 insertions, 6 deletions
diff --git a/chrome/browser/resources/options/chromeos_language_list.js b/chrome/browser/resources/options/chromeos_language_list.js
index f1c18c3..df47550 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.