Skip to content

Commit ec4d91b

Browse files
committed
fix(locale): get list from retrieved locale and default to usen
1 parent 111d8d7 commit ec4d91b

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

packages/services/src/services/Locale/Locale.js

+18-7
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const _proxy = process.env.CORS_PROXY || '';
2020
* @type {string}
2121
* @private
2222
*/
23-
const _endpoint = `${_host}/common/v18/js/data/jsononly/locale`;
23+
const _endpoint = `${_proxy}${_host}/common/v18/js/data/jsononly/locale`;
2424

2525
/**
2626
* Locale API class with method of fetching user's locale for
@@ -59,7 +59,7 @@ class LocaleAPI {
5959
const lc = lang.split('-')[0];
6060

6161
if (cc && lc) {
62-
const list = await this.getList();
62+
const list = await this.getList(cc, lc);
6363
const verifiedCodes = this.verifyLocale(cc, lc, list);
6464

6565
// set the ipcInfo cookie
@@ -73,6 +73,9 @@ class LocaleAPI {
7373
/**
7474
* Get the country list of all supported countries and their languages
7575
*
76+
* @param {string} cc country code
77+
* @param {string} lc language code
78+
*
7679
* @returns {Promise <any>} promise object
7780
*
7881
* @example
@@ -82,16 +85,24 @@ class LocaleAPI {
8285
* const list = await LocaleAPI.getList();
8386
* }
8487
*/
85-
static async getList() {
86-
const url = `${_proxy}${_endpoint}/usen-locale.json`;
87-
88+
static async getList(cc, lc) {
8889
return await axios
89-
.get(url, {
90+
.get(`${_endpoint}/${cc}${lc}-locale.json`, {
9091
headers: {
9192
'Content-Type': 'application/json; charset=utf-8',
9293
},
9394
})
94-
.then(response => response.data);
95+
.then(response => response.data)
96+
.catch(async () => {
97+
//default to us-en locale if previous call fails
98+
return await axios
99+
.get(`${_endpoint}/usen-locale.json`, {
100+
headers: {
101+
'Content-Type': 'application/json; charset=utf-8',
102+
},
103+
})
104+
.then(response => response.data);
105+
});
95106
}
96107

97108
/**

packages/utilities/src/utilities/ipcinfoCookie/__tests__/ipcinfoCookie.test.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ import { ipcinfoCookie } from '../';
22

33
describe('ipcinfo cookie utility', () => {
44
it('should set the ipcInfo cookie', () => {
5+
const locale = { cc: 'us', lc: 'en' };
6+
57
const mockSet = jest.fn();
68
ipcinfoCookie.set = mockSet;
7-
ipcinfoCookie.set('US', 'en');
9+
ipcinfoCookie.set(locale);
810
expect(mockSet).toBeCalled();
911
});
1012

0 commit comments

Comments
 (0)