From d3947cfe431b3d8707e82d703d2ebad3fd0d566c Mon Sep 17 00:00:00 2001 From: Dipak Sarkar Date: Fri, 19 Apr 2024 08:53:59 +0530 Subject: [PATCH] Updated Language --- .npmignore | 4 +++- src/commands.js | 47 ++++++++++++++++++++++++++++++++++++---- src/index.js | 15 +++++++------ src/locale/en.js | 53 ++++++++------------------------------------- src/panels.js | 17 ++++++++++++--- src/utils.js | 56 ++---------------------------------------------- 6 files changed, 79 insertions(+), 113 deletions(-) diff --git a/.npmignore b/.npmignore index af98f26..8c373bc 100644 --- a/.npmignore +++ b/.npmignore @@ -6,4 +6,6 @@ node_modules public src -!src/styles/main.scss \ No newline at end of file +!src/styles/main.scss +assets +server \ No newline at end of file diff --git a/src/commands.js b/src/commands.js index 7efe55c..e7c248e 100644 --- a/src/commands.js +++ b/src/commands.js @@ -1,4 +1,4 @@ -import { modalContent, noItems, loader, mapTemplates, fetchTemplates, storeProjects, removeProjects, PROJECTS, TEMPLATES } from './utils' +import { mapTemplates, fetchTemplates, storeProjects, removeProjects, PROJECTS, TEMPLATES } from './utils' const el = document.createElement('div') @@ -7,6 +7,45 @@ export default (editor, options = {}) => { const $el = $(el) editor.tab = TEMPLATES + const modalContent = ` +
+
+
+ + +
+
+
+
+
+
+
+
+ ` + + const noItems = ` +
+ +
+ ${editor.I18n.t('grapesjs-pages.no-records')} +
+
+ ` + + const loader = ` +
+
+ ${editor.I18n.t('grapesjs-pages.loading')} +
+
+ ` + const updateBtnEvent = () => { $el.find('.gjs-template-card .select').on('click', function () { const id = $(this).attr('data-template') @@ -34,7 +73,7 @@ export default (editor, options = {}) => { editor[type] = templates - const html = mapTemplates(templates, type == PROJECTS) + const html = mapTemplates(editor, templates, type == PROJECTS) $el.find(id).html(templates.length ? html : noItems) setTimeout(() => { @@ -52,7 +91,7 @@ export default (editor, options = {}) => { Commands.add('open-templates', { async run(editor, sender) { - Modal.setTitle('Templates') + Modal.setTitle(editor.I18n.t('grapesjs-pages.templates')) Modal.setContent(el) Modal.open() @@ -82,7 +121,7 @@ export default (editor, options = {}) => { Commands.add('save-templates', { async run(editor) { - const name = prompt('Enter template name:') + const name = prompt(editor.I18n.t('grapesjs-pages.enter-template-name')) if (name) { const data = editor.getProjectData() const thumbnail = await editor.makeThumbnail(editor.getWrapper().getEl(), { diff --git a/src/index.js b/src/index.js index 286acdc..2e6c22e 100644 --- a/src/index.js +++ b/src/index.js @@ -31,6 +31,14 @@ export default (editor, opts = {}) => { ...opts } + // Load i18n files + if (editor.I18n) { + editor.I18n.addMessages({ + en, + ...options.i18n + }) + } + editor.templates = templates editor.makeThumbnail = makeThumbnail editor.createPopper = createPopper @@ -46,11 +54,4 @@ export default (editor, opts = {}) => { // Add panels loadPanels(editor, options) - - // Load i18n files - editor.I18n && - editor.I18n.addMessages({ - en, - ...options.i18n - }) } diff --git a/src/locale/en.js b/src/locale/en.js index e89e40d..ee6d9fd 100644 --- a/src/locale/en.js +++ b/src/locale/en.js @@ -1,48 +1,13 @@ export default { 'grapesjs-pages': { - new: 'New Page +', - placeholder: 'Page name', - templates: { - all: 'All', - templates: 'Templates', - search: 'Search for sites by name or id', - open: 'Open', - new: 'Enter new page name', - create: 'Create', - help: 'Select a template, enter project name, then click create. If no template is selected a blank project will be created.', - info: 'Site Info', - updated: 'Last Updated', - pages: 'Pages', - created: 'Created At', - size: 'Size', - actions: 'Actions', - titles: { - open: 'Select to open site', - info: 'Click to sort by site name', - updated: 'Click to sort by last update date', - pages: 'Click to sort by number of pages', - created: 'Click to sort by site creation date', - size: 'Click to sort by site size', - actions: 'Click to sort by site name', - delete: 'Delete', - edit: 'Edit' - } - }, - settings: { - save: 'Save', - generate: 'Generate', - help: 'Enter url, or generate thumbnail.', - labels: { - name: 'Name', - thumbnail: 'Thumbnail', - description: 'Description', - template: 'Template' - }, - placeholders: { - name: 'Name...', - thumbnail: 'Thumbnail...', - description: 'Description...' - } - } + projects: 'My projects', + templates: 'Templates', + 'save-template': 'Save template', + 'load-template': 'Load templates', + 'template-settings': 'Template settings', + loading: 'Loading...', + select: 'Select', + 'enter-template-name': 'Enter template name:', + 'no-records': 'No projects found. Projects will appear here once you add them.' } } diff --git a/src/panels.js b/src/panels.js index 290a261..853b0c6 100644 --- a/src/panels.js +++ b/src/panels.js @@ -1,13 +1,24 @@ -import { dropdownMenu } from './utils' - export default (editor, opts = {}) => { const { Panels, $, createPopper } = editor + const dropdownMenu = ` + + ` + Panels.addButton('options', { id: 'open-templates', className: 'dropdown fa fa-cog', attributes: { - title: 'Template settings', + title: editor.I18n.t('grapesjs-pages.template-settings'), 'data-dropdown': dropdownMenu, 'data-offset': '-55,7' }, diff --git a/src/utils.js b/src/utils.js index a0c6c71..bad6639 100644 --- a/src/utils.js +++ b/src/utils.js @@ -6,59 +6,7 @@ export const TEMPLATES = 'templates' export const thumbnail = 'https://raw.githubusercontent.com/dipaksarkar/grapesjs-pages/main/assets/placeholder.png' -export const dropdownMenu = ` - -` - -export const modalContent = ` -
-
-
- - -
-
-
-
-
-
-
-
-` - -export const noItems = ` -
- -
- No projects found. Projects will appear here once you add them. -
-
-` - -export const loader = ` -
-
- Loading... -
-
-` - -export const mapTemplates = (templates, removeable = false) => { +export const mapTemplates = (editor, templates, removeable = false) => { const list = templates.map( (item) => `
@@ -66,7 +14,7 @@ export const mapTemplates = (templates, removeable = false) => {