diff --git a/assets/js/components/SiteAnalysisResult.js b/assets/js/components/SiteAnalysisResult.js index af66a8f0..10cb151c 100644 --- a/assets/js/components/SiteAnalysisResult.js +++ b/assets/js/components/SiteAnalysisResult.js @@ -19,14 +19,15 @@ class SiteAnalysisResult { /** * Create a site analysis result page with updated dom from api data * @param {Element} el + * @param {string} currentLocale */ - constructor(el) { + constructor(el, currentLocale) { this.el = el; /** @type {ResultRelativeTextData} */ this.resultRelativeTextData = resultRelativeTextData; - this._init(); + this._init(currentLocale); } /** @@ -34,9 +35,10 @@ class SiteAnalysisResult { * * Checks if an analysis results object exists. If yes, use it. * Otherwise, fetches data from server. - * + * + * @param {string} currentLocale */ - async _init() { + async _init(currentLocale) { const urlParams = new URLSearchParams(window.location.search); const langSwitchersElements = document.querySelectorAll(".language-switcher a.lang") const screenshotImgElement = document.querySelector(".result-screenshot") @@ -86,10 +88,16 @@ class SiteAnalysisResult { // update page size from ko to mo pageResultData.size = Math.round(pageResultData.size) / 1000; - // set page result title + // set page result title and message pageResultData.grade_title = this.resultRelativeTextData.verdictTitles[pageResultData.grade]; - pageResultData.grade_message = this.resultRelativeTextData.verdictMessages[pageResultData.grade]; + + // convert the date from an UTC string in to a human-readable string according to the current locale + const date = new Date(pageResultData.date) + pageResultData.date = Intl.DateTimeFormat(currentLocale, { + dateStyle: "full", + timeStyle: "medium", + }).format(date) // set page result params binary scores (0/1 : good/bad) pageResultData = { diff --git a/assets/js/index.js b/assets/js/index.js index 224eb157..ca17b037 100644 --- a/assets/js/index.js +++ b/assets/js/index.js @@ -7,9 +7,11 @@ import SiteAnalysisResult from "./components/SiteAnalysisResult"; // ------------------------------------------------------------------------- INIT APP function initApp() { + // pick the current locale from the DOM once the application starts: aavoid several picking in the different components + const currentLocale = document.getElementsByTagName("html")[0].getAttribute("lang") initMenu(); initCollapses(); - initPageResult(); + initPageResult(currentLocale); initSubmitUrlForm(); initButtonRemakeAnalysis(); initButtonShareURL(); @@ -47,11 +49,12 @@ function initCollapses() { /** * Init page result interactive data from api or url params + * @param {string} currentLocale */ -function initPageResult() { +function initPageResult(currentLocale) { const resultPageContentEl = document.querySelector(".js-result-container"); if (!resultPageContentEl) return; - new SiteAnalysisResult(resultPageContentEl); + new SiteAnalysisResult(resultPageContentEl, currentLocale); } /**