| 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 /** | 5 /** |
| 6 * @param {string} toTest The string to be tested. | 6 * @param {string} toTest The string to be tested. |
| 7 * @return {boolean} True if |toTest| contains only digits. Leading and trailing | 7 * @return {boolean} True if |toTest| contains only digits. Leading and trailing |
| 8 * whitespace is allowed. | 8 * whitespace is allowed. |
| 9 */ | 9 */ |
| 10 function isInteger(toTest) { | 10 function isInteger(toTest) { |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 /** | 209 /** |
| 210 * @param {!Array} array Array to check for item. | 210 * @param {!Array} array Array to check for item. |
| 211 * @param {*} item Item to look for in array. | 211 * @param {*} item Item to look for in array. |
| 212 * @return {boolean} Whether the item is in the array. | 212 * @return {boolean} Whether the item is in the array. |
| 213 */ | 213 */ |
| 214 function arrayContains(array, item) { | 214 function arrayContains(array, item) { |
| 215 return array.indexOf(item) != -1; | 215 return array.indexOf(item) != -1; |
| 216 } | 216 } |
| 217 | 217 |
| 218 /** | 218 /** |
| 219 * @param {!goog.array.ArrayLike<!{locale: string, value: string}>} | 219 * @param {!Array<!{locale: string, value: string}>} localizedStrings An array |
| 220 * localizedStrings An array of strings with corresponding locales. | 220 * of strings with corresponding locales. |
| 221 * @param {string} locale Locale to look the string up for. | 221 * @param {string} locale Locale to look the string up for. |
| 222 * @return {string} A string for the requested {@code locale}. An empty string | 222 * @return {string} A string for the requested {@code locale}. An empty string |
| 223 * if there's no string for the specified locale found. | 223 * if there's no string for the specified locale found. |
| 224 */ | 224 */ |
| 225 function getStringForLocale(localizedStrings, locale) { | 225 function getStringForLocale(localizedStrings, locale) { |
| 226 locale = locale.toLowerCase(); | 226 locale = locale.toLowerCase(); |
| 227 for (var i = 0; i < localizedStrings.length; i++) { | 227 for (var i = 0; i < localizedStrings.length; i++) { |
| 228 if (localizedStrings[i].locale.toLowerCase() == locale) | 228 if (localizedStrings[i].locale.toLowerCase() == locale) |
| 229 return localizedStrings[i].value; | 229 return localizedStrings[i].value; |
| 230 } | 230 } |
| 231 return ''; | 231 return ''; |
| 232 } | 232 } |
| 233 | 233 |
| 234 /** | 234 /** |
| 235 * @param {!goog.array.ArrayLike<!{locale: string, value: string}>} | 235 * @param {!Array<!{locale: string, value: string}>} localizedStrings An array |
| 236 * localizedStrings An array of strings with corresponding locales. | 236 * of strings with corresponding locales. |
| 237 * @return {string} A string for the current locale. An empty string if there's | 237 * @return {string} A string for the current locale. An empty string if there's |
| 238 * no string for the current locale found. | 238 * no string for the current locale found. |
| 239 */ | 239 */ |
| 240 function getStringForCurrentLocale(localizedStrings) { | 240 function getStringForCurrentLocale(localizedStrings) { |
| 241 // First try to find an exact match and then look for the language only. | 241 // First try to find an exact match and then look for the language only. |
| 242 return getStringForLocale(localizedStrings, navigator.language) || | 242 return getStringForLocale(localizedStrings, navigator.language) || |
| 243 getStringForLocale(localizedStrings, | 243 getStringForLocale(localizedStrings, |
| 244 navigator.language.split('-')[0]); | 244 navigator.language.split('-')[0]); |
| 245 } | 245 } |
| OLD | NEW |