diff --git a/eds/blocks/knowledge-base-overview/knowledge-base-overview.js b/eds/blocks/knowledge-base-overview/knowledge-base-overview.js index 8e77441..28d8896 100644 --- a/eds/blocks/knowledge-base-overview/knowledge-base-overview.js +++ b/eds/blocks/knowledge-base-overview/knowledge-base-overview.js @@ -1,4 +1,4 @@ -import { getLibs, replaceText, getConfig } from './../../scripts/utils.js'; +import { getLibs, replaceText, getConfig, populateLocalizedTextFromListItems } from './../../scripts/utils.js'; import { KnowledgeBaseOverview } from './KnowledgeBaseOverview.js'; function declareKnowledgeBaseOverview() { @@ -40,6 +40,8 @@ export default async function init(el) { '{{search}}': 'Search', }; + populateLocalizedTextFromListItems(el, localizedText); + const deps = await Promise.all([ localizationPromises(localizedText, config), import(`${miloLibs}/features/spectrum-web-components/dist/theme.js`), diff --git a/eds/blocks/partner-news/partner-news.js b/eds/blocks/partner-news/partner-news.js index 936c5b7..7a2bbd5 100644 --- a/eds/blocks/partner-news/partner-news.js +++ b/eds/blocks/partner-news/partner-news.js @@ -1,4 +1,4 @@ -import { getLibs, replaceText, getConfig } from './../../scripts/utils.js'; +import { getLibs, replaceText, getConfig, populateLocalizedTextFromListItems } from './../../scripts/utils.js'; import { PartnerNews } from './PartnerNews.js'; function declarePartnerNews() { @@ -38,9 +38,11 @@ export default async function init(el) { '{{previous-month}}': 'Previous month', '{{results}}': 'Results', '{{search}}': 'Search', - '{{show-all}}': 'Show all' + '{{show-all}}': 'Show all', }; + populateLocalizedTextFromListItems(el, localizedText); + const deps = await Promise.all([ localizationPromises(localizedText, config), import(`${miloLibs}/features/spectrum-web-components/dist/theme.js`), diff --git a/eds/components/PartnerCards.js b/eds/components/PartnerCards.js index 657e9e8..613ac24 100644 --- a/eds/components/PartnerCards.js +++ b/eds/components/PartnerCards.js @@ -123,35 +123,33 @@ export class PartnerCards extends LitElement { this.blockData.title = titleEl.innerText.trim(); }, 'filter': (cols) => { - const [filterKeyEl, filterValueEl, filterTagsKeysEl, filterTagsValueEl] = cols; - const filterKey = filterKeyEl.innerText.trim().toLowerCase().replaceAll(' ', '-'); - const filterValue = filterValueEl.innerText.trim(); - const filterTagsKeys = Array.from(filterTagsKeysEl.querySelectorAll('li'), (li) => li.innerText.trim().toLowerCase()); - const filterTagsValue = Array.from(filterTagsValueEl.querySelectorAll('li'), (li) => li.innerText.trim()); + const [filterKeyEl, filterTagsKeysEl] = cols; + const filterKey = filterKeyEl.innerText.trim().toLowerCase().replace(/ /g, '-'); + const filterTagsKeys = Array.from(filterTagsKeysEl.querySelectorAll('li'), (li) => li.innerText.trim().toLowerCase().replace(/ /g, '-')); if (!filterKey || !filterTagsKeys.length) return; let filterObj = { key: filterKey, - value: filterValue, - tags: filterTagsKeys.map((tagKey, tagIndex) => ({ - key: tagKey.replaceAll(' ', '-'), - parentKey: filterKey, - value: filterTagsValue[tagIndex], - checked: false + value: this.blockData.localizedText[`{{${filterKey}}}`], + tags: filterTagsKeys.map((tagKey) => ({ + key: tagKey, + parentKey: filterKey, + value: this.blockData.localizedText[`{{${tagKey}}}`], + checked: false })) }; this.blockData.filters.push(filterObj); }, 'sort': (cols) => { - const [sortKeysEl, sortValuesEl] = cols; - const sortKeys = Array.from(sortKeysEl.querySelectorAll('li'), (li) => li.innerText.trim().toLowerCase()); - const sortValues = Array.from(sortValuesEl.querySelectorAll('li'), (li) => li.innerText.trim()); + const [sortKeysEl] = cols; + const sortKeys = Array.from(sortKeysEl.querySelectorAll('li'), (li) => li.innerText.trim().toLowerCase().replace(/ /g, '-')); - const sortItems = sortKeys.map((sortKey, sortIndex) => ({ - key: sortKey.endsWith('_default') ? sortKey.slice(0, -8) : sortKey, - value: sortValues[sortIndex] - })); + const sortItems = sortKeys.map((sortKey) => { + const key = sortKey.endsWith('_default') ? sortKey.slice(0, -8) : sortKey; + const value = this.blockData.localizedText[`{{${key}}}`]; + return { key, value }; + }); const defaultKey = sortKeys.find(key => key.endsWith('_default')).slice(0, -8) || sortKeys[0]; const defaultValue = sortItems.find(e => e.key === defaultKey).value; @@ -173,7 +171,7 @@ export class PartnerCards extends LitElement { const rows = Array.from(this.blockData.tableData); rows.forEach((row) => { const cols = Array.from(row.children); - const rowTitle = cols[0].innerText.trim().toLowerCase().replaceAll(' ', '-'); + const rowTitle = cols[0].innerText.trim().toLowerCase().replace(/ /g, '-'); const colsContent = cols.slice(1); if (blockDataActions[rowTitle]) blockDataActions[rowTitle](colsContent); }); diff --git a/eds/scripts/utils.js b/eds/scripts/utils.js index 4ac3747..918eead 100644 --- a/eds/scripts/utils.js +++ b/eds/scripts/utils.js @@ -55,3 +55,12 @@ export { createTag, localizeLink, getConfig }; const { replaceText } = await import(`${miloLibs}/features/placeholders.js`); export { replaceText }; + +export function populateLocalizedTextFromListItems(el, localizedText) { + const liList = Array.from(el.querySelectorAll('li')); + liList.forEach(liEl => { + let liContent = liEl.innerText.trim().toLowerCase().replace(/ /g, '-'); + if (liContent.endsWith('_default')) liContent = liContent.slice(0, -8); + localizedText[`{{${liContent}}}`] = liContent; + }); +} diff --git a/test/blocks/knowledge-base-overview/mocks/body.html b/test/blocks/knowledge-base-overview/mocks/body.html index 2f86f56..0635b8b 100644 --- a/test/blocks/knowledge-base-overview/mocks/body.html +++ b/test/blocks/knowledge-base-overview/mocks/body.html @@ -2,85 +2,109 @@
Title
Sample Title for Card Collection
+
+
+
+
Cards per page
+
6
+
Filter
-
Audience
-
Audience
-
    -
  1. Marketing
  2. -
  3. Sales
  4. -
  5. Practice Lead
  6. -
  7. Technical
  8. -
+
-
    -
  1. Marketing
  2. -
  3. Sales
  4. -
  5. Practice Lead
  6. -
  7. Technical
  8. -
+
Filter
-
Region
-
Region
-
    -
  1. Americas
  2. -
  3. Asia Pacific
  4. -
  5. EMEA
  6. -
  7. Japan
  8. -
+
-
    -
  1. Americas
  2. -
  3. Asia Pacific
  4. -
  5. Europe, Middle East & Africa
  6. -
  7. Japan
  8. -
+
Filter
-
product
-
Product
-
    -
  1. adobe-experience-manager
  2. -
  3. adobe-analytics
  4. -
  5. adobe-target
  6. -
+
-
    -
  1. Experience manager
  2. -
  3. Analytics
  4. -
  5. Target
  6. -
+
-
Sort
+
Filter
-
    -
  1. newest_default
  2. -
  3. oldest
  4. -
  5. a-z
  6. -
  7. z-a
  8. -
+
-
    -
  1. Date: newest
  2. -
  3. Date: oldest
  4. -
  5. Title: A-Z
  6. -
  7. Title: Z-A
  8. -
+ +
+
+
+
Sort
+
+
+
diff --git a/test/blocks/partner-news/mocks/body.html b/test/blocks/partner-news/mocks/body.html index 0e5cb3f..2468b1a 100644 --- a/test/blocks/partner-news/mocks/body.html +++ b/test/blocks/partner-news/mocks/body.html @@ -2,85 +2,109 @@
Title
Sample Title for Card Collection
+
+
+
+
Cards per page
+
6
+
Filter
-
Audience
-
Audience
-
    -
  1. Marketing
  2. -
  3. Sales
  4. -
  5. Practice Lead
  6. -
  7. Technical
  8. -
+
-
    -
  1. Marketing
  2. -
  3. Sales
  4. -
  5. Practice Lead
  6. -
  7. Technical
  8. -
+
Filter
-
Region
-
Region
-
    -
  1. Americas
  2. -
  3. Asia Pacific
  4. -
  5. EMEA
  6. -
  7. Japan
  8. -
+
-
    -
  1. Americas
  2. -
  3. Asia Pacific
  4. -
  5. Europe, Middle East & Africa
  6. -
  7. Japan
  8. -
+
Filter
-
product
-
Product
-
    -
  1. adobe-experience-manager
  2. -
  3. adobe-analytics
  4. -
  5. adobe-target
  6. -
+
-
    -
  1. Experience manager
  2. -
  3. Analytics
  4. -
  5. Target
  6. -
+
-
Sort
+
Filter
-
    -
  1. newest_default
  2. -
  3. oldest
  4. -
  5. a-z
  6. -
  7. z-a
  8. -
+
-
    -
  1. Date: newest
  2. -
  3. Date: oldest
  4. -
  5. Title: A-Z
  6. -
  7. Title: Z-A
  8. -
+ +
+
+
+
Sort
+
+
+