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

Method _loadStringsAsync

modules/core/LocalizationSystem.js:233–268  ·  view source on GitHub ↗

* _loadStringsAsync * Returns a Promise to load the strings for the requested locale * Note that this returns a `Promise.allSettled` because some of these may * fail/reject if a particular language pack doesn't exist. * (For example `core.zh-CN.min.json` exists but `imagery.zh-CC.min.j

(locale)

Source from the content-addressed store, hash-verified

231 * @return {Promise} Promise resolved when all string loading has settled
232 */
233 _loadStringsAsync(locale) {
234 if (locale.toLowerCase() === 'en-us') { // `en-US` strings are stored as `en`
235 locale = 'en';
236 }
237
238 const cache = this._cache;
239 if (cache[locale]) { // already loaded
240 return Promise.resolve();
241 } else {
242 cache[locale] = {};
243 }
244
245 // Add the language packs to the AssetSystem's list of sources
246 const assets = this.context.systems.assets;
247 const origin = assets.origin; // 'local' or 'latest'
248 const sources = assets.sources[origin];
249 if (!sources) {
250 return Promise.reject(`Unknown origin "${origin}"`); // shouldn't happen
251 }
252
253 const loadPromises = [];
254 for (const scope of this._scopes) {
255 const key = `l10n_${scope}_${locale}`;
256 if (!sources[key]) {
257 sources[key] = `data/l10n/${scope}.${locale}.min.json`;
258 }
259 const prom = assets.loadAssetAsync(key)
260 .then(data => {
261 cache[locale][scope] = data[locale];
262 });
263
264 loadPromises.push(prom);
265 }
266
267 return Promise.allSettled(loadPromises);
268 }
269
270
271 /**

Callers 1

selectLocaleAsyncMethod · 0.95

Calls 1

loadAssetAsyncMethod · 0.80

Tested by

no test coverage detected