From 11d2a6840a2e4a3c559a7708c3d491688b29fee3 Mon Sep 17 00:00:00 2001 From: Rax Canaan Layumas Date: Tue, 20 Sep 2022 18:28:57 +0800 Subject: [PATCH] ENG-4201 Use default language instead of en for page titles Implement logic to get default language via languages API endpoint --- lib/env-bundler.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/env-bundler.js b/lib/env-bundler.js index 079cb75..a17d84e 100644 --- a/lib/env-bundler.js +++ b/lib/env-bundler.js @@ -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) => { @@ -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)) { @@ -1223,7 +1232,7 @@ async function setupEnvironment (options) { token = await getToken(); - + defaultLang = await getDefaultLang(); } async function interactiveSession () {