Closed
Conversation
Signed-off-by: Grigorii K. Shartsev <[email protected]>
susnux
reviewed
Feb 1, 2025
Contributor
susnux
left a comment
There was a problem hiding this comment.
Over all very nice approach ✨
Comment on lines
+23
to
+29
| // Node.js runtime | ||
| if ('_nc_l10n_locale' in globalThis && globalThis._nc_l10n_locale) { | ||
| return globalThis._nc_l10n_locale | ||
| } | ||
|
|
||
| // Fallback to English | ||
| return 'en' |
Contributor
There was a problem hiding this comment.
globalThis always works in all contexts.
Suggested change
| // Node.js runtime | |
| if ('_nc_l10n_locale' in globalThis && globalThis._nc_l10n_locale) { | |
| return globalThis._nc_l10n_locale | |
| } | |
| // Fallback to English | |
| return 'en' | |
| return globalThis._nc_l10n_locale ?? 'en' |
Comment on lines
+6
to
+11
| declare global { | ||
| // eslint-disable-next-line camelcase, no-var | ||
| var _nc_l10n_locale: string | undefined | ||
| // eslint-disable-next-line camelcase, no-var | ||
| var _nc_l10n_language: string | undefined | ||
| } |
Contributor
There was a problem hiding this comment.
This will make it available also in exported typings.
Should probably be moved to a globals.d.ts file
Comment on lines
+61
to
+67
| // Node.js runtime | ||
| if ('_nc_l10n_language' in globalThis && globalThis._nc_l10n_language) { | ||
| return globalThis._nc_l10n_language | ||
| } | ||
|
|
||
| // Fallback to English | ||
| return 'en' |
Contributor
There was a problem hiding this comment.
Same here
Suggested change
| // Node.js runtime | |
| if ('_nc_l10n_language' in globalThis && globalThis._nc_l10n_language) { | |
| return globalThis._nc_l10n_language | |
| } | |
| // Fallback to English | |
| return 'en' | |
| return globalThis._nc_l10n_language ?? 'en' |
Comment on lines
+175
to
+176
| } catch { | ||
| // Error is probably a SyntaxError due to invalid response, this is handled by the next line |
Contributor
There was a problem hiding this comment.
This will remove useful information for debugging, instead "duplicate here"
Suggested change
| } catch { | |
| // Error is probably a SyntaxError due to invalid response, this is handled by the next line | |
| } catch (error) { | |
| throw new Error('Invalid content of translation bundle', { cause: error }) |
Comment on lines
+170
to
+174
| if (typeof bundle.translations === 'object') { | ||
| register(appName, bundle.translations) | ||
| return Promise.resolve(bundle).then(callback) | ||
| } | ||
| request.send() | ||
| }) | ||
|
|
||
| // load JSON translation bundle per AJAX | ||
| return promise | ||
| .then((result) => { | ||
| register(appName, result.translations) | ||
| return result | ||
| }) | ||
| .then(callback) | ||
| throw new Error('Invalid content of translation bundle') |
Contributor
There was a problem hiding this comment.
I personally prefer error handling instead of success handling
if (typeof bundle.translations !== 'object') {
throw new Error('Invalid content of translation bundle')
}
register(appName, bundle.translations)
return callback(bundle)
Contributor
Author
There was a problem hiding this comment.
I only wanted to change XHR with fetch here, without changing anything else
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves
Todo
windowwithglobalThis@nextcloud/routeronly when requiredXHRwithfetchmock-xmlhttprequestwithmsw