Skip to content
This repository was archived by the owner on Dec 14, 2023. It is now read-only.

Commit ef3da0c

Browse files
authored
Merge pull request #261 from ArayB/bugfix/dashboard-projects
Ensure en_US locale returns projects
2 parents 147372e + fbec1cd commit ef3da0c

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

src/dashboard/cd-dashboard-projects.vue

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<h2 class="cd-dashboard-projects__header visible-xs">{{ $t('Here are some projects you can try') }}</h2>
55
<hr class ="cd-dashboard-projects__divider visible-xs">
66
<div v-show="isDisplayable" class="cd-dashboard-projects__cards">
7-
<a class="cd-dashboard-projects__card" v-for="project in projects" :key="project.id"
7+
<a class="cd-dashboard-projects__card" v-for="project in projects" :key="project.id"
88
:href="`https://projects.raspberrypi.org/${locale}/projects/${project.attributes.repositoryName}`"
99
v-ga-track-exit-nav>
1010
<img :src="project.attributes.content.heroImage" />
@@ -41,16 +41,25 @@
4141
userLocale() {
4242
const langCookie = LocaleService.getUserLocale();
4343
if (langCookie) {
44-
return langCookie.replace(/"/g, '').replace('_', '-');
44+
let formattedLocale = langCookie.replace(/"/g, '').replace('_', '-');
45+
if (/en-.*/.test(formattedLocale)) {
46+
formattedLocale = 'en';
47+
}
48+
return formattedLocale;
4549
}
4650
return 'en';
4751
},
4852
},
4953
methods: {
5054
async loadProjects(locale = 'en') {
51-
const projects = (await ProjectsService.list(locale, { order: 'desc' })).body;
52-
if (projects) {
53-
this.projects = projects.data.slice(0, 3);
55+
try {
56+
const projects = (await ProjectsService.list(locale, { order: 'desc' })).body;
57+
if (projects) {
58+
this.projects = projects.data.slice(0, 3);
59+
}
60+
} catch (err) {
61+
// If the request fails it is most likely to be the
62+
// locale and we will then fall back to the 'en' locale
5463
}
5564
},
5665
},

test/unit/specs/dashboard/cd-dashboard-projects.spec.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,17 @@ describe('Dashboard children component', () => {
6969
expect(MockLocaleService.getUserLocale).to.have.been.calledOnce;
7070
expect(res).to.equal('fr-FR');
7171
});
72+
it('should return en when cookie locale is en_US', () => {
73+
// ARRANGE
74+
MockLocaleService.getUserLocale.returns('"en_US"');
75+
76+
// EXECUTE
77+
const res = vm.userLocale;
78+
79+
// ASSERT
80+
expect(MockLocaleService.getUserLocale).to.have.been.calledOnce;
81+
expect(res).to.equal('en');
82+
});
7283
});
7384
});
7485

0 commit comments

Comments
 (0)