MCPcopy Create free account
hub / github.com/facebook/Rapid / selectLocaleAsync

Method selectLocaleAsync

modules/core/LocalizationSystem.js:196–220  ·  view source on GitHub ↗

* _selectLocale * Returns a Promise to select the locale. * @return {Promise} Promise resolved when the locale has been selected and strings loaded

()

Source from the content-addressed store, hash-verified

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 /**

Callers 2

initAsyncMethod · 0.95
_hashchangeMethod · 0.95

Calls 7

_getSupportedLocalesMethod · 0.95
_loadStringsAsyncMethod · 0.95
_localeChangedMethod · 0.95
utilDetectFunction · 0.90
filterMethod · 0.80
splitMethod · 0.80
getParamMethod · 0.45

Tested by

no test coverage detected