@salesforce/retail-react-app 1.1.0-dev.1 → 1.1.0-dev.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -143,10 +143,23 @@ const App = (props) => {
|
|
|
143
143
|
l10nConfig: site.l10n
|
|
144
144
|
})
|
|
145
145
|
|
|
146
|
+
// If the translation file exists, it'll be served directly from static folder (and won't reach this code here).
|
|
147
|
+
// However, if the file is missing, the App would render a 404 page.
|
|
148
|
+
const is404ForMissingTranslationFile = /\/static\/translations\/compiled\/[^.]+\.json$/.test(
|
|
149
|
+
location?.pathname
|
|
150
|
+
)
|
|
151
|
+
|
|
146
152
|
// Fetch the translation message data using the target locale.
|
|
147
153
|
const {data: messages} = useQuery({
|
|
148
|
-
queryKey: ['app', '
|
|
149
|
-
queryFn: () =>
|
|
154
|
+
queryKey: ['app', 'translations', 'messages', targetLocale],
|
|
155
|
+
queryFn: () => {
|
|
156
|
+
if (is404ForMissingTranslationFile) {
|
|
157
|
+
// Return early to prevent an infinite loop
|
|
158
|
+
// Otherwise, it'll continue to fetch the missing translation file again
|
|
159
|
+
return {}
|
|
160
|
+
}
|
|
161
|
+
return fetchTranslations(targetLocale)
|
|
162
|
+
},
|
|
150
163
|
enabled: isServer
|
|
151
164
|
})
|
|
152
165
|
|
package/app/utils/locale.js
CHANGED
|
@@ -40,7 +40,7 @@ export const fetchTranslations = async (locale) => {
|
|
|
40
40
|
} catch (err) {
|
|
41
41
|
console.error(err)
|
|
42
42
|
console.log(
|
|
43
|
-
'Loading empty messages, so that react-intl would fall back to the inline default messages'
|
|
43
|
+
'Translation not found. Loading empty messages, so that react-intl would fall back to the inline default messages'
|
|
44
44
|
)
|
|
45
45
|
return {}
|
|
46
46
|
}
|
package/app/utils/locale.test.js
CHANGED
|
@@ -72,6 +72,7 @@ describe('determineTargetLocale', () => {
|
|
|
72
72
|
})
|
|
73
73
|
|
|
74
74
|
describe('fetchTranslations', () => {
|
|
75
|
+
// The following two tests expect the compiled translation files in app/static/translations/compiled to exist
|
|
75
76
|
test('loading the target locale', async () => {
|
|
76
77
|
const messages = await fetchTranslations(supportedLocale)
|
|
77
78
|
expect(messages[testId2]).toBeDefined()
|
|
@@ -126,6 +127,7 @@ describe('getTargetLocale', () => {
|
|
|
126
127
|
windowSpy.mockImplementation(() => undefined)
|
|
127
128
|
|
|
128
129
|
const targetLocale = getTargetLocale({l10nConfig})
|
|
130
|
+
// We expect the compiled translation file in app/static/translations/compiled/en-XA to exist
|
|
129
131
|
const messages = await fetchTranslations(targetLocale)
|
|
130
132
|
// The app should still think its target locale is the default one
|
|
131
133
|
expect(targetLocale).toBe(DEFAULT_LOCALE)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce/retail-react-app",
|
|
3
|
-
"version": "1.1.0-dev.
|
|
3
|
+
"version": "1.1.0-dev.2",
|
|
4
4
|
"license": "See license in LICENSE",
|
|
5
5
|
"author": "cc-pwa-kit@salesforce.com",
|
|
6
6
|
"ccExtensibility": {
|
|
@@ -45,10 +45,10 @@
|
|
|
45
45
|
"@lhci/cli": "^0.11.0",
|
|
46
46
|
"@loadable/component": "^5.15.3",
|
|
47
47
|
"@peculiar/webcrypto": "^1.4.2",
|
|
48
|
-
"@salesforce/commerce-sdk-react": "1.1.0-dev.
|
|
49
|
-
"@salesforce/pwa-kit-dev": "3.1.0-preview.
|
|
50
|
-
"@salesforce/pwa-kit-react-sdk": "3.1.0-preview.
|
|
51
|
-
"@salesforce/pwa-kit-runtime": "3.1.0-preview.
|
|
48
|
+
"@salesforce/commerce-sdk-react": "1.1.0-dev.2",
|
|
49
|
+
"@salesforce/pwa-kit-dev": "3.1.0-preview.3",
|
|
50
|
+
"@salesforce/pwa-kit-react-sdk": "3.1.0-preview.3",
|
|
51
|
+
"@salesforce/pwa-kit-runtime": "3.1.0-preview.3",
|
|
52
52
|
"@tanstack/react-query": "^4.28.0",
|
|
53
53
|
"@tanstack/react-query-devtools": "^4.29.1",
|
|
54
54
|
"@testing-library/dom": "^9.0.1",
|
|
@@ -103,5 +103,5 @@
|
|
|
103
103
|
"overrides": {
|
|
104
104
|
"nwsapi": "2.2.2"
|
|
105
105
|
},
|
|
106
|
-
"gitHead": "
|
|
106
|
+
"gitHead": "3840c85ad3a5526ff6a54eb0bf65327d3aa72797"
|
|
107
107
|
}
|