* _selectLocale * Returns a Promise to select the locale. * @return {Promise} Promise resolved when the locale has been selected and strings loaded
()
| 194 | * @return {Promise} Promise resolved when the locale has been selected and strings loaded |
| 195 | */ |
| 196 | selectLocaleAsync() { |
| 197 | const urlhash = this.context.systems.urlhash; |
| 198 | const urlLocale = urlhash.getParam('locale'); |
| 199 | let urlLocaleCodes = []; |
| 200 | if (typeof urlLocale === 'string') { |
| 201 | urlLocaleCodes = urlLocale.split(',').map(s => s.trim()).filter(Boolean); |
| 202 | } |
| 203 | |
| 204 | // Choose the preferred locales in this order: |
| 205 | // 1. Locales stored in `_preferredLocaleCodes` |
| 206 | // 2. Locales included in the url hash |
| 207 | // 3. Locales detected by the browser |
| 208 | // 4. English (always fallback) |
| 209 | const requestedLocales = (this._preferredLocaleCodes || []) |
| 210 | .concat(urlLocaleCodes) |
| 211 | .concat(utilDetect().locales) // Locales preferred by the browser in priority order. |
| 212 | .concat(['en']); // Fallback to English since it's the only guaranteed complete language |
| 213 | |
| 214 | this._currLocaleCodes = this._getSupportedLocales(requestedLocales); |
| 215 | this._currLocaleCode = this._currLocaleCodes[0]; // First is highest priority locale; the rest are fallbacks |
| 216 | |
| 217 | const loadPromises = this._currLocaleCodes.map(locale => this._loadStringsAsync(locale)); |
| 218 | return Promise.all(loadPromises) |
| 219 | .then(() => this._localeChanged()); |
| 220 | } |
| 221 | |
| 222 | |
| 223 | /** |
no test coverage detected