|
162 | 162 | const localStorageAvailable = () => {
|
163 | 163 | if (hasLocalStorageSupport !== null) return hasLocalStorageSupport;
|
164 | 164 | try {
|
165 |
| - hasLocalStorageSupport = window !== 'undefined' && window.localStorage !== null; |
| 165 | + hasLocalStorageSupport = typeof window !== 'undefined' && window.localStorage !== null; |
| 166 | + if (!hasLocalStorageSupport) { |
| 167 | + return false; |
| 168 | + } |
166 | 169 | const testKey = 'i18next.translate.boo';
|
167 | 170 | window.localStorage.setItem(testKey, 'foo');
|
168 | 171 | window.localStorage.removeItem(testKey);
|
|
178 | 181 | let {
|
179 | 182 | lookupLocalStorage
|
180 | 183 | } = _ref;
|
181 |
| - if (localStorageAvailable() && lookupLocalStorage) { |
| 184 | + if (lookupLocalStorage && localStorageAvailable()) { |
182 | 185 | return window.localStorage.getItem(lookupLocalStorage) || undefined; // Undefined ensures type consistency with the previous version of this function
|
183 | 186 | }
|
| 187 | + |
184 | 188 | return undefined;
|
185 | 189 | },
|
186 | 190 | // Deconstruct the options object and extract the lookupLocalStorage property
|
187 | 191 | cacheUserLanguage(lng, _ref2) {
|
188 | 192 | let {
|
189 | 193 | lookupLocalStorage
|
190 | 194 | } = _ref2;
|
191 |
| - if (localStorageAvailable() && lookupLocalStorage) { |
| 195 | + if (lookupLocalStorage && localStorageAvailable()) { |
192 | 196 | window.localStorage.setItem(lookupLocalStorage, lng);
|
193 | 197 | }
|
194 | 198 | }
|
|
198 | 202 | const sessionStorageAvailable = () => {
|
199 | 203 | if (hasSessionStorageSupport !== null) return hasSessionStorageSupport;
|
200 | 204 | try {
|
201 |
| - hasSessionStorageSupport = window !== 'undefined' && window.sessionStorage !== null; |
| 205 | + hasSessionStorageSupport = typeof window !== 'undefined' && window.sessionStorage !== null; |
| 206 | + if (!hasSessionStorageSupport) { |
| 207 | + return false; |
| 208 | + } |
202 | 209 | const testKey = 'i18next.translate.boo';
|
203 | 210 | window.sessionStorage.setItem(testKey, 'foo');
|
204 | 211 | window.sessionStorage.removeItem(testKey);
|
|
379 | 386 | if (this.services && this.services.languageUtils && this.services.languageUtils.getBestMatchFromCodes) return detected; // new i18next v19.5.0
|
380 | 387 | return detected.length > 0 ? detected[0] : null; // a little backward compatibility
|
381 | 388 | }
|
| 389 | + |
382 | 390 | cacheUserLanguage(lng) {
|
383 | 391 | let caches = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.options.caches;
|
384 | 392 | if (!caches) return;
|
|
0 commit comments