Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 11
Línea 151... Línea 151...
151
        };
151
        };
Línea 152... Línea 152...
152
 
152
 
153
        // Check if we can serve the string straight from M.str.
153
        // Check if we can serve the string straight from M.str.
154
        if (component in M.str && key in M.str[component]) {
154
        if (component in M.str && key in M.str[component]) {
155
            return buildReturn(new Promise((resolve) => {
155
            return buildReturn(new Promise((resolve) => {
156
                resolve(M.util.get_string(key, component, param, lang));
156
                resolve(M.util.get_string(key, component, param));
157
            }));
157
            }));
Línea 158... Línea 158...
158
        }
158
        }
159
 
159
 
160
        // Check if the string is in the browser's local storage.
160
        // Check if the string is in the browser's local storage.
161
        const cached = LocalStorage.get(cacheKey);
161
        const cached = LocalStorage.get(cacheKey);
162
        if (cached) {
162
        if (cached) {
163
            M.str[component] = {...M.str[component], [key]: cached};
163
            M.str[component] = {...M.str[component], [key]: cached};
164
            return buildReturn(new Promise((resolve) => {
164
            return buildReturn(new Promise((resolve) => {
165
                resolve(M.util.get_string(key, component, param, lang));
165
                resolve(M.util.get_string(key, component, param));
Línea 166... Línea 166...
166
            }));
166
            }));
167
        }
167
        }
168
 
168
 
169
        // Check if we've already loaded this string from the server.
169
        // Check if we've already loaded this string from the server.
170
        if (cacheKey in promiseCache) {
170
        if (cacheKey in promiseCache) {
171
            return buildReturn(promiseCache[cacheKey]).then(() => {
171
            return buildReturn(promiseCache[cacheKey]).then(() => {
172
                return M.util.get_string(key, component, param, lang);
172
                return M.util.get_string(key, component, param);
173
            });
173
            });
174
        } else {
174
        } else {
Línea 187... Línea 187...
187
                        // When we get the response from the server
187
                        // When we get the response from the server
188
                        // we should update M.str and the browser's
188
                        // we should update M.str and the browser's
189
                        // local storage before resolving this promise.
189
                        // local storage before resolving this promise.
190
                        M.str[component] = {...M.str[component], [key]: str};
190
                        M.str[component] = {...M.str[component], [key]: str};
191
                        LocalStorage.set(cacheKey, str);
191
                        LocalStorage.set(cacheKey, str);
192
                        resolve(M.util.get_string(key, component, param, lang));
192
                        resolve(M.util.get_string(key, component, param));
193
                    },
193
                    },
194
                    fail: reject
194
                    fail: reject
195
                });
195
                });
196
            }));
196
            }));
197
        }
197
        }