From 98b3a1c738cf181e3a6f57a365af24605d2bd6ef Mon Sep 17 00:00:00 2001 From: soupette Date: Wed, 9 Jun 2021 11:22:23 +0200 Subject: [PATCH 1/2] Load strapi plugins translations Signed-off-by: soupette --- examples/getstarted/admin/admin.config.js | 13 ++++ packages/core/admin/admin/src/StrapiApp.js | 77 ++++++++++++------- packages/core/admin/admin/src/admin.config.js | 7 ++ packages/core/admin/admin/src/index.js | 17 +++- .../admin/admin/src/tests/StrapiApp.test.js | 15 ++-- .../core/content-manager/admin/src/index.js | 31 +++++++- .../content-type-builder/admin/src/index.js | 31 +++++++- packages/core/email/admin/src/index.js | 31 +++++++- packages/core/upload/admin/src/index.js | 31 +++++++- .../plugins/documentation/admin/src/index.js | 31 +++++++- packages/plugins/graphql/admin/src/index.js | 27 +++++++ packages/plugins/i18n/admin/src/index.js | 31 +++++++- packages/plugins/sentry/admin/src/index.js | 31 +++++++- .../users-permissions/admin/src/index.js | 31 +++++++- 14 files changed, 354 insertions(+), 50 deletions(-) create mode 100644 examples/getstarted/admin/admin.config.js create mode 100644 packages/core/admin/admin/src/admin.config.js diff --git a/examples/getstarted/admin/admin.config.js b/examples/getstarted/admin/admin.config.js new file mode 100644 index 0000000000..7c47030570 --- /dev/null +++ b/examples/getstarted/admin/admin.config.js @@ -0,0 +1,13 @@ +module.exports = { + webpack: (config, webpack) => { + // Note: we provide webpack above so you should not `require` it + // Perform customizations to webpack config + // Important: return the modified config + return config; + }, + app: config => { + console.log(config); + + return config; + }, +}; diff --git a/packages/core/admin/admin/src/StrapiApp.js b/packages/core/admin/admin/src/StrapiApp.js index 255b22814c..c4a8ffb649 100644 --- a/packages/core/admin/admin/src/StrapiApp.js +++ b/packages/core/admin/admin/src/StrapiApp.js @@ -17,9 +17,6 @@ import GlobalStyle from './components/GlobalStyle'; import Notifications from './components/Notifications'; import themes from './themes'; -// TODO -import translations from './translations'; - window.strapi = { backendURL: process.env.STRAPI_ADMIN_BACKEND_URL, }; @@ -32,16 +29,15 @@ const queryClient = new QueryClient({ }, }); -const appLocales = Object.keys(translations); - class StrapiApp { - constructor({ appPlugins, library, middlewares, reducers }) { + constructor({ appPlugins, library, locales, middlewares, reducers }) { + this.appLocales = ['en', ...locales.filter(loc => loc !== 'en')]; this.appPlugins = appPlugins || {}; this.library = library; this.middlewares = middlewares; this.plugins = {}; this.reducers = reducers; - this.translations = translations; + this.translations = {}; this.hooksDict = {}; } @@ -105,20 +101,52 @@ class StrapiApp { return this.plugins[pluginId]; }; - // FIXME - registerPluginTranslations(pluginId, trads) { - const pluginTranslations = appLocales.reduce((acc, currentLanguage) => { - const currentLocale = trads[currentLanguage]; + async loadAdminTrads() { + const arrayOfPromises = this.appLocales.map(locale => { + return import(/* webpackChunkName: "[request]" */ `./translations/${locale}.json`) + .then(({ default: data }) => { + return { data, locale }; + }) + .catch(err => { + // TODO + console.log(err); + }); + }); + const adminLocales = await Promise.all(arrayOfPromises); - if (currentLocale) { - const localeprefixedWithPluginId = Object.keys(currentLocale).reduce((acc2, current) => { - acc2[`${pluginId}.${current}`] = currentLocale[current]; + this.translations = adminLocales.reduce((acc, current) => { + acc[current.locale] = current.data; - return acc2; - }, {}); + return acc; + }, {}); - acc[currentLanguage] = localeprefixedWithPluginId; - } + return Promise.resolve(); + } + + async loadTrads() { + const arrayOfPromises = Object.keys(this.appPlugins) + .map(plugin => { + const registerTrads = this.appPlugins[plugin].registerTrads; + + if (registerTrads) { + return registerTrads({ locales: this.appLocales }); + } + + return null; + }) + .filter(a => a); + + const pluginsTrads = await Promise.all(arrayOfPromises); + const mergedTrads = pluginsTrads.reduce((acc, currentPluginTrads) => { + const pluginTrads = currentPluginTrads.reduce((acc1, current) => { + acc1[current.locale] = current.data; + + return acc1; + }, {}); + + Object.keys(pluginTrads).forEach(locale => { + acc[locale] = { ...acc[locale], ...pluginTrads[locale] }; + }); return acc; }, {}); @@ -126,19 +154,16 @@ class StrapiApp { this.translations = Object.keys(this.translations).reduce((acc, current) => { acc[current] = { ...this.translations[current], - ...(pluginTranslations[current] || {}), + ...(mergedTrads[current] || {}), }; return acc; }, {}); + + return Promise.resolve(); } registerPlugin = pluginConf => { - // FIXME - // Translations should be loaded differently - // This is a temporary fix - this.registerPluginTranslations(pluginConf.id, pluginConf.trads); - const plugin = Plugin(pluginConf); this.plugins[plugin.pluginId] = plugin; @@ -204,5 +229,5 @@ class StrapiApp { } } -export default ({ appPlugins, library, middlewares, reducers }) => - new StrapiApp({ appPlugins, library, middlewares, reducers }); +export default ({ appPlugins, library, locales, middlewares, reducers }) => + new StrapiApp({ appPlugins, library, locales, middlewares, reducers }); diff --git a/packages/core/admin/admin/src/admin.config.js b/packages/core/admin/admin/src/admin.config.js new file mode 100644 index 0000000000..57b6ec8bb1 --- /dev/null +++ b/packages/core/admin/admin/src/admin.config.js @@ -0,0 +1,7 @@ +module.exports = { + app: config => { + console.log(config); + + return config; + }, +}; diff --git a/packages/core/admin/admin/src/index.js b/packages/core/admin/admin/src/index.js index 1bd858f339..3789770c5a 100644 --- a/packages/core/admin/admin/src/index.js +++ b/packages/core/admin/admin/src/index.js @@ -1,22 +1,37 @@ import ReactDOM from 'react-dom'; import StrapiApp from './StrapiApp'; import { Components, Fields, Middlewares, Reducers } from './core/apis'; +import appCustomisations from './admin.config'; import plugins from './plugins'; import appReducers from './reducers'; +const appConfig = { + locales: [], +}; + +const customConfig = appCustomisations.app(appConfig); + const library = { components: Components(), fields: Fields(), }; const middlewares = Middlewares(); const reducers = Reducers({ appReducers }); -const app = StrapiApp({ appPlugins: plugins, library, middlewares, reducers }); +const app = StrapiApp({ + appPlugins: plugins, + library, + locales: customConfig.locales, + middlewares, + reducers, +}); const MOUNT_NODE = document.getElementById('app'); const run = async () => { + await app.loadAdminTrads(); await app.initialize(); await app.boot(); + await app.loadTrads(); ReactDOM.render(app.render(), MOUNT_NODE); }; diff --git a/packages/core/admin/admin/src/tests/StrapiApp.test.js b/packages/core/admin/admin/src/tests/StrapiApp.test.js index 6519e5b7d0..6dd58db2ae 100644 --- a/packages/core/admin/admin/src/tests/StrapiApp.test.js +++ b/packages/core/admin/admin/src/tests/StrapiApp.test.js @@ -6,10 +6,11 @@ import appReducers from '../reducers'; const library = { fields: {}, components: {} }; const middlewares = { middlewares: [] }; const reducers = { reducers: appReducers }; +const locales = []; describe('ADMIN | StrapiApp', () => { it('should render the app without plugins', () => { - const app = StrapiApp({ middlewares, reducers, library }); + const app = StrapiApp({ middlewares, reducers, library, locales }); const { container } = render(app.render()); expect(container.firstChild).toMatchInlineSnapshot(` @@ -43,7 +44,7 @@ describe('ADMIN | StrapiApp', () => { }); it('should create a valid store', () => { - const app = StrapiApp({ middlewares, reducers, library }); + const app = StrapiApp({ middlewares, reducers, library, locales }); const store = app.createStore(); @@ -52,7 +53,7 @@ describe('ADMIN | StrapiApp', () => { describe('Hook api', () => { it('runs the "moto" hooks in series', () => { - const app = StrapiApp({ middlewares, reducers, library }); + const app = StrapiApp({ middlewares, reducers, library, locales }); app.createHook('hello'); app.createHook('moto'); @@ -70,7 +71,7 @@ describe('ADMIN | StrapiApp', () => { }); it('runs the "moto" hooks in series asynchronously', async () => { - const app = StrapiApp({ middlewares, reducers, library }); + const app = StrapiApp({ middlewares, reducers, library, locales }); app.createHook('hello'); app.createHook('moto'); @@ -88,7 +89,7 @@ describe('ADMIN | StrapiApp', () => { }); it('runs the "moto" hooks in waterfall', () => { - const app = StrapiApp({ middlewares, reducers, library }); + const app = StrapiApp({ middlewares, reducers, library, locales }); app.createHook('hello'); app.createHook('moto'); @@ -104,7 +105,7 @@ describe('ADMIN | StrapiApp', () => { }); it('runs the "moto" hooks in waterfall asynchronously', async () => { - const app = StrapiApp({ middlewares, reducers, library }); + const app = StrapiApp({ middlewares, reducers, library, locales }); app.createHook('hello'); app.createHook('moto'); @@ -120,7 +121,7 @@ describe('ADMIN | StrapiApp', () => { }); it('runs the "moto" hooks in parallel', async () => { - const app = StrapiApp({ middlewares, reducers, library }); + const app = StrapiApp({ middlewares, reducers, library, locales }); app.createHook('hello'); app.createHook('moto'); diff --git a/packages/core/content-manager/admin/src/index.js b/packages/core/content-manager/admin/src/index.js index c8de549c2a..adc2e54210 100644 --- a/packages/core/content-manager/admin/src/index.js +++ b/packages/core/content-manager/admin/src/index.js @@ -9,7 +9,7 @@ import pluginPkg from '../../package.json'; import pluginId from './pluginId'; import pluginLogo from './assets/images/logo.svg'; import reducers from './reducers'; -import trads from './translations'; +// import trads from './translations'; const pluginDescription = pluginPkg.strapi.description || pluginPkg.description; const icon = pluginPkg.strapi.icon; @@ -31,8 +31,35 @@ export default { isRequired: pluginPkg.strapi.required || false, name, pluginLogo, - trads, + // trads, }); }, boot() {}, + async registerTrads({ locales }) { + const importedTrads = await Promise.all( + locales.map(locale => { + return import( + /* webpackChunkName: "content-manager-translation-[request]" */ `./translations/${locale}.json` + ) + .then(({ default: data }) => { + return { + data: Object.keys(data).reduce((acc, current) => { + acc[`${pluginId}.${current}`] = data[current]; + + return acc; + }, {}), + locale, + }; + }) + .catch(() => { + return { + data: {}, + locale, + }; + }); + }) + ); + + return Promise.resolve(importedTrads); + }, }; diff --git a/packages/core/content-type-builder/admin/src/index.js b/packages/core/content-type-builder/admin/src/index.js index a8d309c7ec..2074a9695b 100644 --- a/packages/core/content-type-builder/admin/src/index.js +++ b/packages/core/content-type-builder/admin/src/index.js @@ -7,7 +7,7 @@ import pluginPkg from '../../package.json'; import pluginLogo from './assets/images/logo.svg'; -import trads from './translations'; +// import trads from './translations'; import pluginPermissions from './permissions'; import pluginId from './pluginId'; import reducers from './reducers'; @@ -28,7 +28,7 @@ export default { isReady: true, name, pluginLogo, - trads, + // trads, menu: { pluginsSectionLinks: [ { @@ -50,4 +50,31 @@ export default { }); }, boot() {}, + async registerTrads({ locales }) { + const importedTrads = await Promise.all( + locales.map(locale => { + return import( + /* webpackChunkName: "content-type-builder-translation-[request]" */ `./translations/${locale}.json` + ) + .then(({ default: data }) => { + return { + data: Object.keys(data).reduce((acc, current) => { + acc[`${pluginId}.${current}`] = data[current]; + + return acc; + }, {}), + locale, + }; + }) + .catch(() => { + return { + data: {}, + locale, + }; + }); + }) + ); + + return Promise.resolve(importedTrads); + }, }; diff --git a/packages/core/email/admin/src/index.js b/packages/core/email/admin/src/index.js index d54eaf145f..4fca43faaa 100644 --- a/packages/core/email/admin/src/index.js +++ b/packages/core/email/admin/src/index.js @@ -11,7 +11,7 @@ import pluginPkg from '../../package.json'; import pluginId from './pluginId'; import pluginLogo from './assets/images/logo.svg'; import pluginPermissions from './permissions'; -import trads from './translations'; +// import trads from './translations'; import getTrad from './utils/getTrad'; import SettingsPage from './pages/Settings'; @@ -29,7 +29,7 @@ export default { isRequired: pluginPkg.strapi.required || false, name, pluginLogo, - trads, + // trads, settings: { menuSection: { id: pluginId, @@ -55,4 +55,31 @@ export default { }); }, boot() {}, + async registerTrads({ locales }) { + const importedTrads = await Promise.all( + locales.map(locale => { + return import( + /* webpackChunkName: "email-translation-[request]" */ `./translations/${locale}.json` + ) + .then(({ default: data }) => { + return { + data: Object.keys(data).reduce((acc, current) => { + acc[`${pluginId}.${current}`] = data[current]; + + return acc; + }, {}), + locale, + }; + }) + .catch(() => { + return { + data: {}, + locale, + }; + }); + }) + ); + + return Promise.resolve(importedTrads); + }, }; diff --git a/packages/core/upload/admin/src/index.js b/packages/core/upload/admin/src/index.js index 3451d69995..bf183112b5 100644 --- a/packages/core/upload/admin/src/index.js +++ b/packages/core/upload/admin/src/index.js @@ -14,7 +14,7 @@ import InputMedia from './components/InputMedia'; import InputModalStepper from './components/InputModalStepper'; import SettingsPage from './pages/SettingsPage'; import reducers from './reducers'; -import trads from './translations'; +// import trads from './translations'; import pluginId from './pluginId'; import { getTrad } from './utils'; @@ -62,7 +62,7 @@ export default { ], }, }, - trads, + // trads, menu: { pluginsSectionLinks: [ { @@ -80,4 +80,31 @@ export default { }); }, boot() {}, + async registerTrads({ locales }) { + const importedTrads = await Promise.all( + locales.map(locale => { + return import( + /* webpackChunkName: "upload-translation-[request]" */ `./translations/${locale}.json` + ) + .then(({ default: data }) => { + return { + data: Object.keys(data).reduce((acc, current) => { + acc[`${pluginId}.${current}`] = data[current]; + + return acc; + }, {}), + locale, + }; + }) + .catch(() => { + return { + data: {}, + locale, + }; + }); + }) + ); + + return Promise.resolve(importedTrads); + }, }; diff --git a/packages/plugins/documentation/admin/src/index.js b/packages/plugins/documentation/admin/src/index.js index 1df5a6084b..be124e8415 100644 --- a/packages/plugins/documentation/admin/src/index.js +++ b/packages/plugins/documentation/admin/src/index.js @@ -9,7 +9,7 @@ import pluginPermissions from './permissions'; import pluginId from './pluginId'; import pluginLogo from './assets/images/logo.svg'; import App from './pages/App'; -import trads from './translations'; +// import trads from './translations'; const pluginDescription = pluginPkg.strapi.description || pluginPkg.description; const icon = pluginPkg.strapi.icon; @@ -28,7 +28,7 @@ export default { name, pluginLogo, // TODO - trads, + // trads, // TODO menu: { pluginsSectionLinks: [ @@ -47,4 +47,31 @@ export default { }); }, boot() {}, + async registerTrads({ locales }) { + const importedTrads = await Promise.all( + locales.map(locale => { + return import( + /* webpackChunkName: "documentation-translation-[request]" */ `./translations/${locale}.json` + ) + .then(({ default: data }) => { + return { + data: Object.keys(data).reduce((acc, current) => { + acc[`${pluginId}.${current}`] = data[current]; + + return acc; + }, {}), + locale, + }; + }) + .catch(() => { + return { + data: {}, + locale, + }; + }); + }) + ); + + return Promise.resolve(importedTrads); + }, }; diff --git a/packages/plugins/graphql/admin/src/index.js b/packages/plugins/graphql/admin/src/index.js index c67aa1b793..8bf3b391d7 100644 --- a/packages/plugins/graphql/admin/src/index.js +++ b/packages/plugins/graphql/admin/src/index.js @@ -21,4 +21,31 @@ export default { }); }, boot() {}, + async registerTrads({ locales }) { + const importedTrads = await Promise.all( + locales.map(locale => { + return import( + /* webpackChunkName: "graphql-translation-[request]" */ `./translations/${locale}.json` + ) + .then(({ default: data }) => { + return { + data: Object.keys(data).reduce((acc, current) => { + acc[`${pluginId}.${current}`] = data[current]; + + return acc; + }, {}), + locale, + }; + }) + .catch(() => { + return { + data: {}, + locale, + }; + }); + }) + ); + + return Promise.resolve(importedTrads); + }, }; diff --git a/packages/plugins/i18n/admin/src/index.js b/packages/plugins/i18n/admin/src/index.js index 9044417913..1195140415 100644 --- a/packages/plugins/i18n/admin/src/index.js +++ b/packages/plugins/i18n/admin/src/index.js @@ -11,7 +11,7 @@ import LocalePicker from './components/LocalePicker'; import middlewares from './middlewares'; import pluginPermissions from './permissions'; import pluginId from './pluginId'; -import trads from './translations'; +// import trads from './translations'; import { getTrad } from './utils'; import mutateCTBContentTypeSchema from './utils/mutateCTBContentTypeSchema'; import LOCALIZED_FIELDS from './utils/localizedFields'; @@ -54,7 +54,7 @@ export default { ], }, }, - trads, + // trads, }); }, boot(app) { @@ -166,4 +166,31 @@ export default { }); } }, + async registerTrads({ locales }) { + const importedTrads = await Promise.all( + locales.map(locale => { + return import( + /* webpackChunkName: "i18n-translation-[request]" */ `./translations/${locale}.json` + ) + .then(({ default: data }) => { + return { + data: Object.keys(data).reduce((acc, current) => { + acc[`${pluginId}.${current}`] = data[current]; + + return acc; + }, {}), + locale, + }; + }) + .catch(() => { + return { + data: {}, + locale, + }; + }); + }) + ); + + return Promise.resolve(importedTrads); + }, }; diff --git a/packages/plugins/sentry/admin/src/index.js b/packages/plugins/sentry/admin/src/index.js index c67aa1b793..5f4d01e6da 100644 --- a/packages/plugins/sentry/admin/src/index.js +++ b/packages/plugins/sentry/admin/src/index.js @@ -1,7 +1,7 @@ import pluginPkg from '../../package.json'; import pluginId from './pluginId'; import pluginLogo from './assets/images/logo.svg'; -import trads from './translations'; +// import trads from './translations'; const pluginDescription = pluginPkg.strapi.description || pluginPkg.description; const icon = pluginPkg.strapi.icon; @@ -17,8 +17,35 @@ export default { isRequired: pluginPkg.strapi.required || false, name, pluginLogo, - trads, + // trads, }); }, boot() {}, + async registerTrads({ locales }) { + const importedTrads = await Promise.all( + locales.map(locale => { + return import( + /* webpackChunkName: "sentry-translation-[request]" */ `./translations/${locale}.json` + ) + .then(({ default: data }) => { + return { + data: Object.keys(data).reduce((acc, current) => { + acc[`${pluginId}.${current}`] = data[current]; + + return acc; + }, {}), + locale, + }; + }) + .catch(() => { + return { + data: {}, + locale, + }; + }); + }) + ); + + return Promise.resolve(importedTrads); + }, }; diff --git a/packages/plugins/users-permissions/admin/src/index.js b/packages/plugins/users-permissions/admin/src/index.js index 83135e4173..08eb1e8a08 100644 --- a/packages/plugins/users-permissions/admin/src/index.js +++ b/packages/plugins/users-permissions/admin/src/index.js @@ -10,7 +10,7 @@ import pluginPkg from '../../package.json'; import pluginLogo from './assets/images/logo.svg'; import pluginPermissions from './permissions'; import pluginId from './pluginId'; -import trads from './translations'; +// import trads from './translations'; import RolesPage from './pages/Roles'; import ProvidersPage from './pages/Providers'; import EmailTemplatesPage from './pages/EmailTemplates'; @@ -31,7 +31,7 @@ export default { isRequired: pluginPkg.strapi.required || false, name, pluginLogo, - trads, + // trads, // TODO settings: { menuSection: { @@ -100,4 +100,31 @@ export default { }); }, boot() {}, + async registerTrads({ locales }) { + const importedTrads = await Promise.all( + locales.map(locale => { + return import( + /* webpackChunkName: "users-permissions-translation-[request]" */ `./translations/${locale}.json` + ) + .then(({ default: data }) => { + return { + data: Object.keys(data).reduce((acc, current) => { + acc[`${pluginId}.${current}`] = data[current]; + + return acc; + }, {}), + locale, + }; + }) + .catch(() => { + return { + data: {}, + locale, + }; + }); + }) + ); + + return Promise.resolve(importedTrads); + }, }; From 3806d3cbf8cf6d2821d6dfaf0227426f6490eaf6 Mon Sep 17 00:00:00 2001 From: soupette Date: Wed, 9 Jun 2021 12:11:51 +0200 Subject: [PATCH 2/2] Clean files Signed-off-by: soupette --- examples/getstarted/admin/admin.config.js | 2 - .../plugins/myplugin/admin/src/index.js | 26 ++++++++- .../myplugin/admin/src/pages/App/index.js | 9 +++ .../myplugin/admin/src/translations/en.json | 3 + .../myplugin/admin/src/utils/getTrad.js | 5 ++ packages/core/admin/admin/src/StrapiApp.js | 5 +- packages/core/admin/admin/src/admin.config.js | 2 +- packages/core/admin/index.js | 10 ++++ .../core/content-manager/admin/src/index.js | 10 +--- .../admin/src/translations/index.js | 53 ------------------ .../content-type-builder/admin/src/index.js | 10 +--- .../admin/src/translations/index.js | 51 ----------------- packages/core/email/admin/src/index.js | 9 +-- .../email/admin/src/translations/index.js | 53 ------------------ packages/core/helper-plugin/lib/src/index.js | 1 + .../lib/src/utils/prefixPluginTranslations.js | 9 +++ packages/core/upload/admin/src/index.js | 10 +--- .../upload/admin/src/translations/index.js | 37 ------------- .../plugins/documentation/admin/src/index.js | 10 +--- .../admin/src/translations/index.js | 50 ----------------- packages/plugins/graphql/admin/src/index.js | 9 +-- .../graphql/admin/src/translations/index.js | 9 --- packages/plugins/i18n/admin/src/index.js | 9 +-- .../i18n/admin/src/translations/index.js | 9 --- packages/plugins/sentry/admin/src/index.js | 9 +-- .../sentry/admin/src/translations/index.js | 49 ----------------- .../users-permissions/admin/src/index.js | 9 +-- .../admin/src/translations/index.js | 55 ------------------- 28 files changed, 82 insertions(+), 441 deletions(-) create mode 100644 examples/getstarted/plugins/myplugin/admin/src/pages/App/index.js create mode 100644 examples/getstarted/plugins/myplugin/admin/src/translations/en.json create mode 100644 examples/getstarted/plugins/myplugin/admin/src/utils/getTrad.js delete mode 100644 packages/core/content-manager/admin/src/translations/index.js delete mode 100644 packages/core/content-type-builder/admin/src/translations/index.js delete mode 100644 packages/core/email/admin/src/translations/index.js create mode 100644 packages/core/helper-plugin/lib/src/utils/prefixPluginTranslations.js delete mode 100644 packages/core/upload/admin/src/translations/index.js delete mode 100644 packages/plugins/documentation/admin/src/translations/index.js delete mode 100644 packages/plugins/graphql/admin/src/translations/index.js delete mode 100644 packages/plugins/i18n/admin/src/translations/index.js delete mode 100644 packages/plugins/sentry/admin/src/translations/index.js delete mode 100644 packages/plugins/users-permissions/admin/src/translations/index.js diff --git a/examples/getstarted/admin/admin.config.js b/examples/getstarted/admin/admin.config.js index 7c47030570..0e0a7db994 100644 --- a/examples/getstarted/admin/admin.config.js +++ b/examples/getstarted/admin/admin.config.js @@ -6,8 +6,6 @@ module.exports = { return config; }, app: config => { - console.log(config); - return config; }, }; diff --git a/examples/getstarted/plugins/myplugin/admin/src/index.js b/examples/getstarted/plugins/myplugin/admin/src/index.js index 0c5ee9f361..1262df50e6 100644 --- a/examples/getstarted/plugins/myplugin/admin/src/index.js +++ b/examples/getstarted/plugins/myplugin/admin/src/index.js @@ -1,3 +1,4 @@ +import { prefixPluginTranslations } from '@strapi/helper-plugin'; import pluginPkg from '../../package.json'; import pluginId from './pluginId'; @@ -15,8 +16,6 @@ export default { isRequired: pluginPkg.strapi.required || false, mainComponent: () => 'My plugin', name, - settings: null, - trads: {}, menu: { pluginsSectionLinks: [ { @@ -34,4 +33,27 @@ export default { }); }, boot() {}, + async registerTrads({ locales }) { + const importedTrads = await Promise.all( + locales.map(locale => { + return import( + /* webpackChunkName: "[pluginId]-[request]" */ `./translations/${locale}.json` + ) + .then(({ default: data }) => { + return { + data: prefixPluginTranslations(data, pluginId), + locale, + }; + }) + .catch(() => { + return { + data: {}, + locale, + }; + }); + }) + ); + + return Promise.resolve(importedTrads); + }, }; diff --git a/examples/getstarted/plugins/myplugin/admin/src/pages/App/index.js b/examples/getstarted/plugins/myplugin/admin/src/pages/App/index.js new file mode 100644 index 0000000000..ebd50fc061 --- /dev/null +++ b/examples/getstarted/plugins/myplugin/admin/src/pages/App/index.js @@ -0,0 +1,9 @@ +import React from 'react'; +import { FormattedMessage } from 'react-intl'; +import getTrad from '../../utils/getTrad'; + +const App = () => { + return ; +}; + +export default App; diff --git a/examples/getstarted/plugins/myplugin/admin/src/translations/en.json b/examples/getstarted/plugins/myplugin/admin/src/translations/en.json new file mode 100644 index 0000000000..5a983e46aa --- /dev/null +++ b/examples/getstarted/plugins/myplugin/admin/src/translations/en.json @@ -0,0 +1,3 @@ +{ + "plugin.name": "My plugin" +} diff --git a/examples/getstarted/plugins/myplugin/admin/src/utils/getTrad.js b/examples/getstarted/plugins/myplugin/admin/src/utils/getTrad.js new file mode 100644 index 0000000000..a2b8632a8d --- /dev/null +++ b/examples/getstarted/plugins/myplugin/admin/src/utils/getTrad.js @@ -0,0 +1,5 @@ +import pluginId from '../pluginId'; + +const getTrad = id => `${pluginId}.${id}`; + +export default getTrad; diff --git a/packages/core/admin/admin/src/StrapiApp.js b/packages/core/admin/admin/src/StrapiApp.js index c4a8ffb649..7555656dcd 100644 --- a/packages/core/admin/admin/src/StrapiApp.js +++ b/packages/core/admin/admin/src/StrapiApp.js @@ -107,9 +107,8 @@ class StrapiApp { .then(({ default: data }) => { return { data, locale }; }) - .catch(err => { - // TODO - console.log(err); + .catch(() => { + return { data: {}, locale }; }); }); const adminLocales = await Promise.all(arrayOfPromises); diff --git a/packages/core/admin/admin/src/admin.config.js b/packages/core/admin/admin/src/admin.config.js index 57b6ec8bb1..94503f6c2c 100644 --- a/packages/core/admin/admin/src/admin.config.js +++ b/packages/core/admin/admin/src/admin.config.js @@ -1,6 +1,6 @@ module.exports = { app: config => { - console.log(config); + config.locales = ['fr']; return config; }, diff --git a/packages/core/admin/index.js b/packages/core/admin/index.js index ea5a072b89..0654a9a21b 100644 --- a/packages/core/admin/index.js +++ b/packages/core/admin/index.js @@ -199,6 +199,16 @@ async function createCacheDir(dir) { await copyCustomAdmin(path.join(dir, 'admin'), cacheDir); } + // Copy admin.config.js + const customAdminConfigFilePath = path.join(dir, 'admin', 'admin.config.js'); + + if (fs.existsSync(customAdminConfigFilePath)) { + await fs.copy( + customAdminConfigFilePath, + path.resolve(cacheDir, 'admin', 'src', 'admin.config.js') + ); + } + // create plugins.js with plugins requires await createPluginsJs(pluginsToCopy, localPluginsToCopy, cacheDir); diff --git a/packages/core/content-manager/admin/src/index.js b/packages/core/content-manager/admin/src/index.js index adc2e54210..cd19702a42 100644 --- a/packages/core/content-manager/admin/src/index.js +++ b/packages/core/content-manager/admin/src/index.js @@ -4,12 +4,11 @@ // Here's the file: strapi/docs/3.0.0-beta.x/guides/registering-a-field-in-admin.md // Also the strapi-generate-plugins/files/admin/src/index.js needs to be updated // IF THE DOC IS NOT UPDATED THE PULL REQUEST WILL NOT BE MERGED - +import { prefixPluginTranslations } from '@strapi/helper-plugin'; import pluginPkg from '../../package.json'; import pluginId from './pluginId'; import pluginLogo from './assets/images/logo.svg'; import reducers from './reducers'; -// import trads from './translations'; const pluginDescription = pluginPkg.strapi.description || pluginPkg.description; const icon = pluginPkg.strapi.icon; @@ -31,7 +30,6 @@ export default { isRequired: pluginPkg.strapi.required || false, name, pluginLogo, - // trads, }); }, boot() {}, @@ -43,11 +41,7 @@ export default { ) .then(({ default: data }) => { return { - data: Object.keys(data).reduce((acc, current) => { - acc[`${pluginId}.${current}`] = data[current]; - - return acc; - }, {}), + data: prefixPluginTranslations(data, pluginId), locale, }; }) diff --git a/packages/core/content-manager/admin/src/translations/index.js b/packages/core/content-manager/admin/src/translations/index.js deleted file mode 100644 index 73c623f40a..0000000000 --- a/packages/core/content-manager/admin/src/translations/index.js +++ /dev/null @@ -1,53 +0,0 @@ -// import ar from './ar.json'; -// import cs from './cs.json'; -// import de from './de.json'; -// import dk from './dk.json'; -import en from './en.json'; -// import es from './es.json'; -import fr from './fr.json'; -// import id from './id.json'; -// import it from './it.json'; -// import ja from './ja.json'; -// import ko from './ko.json'; -// import ms from './ms.json'; -// import nl from './nl.json'; -// import pl from './pl.json'; -// import ptBR from './pt-BR.json'; -// import pt from './pt.json'; -// import ru from './ru.json'; -// import th from './th.json'; -// import tr from './tr.json'; -// import uk from './uk.json'; -// import vi from './vi.json'; -// import zhHans from './zh-Hans.json'; -// import zh from './zh.json'; -// import sk from './sk.json'; - -const trads = { - // ar, - // cs, - // de, - // dk, - en, - // es, - fr, - // id, - // it, - // ja, - // ko, - // ms, - // nl, - // pl, - // 'pt-BR': ptBR, - // pt, - // ru, - // th, - // tr, - // uk, - // vi, - // 'zh-Hans': zhHans, - // zh, - // sk, -}; - -export default trads; diff --git a/packages/core/content-type-builder/admin/src/index.js b/packages/core/content-type-builder/admin/src/index.js index 2074a9695b..2236dad4ea 100644 --- a/packages/core/content-type-builder/admin/src/index.js +++ b/packages/core/content-type-builder/admin/src/index.js @@ -4,10 +4,9 @@ // Here's the file: strapi/docs/3.0.0-beta.x/guides/registering-a-field-in-admin.md // Also the strapi-generate-plugins/files/admin/src/index.js needs to be updated // IF THE DOC IS NOT UPDATED THE PULL REQUEST WILL NOT BE MERGED - +import { prefixPluginTranslations } from '@strapi/helper-plugin'; import pluginPkg from '../../package.json'; import pluginLogo from './assets/images/logo.svg'; -// import trads from './translations'; import pluginPermissions from './permissions'; import pluginId from './pluginId'; import reducers from './reducers'; @@ -28,7 +27,6 @@ export default { isReady: true, name, pluginLogo, - // trads, menu: { pluginsSectionLinks: [ { @@ -58,11 +56,7 @@ export default { ) .then(({ default: data }) => { return { - data: Object.keys(data).reduce((acc, current) => { - acc[`${pluginId}.${current}`] = data[current]; - - return acc; - }, {}), + data: prefixPluginTranslations(data, pluginId), locale, }; }) diff --git a/packages/core/content-type-builder/admin/src/translations/index.js b/packages/core/content-type-builder/admin/src/translations/index.js deleted file mode 100644 index 596b252347..0000000000 --- a/packages/core/content-type-builder/admin/src/translations/index.js +++ /dev/null @@ -1,51 +0,0 @@ -// import ar from './ar.json'; -// import cs from './cs.json'; -// import de from './de.json'; -// import dk from './dk.json'; -import en from './en.json'; -// import es from './es.json'; -import fr from './fr.json'; -// import id from './id.json'; -// import it from './it.json'; -// import ja from './ja.json'; -// import ko from './ko.json'; -// import ms from './ms.json'; -// import nl from './nl.json'; -// import pl from './pl.json'; -// import ptBR from './pt-BR.json'; -// import pt from './pt.json'; -// import ru from './ru.json'; -// import th from './th.json'; -// import tr from './tr.json'; -// import uk from './uk.json'; -// import zhHans from './zh-Hans.json'; -// import zh from './zh.json'; -// import sk from './sk.json'; - -const trads = { - // ar, - // cs, - // de, - // dk, - en, - // es, - fr, - // id, - // it, - // ja, - // ko, - // ms, - // nl, - // pl, - // 'pt-BR': ptBR, - // pt, - // ru, - // th, - // tr, - // uk, - // 'zh-Hans': zhHans, - // zh, - // sk, -}; - -export default trads; diff --git a/packages/core/email/admin/src/index.js b/packages/core/email/admin/src/index.js index 4fca43faaa..4787c29a24 100644 --- a/packages/core/email/admin/src/index.js +++ b/packages/core/email/admin/src/index.js @@ -6,12 +6,11 @@ // IF THE DOC IS NOT UPDATED THE PULL REQUEST WILL NOT BE MERGED import React from 'react'; -import { CheckPagePermissions } from '@strapi/helper-plugin'; +import { CheckPagePermissions, prefixPluginTranslations } from '@strapi/helper-plugin'; import pluginPkg from '../../package.json'; import pluginId from './pluginId'; import pluginLogo from './assets/images/logo.svg'; import pluginPermissions from './permissions'; -// import trads from './translations'; import getTrad from './utils/getTrad'; import SettingsPage from './pages/Settings'; @@ -63,11 +62,7 @@ export default { ) .then(({ default: data }) => { return { - data: Object.keys(data).reduce((acc, current) => { - acc[`${pluginId}.${current}`] = data[current]; - - return acc; - }, {}), + data: prefixPluginTranslations(data, pluginId), locale, }; }) diff --git a/packages/core/email/admin/src/translations/index.js b/packages/core/email/admin/src/translations/index.js deleted file mode 100644 index 73c623f40a..0000000000 --- a/packages/core/email/admin/src/translations/index.js +++ /dev/null @@ -1,53 +0,0 @@ -// import ar from './ar.json'; -// import cs from './cs.json'; -// import de from './de.json'; -// import dk from './dk.json'; -import en from './en.json'; -// import es from './es.json'; -import fr from './fr.json'; -// import id from './id.json'; -// import it from './it.json'; -// import ja from './ja.json'; -// import ko from './ko.json'; -// import ms from './ms.json'; -// import nl from './nl.json'; -// import pl from './pl.json'; -// import ptBR from './pt-BR.json'; -// import pt from './pt.json'; -// import ru from './ru.json'; -// import th from './th.json'; -// import tr from './tr.json'; -// import uk from './uk.json'; -// import vi from './vi.json'; -// import zhHans from './zh-Hans.json'; -// import zh from './zh.json'; -// import sk from './sk.json'; - -const trads = { - // ar, - // cs, - // de, - // dk, - en, - // es, - fr, - // id, - // it, - // ja, - // ko, - // ms, - // nl, - // pl, - // 'pt-BR': ptBR, - // pt, - // ru, - // th, - // tr, - // uk, - // vi, - // 'zh-Hans': zhHans, - // zh, - // sk, -}; - -export default trads; diff --git a/packages/core/helper-plugin/lib/src/index.js b/packages/core/helper-plugin/lib/src/index.js index 8a6d67417d..19b680e321 100644 --- a/packages/core/helper-plugin/lib/src/index.js +++ b/packages/core/helper-plugin/lib/src/index.js @@ -164,6 +164,7 @@ export { default as generateFiltersFromSearch } from './utils/generateFiltersFro export { default as generateSearchFromFilters } from './utils/generateSearchFromFilters'; export { default as generateSearchFromObject } from './utils/generateSearchFromObject'; export { default as prefixFileUrlWithBackendUrl } from './utils/prefixFileUrlWithBackendUrl'; +export { default as prefixPluginTranslations } from './utils/prefixPluginTranslations'; // SVGS export { default as LayoutIcon } from './svgs/Layout'; diff --git a/packages/core/helper-plugin/lib/src/utils/prefixPluginTranslations.js b/packages/core/helper-plugin/lib/src/utils/prefixPluginTranslations.js new file mode 100644 index 0000000000..c94fc993b8 --- /dev/null +++ b/packages/core/helper-plugin/lib/src/utils/prefixPluginTranslations.js @@ -0,0 +1,9 @@ +const prefixPluginTranslations = (trad, pluginId) => { + return Object.keys(trad).reduce((acc, current) => { + acc[`${pluginId}.${current}`] = trad[current]; + + return acc; + }, {}); +}; + +export default prefixPluginTranslations; diff --git a/packages/core/upload/admin/src/index.js b/packages/core/upload/admin/src/index.js index bf183112b5..dd2f383806 100644 --- a/packages/core/upload/admin/src/index.js +++ b/packages/core/upload/admin/src/index.js @@ -5,7 +5,7 @@ // Also the strapi-generate-plugins/files/admin/src/index.js needs to be updated // IF THE DOC IS NOT UPDATED THE PULL REQUEST WILL NOT BE MERGED import React from 'react'; -import { CheckPagePermissions } from '@strapi/helper-plugin'; +import { CheckPagePermissions, prefixPluginTranslations } from '@strapi/helper-plugin'; import pluginPkg from '../../package.json'; import pluginLogo from './assets/images/logo.svg'; import pluginPermissions from './permissions'; @@ -14,7 +14,6 @@ import InputMedia from './components/InputMedia'; import InputModalStepper from './components/InputModalStepper'; import SettingsPage from './pages/SettingsPage'; import reducers from './reducers'; -// import trads from './translations'; import pluginId from './pluginId'; import { getTrad } from './utils'; @@ -62,7 +61,6 @@ export default { ], }, }, - // trads, menu: { pluginsSectionLinks: [ { @@ -88,11 +86,7 @@ export default { ) .then(({ default: data }) => { return { - data: Object.keys(data).reduce((acc, current) => { - acc[`${pluginId}.${current}`] = data[current]; - - return acc; - }, {}), + data: prefixPluginTranslations(data, pluginId), locale, }; }) diff --git a/packages/core/upload/admin/src/translations/index.js b/packages/core/upload/admin/src/translations/index.js deleted file mode 100644 index df0a345db2..0000000000 --- a/packages/core/upload/admin/src/translations/index.js +++ /dev/null @@ -1,37 +0,0 @@ -// import de from './de.json'; -// import dk from './dk.json'; -import en from './en.json'; -// import es from './es.json'; -import fr from './fr.json'; -// import he from './he.json'; -// import it from './it.json'; -// import ja from './ja.json'; -// import ms from './ms.json'; -// import ru from './ru.json'; -// import th from './th.json'; -// import uk from './uk.json'; -// import ptBR from './pt-BR.json'; -// import sk from './sk.json'; -// import zh from './zh.json'; -// import pl from './pl.json'; - -const trads = { - // de, - // dk, - en, - // es, - fr, - // he, - // it, - // ja, - // ms, - // ru, - // th, - // uk, - // 'pt-BR': ptBR, - // sk, - // zh, - // pl, -}; - -export default trads; diff --git a/packages/plugins/documentation/admin/src/index.js b/packages/plugins/documentation/admin/src/index.js index be124e8415..fd3a81914e 100644 --- a/packages/plugins/documentation/admin/src/index.js +++ b/packages/plugins/documentation/admin/src/index.js @@ -4,12 +4,12 @@ // Here's the file: strapi/docs/3.0.0-beta.x/guides/registering-a-field-in-admin.md // Also the strapi-generate-plugins/files/admin/src/index.js needs to be updated // IF THE DOC IS NOT UPDATED THE PULL REQUEST WILL NOT BE MERGED +import { prefixPluginTranslations } from '@strapi/helper-plugin'; import pluginPkg from '../../package.json'; import pluginPermissions from './permissions'; import pluginId from './pluginId'; import pluginLogo from './assets/images/logo.svg'; import App from './pages/App'; -// import trads from './translations'; const pluginDescription = pluginPkg.strapi.description || pluginPkg.description; const icon = pluginPkg.strapi.icon; @@ -28,8 +28,6 @@ export default { name, pluginLogo, // TODO - // trads, - // TODO menu: { pluginsSectionLinks: [ { @@ -55,11 +53,7 @@ export default { ) .then(({ default: data }) => { return { - data: Object.keys(data).reduce((acc, current) => { - acc[`${pluginId}.${current}`] = data[current]; - - return acc; - }, {}), + data: prefixPluginTranslations(data, pluginId), locale, }; }) diff --git a/packages/plugins/documentation/admin/src/translations/index.js b/packages/plugins/documentation/admin/src/translations/index.js deleted file mode 100644 index d5534490a9..0000000000 --- a/packages/plugins/documentation/admin/src/translations/index.js +++ /dev/null @@ -1,50 +0,0 @@ -// TODO -// import ar from './ar.json'; -// import cs from './cs.json'; -// import de from './de.json'; -import en from './en.json'; -// import es from './es.json'; -import fr from './fr.json'; -// import id from './id.json'; -// import it from './it.json'; -// import ko from './ko.json'; -// import ms from './ms.json'; -// import nl from './nl.json'; -// import pl from './pl.json'; -// import ptBR from './pt-BR.json'; -// import pt from './pt.json'; -// import ru from './ru.json'; -// import th from './th.json'; -// import tr from './tr.json'; -// import uk from './uk.json'; -// import vi from './vi.json'; -// import zhHans from './zh-Hans.json'; -// import zh from './zh.json'; -// import sk from './sk.json'; - -const trads = { - // ar, - // cs, - // de, - en, - // es, - fr, - // id, - // it, - // ko, - // ms, - // nl, - // pl, - // 'pt-BR': ptBR, - // pt, - // ru, - // th, - // tr, - // uk, - // vi, - // 'zh-Hans': zhHans, - // zh, - // sk, -}; - -export default trads; diff --git a/packages/plugins/graphql/admin/src/index.js b/packages/plugins/graphql/admin/src/index.js index 8bf3b391d7..c9a1e22e09 100644 --- a/packages/plugins/graphql/admin/src/index.js +++ b/packages/plugins/graphql/admin/src/index.js @@ -1,7 +1,7 @@ +import { prefixPluginTranslations } from '@strapi/helper-plugin'; import pluginPkg from '../../package.json'; import pluginId from './pluginId'; import pluginLogo from './assets/images/logo.svg'; -import trads from './translations'; const pluginDescription = pluginPkg.strapi.description || pluginPkg.description; const icon = pluginPkg.strapi.icon; @@ -17,7 +17,6 @@ export default { isRequired: pluginPkg.strapi.required || false, name, pluginLogo, - trads, }); }, boot() {}, @@ -29,11 +28,7 @@ export default { ) .then(({ default: data }) => { return { - data: Object.keys(data).reduce((acc, current) => { - acc[`${pluginId}.${current}`] = data[current]; - - return acc; - }, {}), + data: prefixPluginTranslations(data, pluginId), locale, }; }) diff --git a/packages/plugins/graphql/admin/src/translations/index.js b/packages/plugins/graphql/admin/src/translations/index.js deleted file mode 100644 index bb24bb1106..0000000000 --- a/packages/plugins/graphql/admin/src/translations/index.js +++ /dev/null @@ -1,9 +0,0 @@ -import en from './en.json'; -import fr from './fr.json'; - -const trads = { - en, - fr, -}; - -export default trads; diff --git a/packages/plugins/i18n/admin/src/index.js b/packages/plugins/i18n/admin/src/index.js index 1195140415..6c8a1af591 100644 --- a/packages/plugins/i18n/admin/src/index.js +++ b/packages/plugins/i18n/admin/src/index.js @@ -1,6 +1,7 @@ import React from 'react'; import get from 'lodash/get'; import * as yup from 'yup'; +import { prefixPluginTranslations } from '@strapi/helper-plugin'; import pluginPkg from '../../package.json'; import pluginLogo from './assets/images/logo.svg'; import CheckboxConfirmation from './components/CheckboxConfirmation'; @@ -11,7 +12,6 @@ import LocalePicker from './components/LocalePicker'; import middlewares from './middlewares'; import pluginPermissions from './permissions'; import pluginId from './pluginId'; -// import trads from './translations'; import { getTrad } from './utils'; import mutateCTBContentTypeSchema from './utils/mutateCTBContentTypeSchema'; import LOCALIZED_FIELDS from './utils/localizedFields'; @@ -54,7 +54,6 @@ export default { ], }, }, - // trads, }); }, boot(app) { @@ -174,11 +173,7 @@ export default { ) .then(({ default: data }) => { return { - data: Object.keys(data).reduce((acc, current) => { - acc[`${pluginId}.${current}`] = data[current]; - - return acc; - }, {}), + data: prefixPluginTranslations(data, pluginId), locale, }; }) diff --git a/packages/plugins/i18n/admin/src/translations/index.js b/packages/plugins/i18n/admin/src/translations/index.js deleted file mode 100644 index bb24bb1106..0000000000 --- a/packages/plugins/i18n/admin/src/translations/index.js +++ /dev/null @@ -1,9 +0,0 @@ -import en from './en.json'; -import fr from './fr.json'; - -const trads = { - en, - fr, -}; - -export default trads; diff --git a/packages/plugins/sentry/admin/src/index.js b/packages/plugins/sentry/admin/src/index.js index 5f4d01e6da..e06e41ee0c 100644 --- a/packages/plugins/sentry/admin/src/index.js +++ b/packages/plugins/sentry/admin/src/index.js @@ -1,7 +1,7 @@ +import { prefixPluginTranslations } from '@strapi/helper-plugin'; import pluginPkg from '../../package.json'; import pluginId from './pluginId'; import pluginLogo from './assets/images/logo.svg'; -// import trads from './translations'; const pluginDescription = pluginPkg.strapi.description || pluginPkg.description; const icon = pluginPkg.strapi.icon; @@ -17,7 +17,6 @@ export default { isRequired: pluginPkg.strapi.required || false, name, pluginLogo, - // trads, }); }, boot() {}, @@ -29,11 +28,7 @@ export default { ) .then(({ default: data }) => { return { - data: Object.keys(data).reduce((acc, current) => { - acc[`${pluginId}.${current}`] = data[current]; - - return acc; - }, {}), + data: prefixPluginTranslations(data, pluginId), locale, }; }) diff --git a/packages/plugins/sentry/admin/src/translations/index.js b/packages/plugins/sentry/admin/src/translations/index.js deleted file mode 100644 index b8134d0dac..0000000000 --- a/packages/plugins/sentry/admin/src/translations/index.js +++ /dev/null @@ -1,49 +0,0 @@ -// import ar from './ar.json'; -// import cs from './cs.json'; -// import de from './de.json'; -import en from './en.json'; -// import es from './es.json'; -import fr from './fr.json'; -// import id from './id.json'; -// import it from './it.json'; -// import ko from './ko.json'; -// import ms from './ms.json'; -// import nl from './nl.json'; -// import pl from './pl.json'; -// import ptBR from './pt-BR.json'; -// import pt from './pt.json'; -// import ru from './ru.json'; -// import th from './th.json'; -// import tr from './tr.json'; -// import uk from './uk.json'; -// import vi from './vi.json'; -// import zhHans from './zh-Hans.json'; -// import zh from './zh.json'; -// import sk from './sk.json'; - -const trads = { - // ar, - // cs, - // de, - en, - // es, - fr, - // id, - // it, - // ko, - // ms, - // nl, - // pl, - // 'pt-BR': ptBR, - // pt, - // ru, - // th, - // tr, - // uk, - // vi, - // 'zh-Hans': zhHans, - // zh, - // sk, -}; - -export default trads; diff --git a/packages/plugins/users-permissions/admin/src/index.js b/packages/plugins/users-permissions/admin/src/index.js index 08eb1e8a08..2c056729af 100644 --- a/packages/plugins/users-permissions/admin/src/index.js +++ b/packages/plugins/users-permissions/admin/src/index.js @@ -5,12 +5,11 @@ // Also the strapi-generate-plugins/files/admin/src/index.js needs to be updated // IF THE DOC IS NOT UPDATED THE PULL REQUEST WILL NOT BE MERGED import React from 'react'; -import { CheckPagePermissions } from '@strapi/helper-plugin'; +import { CheckPagePermissions, prefixPluginTranslations } from '@strapi/helper-plugin'; import pluginPkg from '../../package.json'; import pluginLogo from './assets/images/logo.svg'; import pluginPermissions from './permissions'; import pluginId from './pluginId'; -// import trads from './translations'; import RolesPage from './pages/Roles'; import ProvidersPage from './pages/Providers'; import EmailTemplatesPage from './pages/EmailTemplates'; @@ -108,11 +107,7 @@ export default { ) .then(({ default: data }) => { return { - data: Object.keys(data).reduce((acc, current) => { - acc[`${pluginId}.${current}`] = data[current]; - - return acc; - }, {}), + data: prefixPluginTranslations(data, pluginId), locale, }; }) diff --git a/packages/plugins/users-permissions/admin/src/translations/index.js b/packages/plugins/users-permissions/admin/src/translations/index.js deleted file mode 100644 index 4ac47e3ed7..0000000000 --- a/packages/plugins/users-permissions/admin/src/translations/index.js +++ /dev/null @@ -1,55 +0,0 @@ -// import ar from './ar.json'; -// import cs from './cs.json'; -// import de from './de.json'; -// import dk from './dk.json'; -import en from './en.json'; -// import es from './es.json'; -import fr from './fr.json'; -// import id from './id.json'; -// import it from './it.json'; -// import ja from './ja.json'; -// import ko from './ko.json'; -// import ms from './ms.json'; -// import nl from './nl.json'; -// import pl from './pl.json'; -// import ptBR from './pt-BR.json'; -// import pt from './pt.json'; -// import ru from './ru.json'; -// import th from './th.json'; -// import tr from './tr.json'; -// import uk from './uk.json'; -// import vi from './vi.json'; -// import zhHans from './zh-Hans.json'; -// import zh from './zh.json'; -// import sk from './sk.json'; -// import sv from './sv.json'; - -const trads = { - // ar, - // cs, - // de, - // dk, - en, - // es, - fr, - // id, - // it, - // ja, - // ko, - // ms, - // nl, - // pl, - // 'pt-BR': ptBR, - // pt, - // ru, - // th, - // tr, - // uk, - // vi, - // 'zh-Hans': zhHans, - // zh, - // sk, - // sv, -}; - -export default trads;