Skip to content

Commit a2ac150

Browse files
authored
Update locale in all view routing hooks. (#974)
Resolves: rdar://160500944
1 parent a8d6e85 commit a2ac150

File tree

5 files changed

+25
-0
lines changed

5 files changed

+25
-0
lines changed

src/views/NotFound.vue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
</template>
1616

1717
<script>
18+
import { updateLocale } from 'theme/utils/i18n-utils';
1819
import GenericError from 'theme/components/GenericError.vue';
1920
import AppStore from 'docc-render/stores/AppStore';
2021
@@ -24,5 +25,13 @@ export default {
2425
created() {
2526
AppStore.setAllLocalesAreAvailable();
2627
},
28+
beforeRouteEnter(to, from, next) {
29+
next((vm) => {
30+
updateLocale(to.params.locale, vm);
31+
});
32+
},
33+
beforeRouteUpdate(to) {
34+
updateLocale(to.params.locale, this);
35+
},
2736
};
2837
</script>

src/views/ServerError.vue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
</template>
1414

1515
<script>
16+
import { updateLocale } from 'theme/utils/i18n-utils';
1617
import GenericError from 'theme/components/GenericError.vue';
1718
import AppStore from 'docc-render/stores/AppStore';
1819
@@ -22,5 +23,13 @@ export default {
2223
created() {
2324
AppStore.setAllLocalesAreAvailable();
2425
},
26+
beforeRouteEnter(to, from, next) {
27+
next((vm) => {
28+
updateLocale(to.params.locale, vm);
29+
});
30+
},
31+
beforeRouteUpdate(to) {
32+
updateLocale(to.params.locale, this);
33+
},
2534
};
2635
</script>

src/views/Topic.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
</template>
2222

2323
<script>
24+
import { updateLocale } from 'theme/utils/i18n-utils';
2425
import {
2526
fetchDataForRouteEnter,
2627
shouldFetchDataForRouteUpdate,
@@ -80,13 +81,15 @@ export default {
8081
return;
8182
}
8283
fetchDataForRouteEnter(to, from, next).then(data => next((vm) => {
84+
updateLocale(to.params.locale, vm);
8385
vm.topicData = data; // eslint-disable-line no-param-reassign
8486
})).catch(next);
8587
},
8688
beforeRouteUpdate(to, from, next) {
8789
if (shouldFetchDataForRouteUpdate(to, from)) {
8890
fetchDataForRouteEnter(to, from, next).then((data) => {
8991
this.topicData = data;
92+
updateLocale(to.params.locale, this);
9093
next();
9194
}).catch(next);
9295
} else {

src/views/TutorialsOverview.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
</template>
1414

1515
<script>
16+
import { updateLocale } from 'theme/utils/i18n-utils';
1617
import {
1718
fetchDataForRouteEnter,
1819
shouldFetchDataForRouteUpdate,
@@ -54,13 +55,15 @@ export default {
5455
}
5556
5657
fetchDataForRouteEnter(to, from, next).then(data => next((vm) => {
58+
updateLocale(to.params.locale, vm);
5759
vm.topicData = data; // eslint-disable-line no-param-reassign
5860
})).catch(next);
5961
},
6062
beforeRouteUpdate(to, from, next) {
6163
if (shouldFetchDataForRouteUpdate(to, from)) {
6264
fetchDataForRouteEnter(to, from, next).then((data) => {
6365
this.topicData = data;
66+
updateLocale(to.params.locale, this);
6467
next();
6568
}).catch(next);
6669
} else {

tests/unit/setup-utils/SwiftDocCRenderRouter.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import FetchError from 'docc-render/errors/FetchError';
1515

1616
jest.mock('docc-render/utils/theme-settings', () => ({
1717
baseUrl: '/',
18+
getSetting: jest.fn(),
1819
}));
1920

2021
const mockInstance = {

0 commit comments

Comments
 (0)