diff --git a/modules/app/src/main/resources/admin/tools/main/main.xml b/modules/app/src/main/resources/admin/tools/main/main.xml index 995b7b218e..b42d99fb9d 100644 --- a/modules/app/src/main/resources/admin/tools/main/main.xml +++ b/modules/app/src/main/resources/admin/tools/main/main.xml @@ -10,7 +10,6 @@ collaboration content export - i18n license styles com.enonic.xp.app.main:launcher diff --git a/modules/app/src/main/resources/apis/i18n/i18n.js b/modules/app/src/main/resources/apis/i18n/i18n.js deleted file mode 100644 index a8709ab8ec..0000000000 --- a/modules/app/src/main/resources/apis/i18n/i18n.js +++ /dev/null @@ -1,36 +0,0 @@ -const i18n = require('/lib/xp/i18n'); -const admin = require('/lib/xp/admin'); - -const processRequest = function (req) { - const customBundles = req.params && req.params.bundles ? req.params.bundles.split(',') : []; - return { - status: 200, - contentType: 'application/json', - body: getPhrases(customBundles) - } -}; - -exports.get = processRequest; -exports.post = processRequest; - -const getPhrases = function(customBundles) { - const locales = admin.getLocales(); - const phrases = {}; - let bundles = ['i18n/common', 'i18n/common_wcag', 'i18n/phrases', 'i18n/dialogs', 'i18n/wcag']; - if (customBundles.length) { - bundles = bundles.concat(customBundles); - } - - bundles.forEach(function (bundle) { - const bundlePhrases = i18n.getPhrases(locales, [bundle]); - for (const key in bundlePhrases) { - if (bundlePhrases.hasOwnProperty(key)) { - // This should be ok with the hasOwnProperty check above - /* eslint-disable-next-line */ - phrases[key] = bundlePhrases[key]; - } - } - }); - - return phrases; -}; diff --git a/modules/app/src/main/resources/apis/i18n/i18n.xml b/modules/app/src/main/resources/apis/i18n/i18n.xml deleted file mode 100644 index f28a669188..0000000000 --- a/modules/app/src/main/resources/apis/i18n/i18n.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - role:system.authenticated - - diff --git a/modules/app/src/main/resources/assets/js/main.ts b/modules/app/src/main/resources/assets/js/main.ts index e838b0949e..da185338cb 100644 --- a/modules/app/src/main/resources/assets/js/main.ts +++ b/modules/app/src/main/resources/assets/js/main.ts @@ -22,7 +22,6 @@ import {ConnectionDetector} from '@enonic/lib-admin-ui/system/ConnectionDetector import {AppHelper} from '@enonic/lib-admin-ui/util/AppHelper'; import {CONFIG} from '@enonic/lib-admin-ui/util/Config'; import {i18n} from '@enonic/lib-admin-ui/util/Messages'; -import {i18nInit} from '@enonic/lib-admin-ui/util/MessagesInitializer'; import * as $ from 'jquery'; import {AppContext} from 'lib-contentstudio/app/AppContext'; import {ContentDeletePromptEvent} from 'lib-contentstudio/app/browse/ContentDeletePromptEvent'; @@ -66,6 +65,7 @@ import {ContentAppHelper} from 'lib-contentstudio/app/wizard/ContentAppHelper'; import {ContentWizardPanelParams} from 'lib-contentstudio/app/wizard/ContentWizardPanelParams'; import * as Q from 'q'; import {JSONObject} from '@enonic/lib-admin-ui/types'; +import {Messages} from '@enonic/lib-admin-ui/util/Messages'; // Dynamically import and execute all input types, since they are used // on-demand, when parsing XML schemas and has not real usage in app @@ -643,10 +643,11 @@ function initProjectContext(application: Application): Q.Promise { if (!configScriptId) { throw Error('Unable to fetch app config'); } - CONFIG.setConfig(JSON.parse(document.getElementById(configScriptId).innerText) as JSONObject); - // eslint-disable-next-line @typescript-eslint/no-unsafe-argument - await i18nInit(CONFIG.getString('services.i18nUrl')); + CONFIG.setConfig(JSON.parse(document.getElementById(configScriptId).innerText) as JSONObject); + if (Messages.isEmpty()) { + Messages.setMessages(JSON.parse(CONFIG.getString('phrasesAsJson')) as object); + } const body = Body.get(); diff --git a/modules/app/src/main/resources/lib/config.js b/modules/app/src/main/resources/lib/config.js index d59ea19edf..1343e0b37d 100644 --- a/modules/app/src/main/resources/lib/config.js +++ b/modules/app/src/main/resources/lib/config.js @@ -3,6 +3,24 @@ const admin = require('/lib/xp/admin'); const portal = require('/lib/xp/portal'); const contextLib = require('/lib/xp/context'); +const i18n = require('/lib/xp/i18n'); + +function getPhrases() { + const locales = admin.getLocales(); + const phrases = {}; + const bundles = ['i18n/common', 'i18n/common_wcag', 'i18n/phrases', 'i18n/dialogs', 'i18n/wcag', 'i18n/page-editor']; + + bundles.forEach(function (bundle) { + const bundlePhrases = i18n.getPhrases(locales, [bundle]); + for (const key in bundlePhrases) { + if (Object.prototype.hasOwnProperty.call(bundlePhrases, key)) { + phrases[key] = bundlePhrases[key]; + } + } + }); + + return phrases; +} function getConfig() { const context = contextLib.get(); @@ -35,9 +53,6 @@ function getConfig() { contentUrl: portal.apiUrl({ api: 'content', }), - i18nUrl: portal.apiUrl({ - api: 'i18n', - }), licenseUrl: portal.apiUrl({ api: 'license', }), @@ -60,6 +75,7 @@ function getConfig() { application: 'admin', api: 'widget', }), + phrasesAsJson: JSON.stringify(getPhrases(), null, 4), }; } diff --git a/modules/lib/src/main/resources/assets/js/page-editor/LiveEditPage.ts b/modules/lib/src/main/resources/assets/js/page-editor/LiveEditPage.ts index 61686e1aab..3f1befc7d4 100644 --- a/modules/lib/src/main/resources/assets/js/page-editor/LiveEditPage.ts +++ b/modules/lib/src/main/resources/assets/js/page-editor/LiveEditPage.ts @@ -1,4 +1,3 @@ -import {i18nInit} from '@enonic/lib-admin-ui/util/MessagesInitializer'; import {ObjectHelper} from '@enonic/lib-admin-ui/ObjectHelper'; import {Body} from '@enonic/lib-admin-ui/dom/Body'; import {PageView, PageViewBuilder} from './PageView'; @@ -69,6 +68,7 @@ import {ResetComponentViewEvent} from './event/incoming/manipulation/ResetCompon import {PageStateEvent} from './event/incoming/common/PageStateEvent'; import {PageState} from '../app/wizard/page/PageState'; import {PageBuilder} from '../app/page/Page'; +import {Messages} from '@enonic/lib-admin-ui/util/Messages'; export class LiveEditPage { @@ -141,6 +141,10 @@ export class LiveEditPage { } CONFIG.setConfig(event.getConfig()); + if (Messages.isEmpty()) { + Messages.setMessages(JSON.parse(CONFIG.getString('phrasesAsJson')) as object); + } + ProjectContext.get().setProject(Project.fromJson(event.getProjectJson())); PageState.setState(event.getPageJson() ? new PageBuilder().fromJson(event.getPageJson()).build() : null); @@ -152,9 +156,7 @@ export class LiveEditPage { ContentContext.get().setContent(content); }); - const initPromise: Q.Promise = i18nInit(CONFIG.getString('services.i18nUrl'), ['i18n/page-editor']); - - Q.all([initPromise, contentPromise]).then(() => { + Q.all([contentPromise]).then(() => { const body = Body.get().loadExistingChildren(); try { this.pageView = new PageViewBuilder()