Skip to content

Commit

Permalink
ENG-4201 Use default language instead of en for page titles
Browse files Browse the repository at this point in the history
Implement logic to get default language via languages API endpoint
  • Loading branch information
raxkaynan committed Sep 20, 2022
1 parent a10afc9 commit 11d2a68
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/env-bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ const ALL_TYPES = [
'language',
];

var coreBaseApi, componentManagerApi, clientId, clientSecret, apiUrlTable;
var coreBaseApi, componentManagerApi, clientId, clientSecret, apiUrlTable, defaultLang;

const componentDetailExtractors = {
page: (components) =>
components.map((c) => {
return { value: c.code, name: `${c.titles.en} (${c.code})` };
return { value: c.code, name: `${c.titles[defaultLang]} (${c.code})` };
}),
pageModel: (components) =>
components.map((c) => {
Expand Down Expand Up @@ -865,6 +865,15 @@ const getToken = async function () {
return res.data.access_token;
};

async function getDefaultLang() {
const response = await axios.get(apiUrlTable.language, {
withCredentials: true,
headers: { Authorization: `Bearer ${token}` },
});

return response.data.payload.find(lang => lang.isDefault).code;
}

async function getComponents (type, componentsToFetch) {
// Check if exists in cache
if (hasProperty(componentCache, type)) {
Expand Down Expand Up @@ -1223,7 +1232,7 @@ async function setupEnvironment (options) {

token = await getToken();


defaultLang = await getDefaultLang();
}

async function interactiveSession () {
Expand Down

0 comments on commit 11d2a68

Please sign in to comment.