From cadd63bc9cb0cd55db133047374a639dbfd1bd41 Mon Sep 17 00:00:00 2001 From: Aleksander Chromik Date: Fri, 8 Oct 2021 16:31:17 +0200 Subject: [PATCH] Replaced i18n.t w/ tpl in core/server/data (#13491) refs: #13380 - The i18n package is deprecated. It is being replaced with the tpl package. Co-authored-by: Aleksander Chromik --- core/server/data/exporter/exporter.js | 8 ++++++-- core/server/data/importer/handlers/json.js | 12 +++++++++--- core/server/data/importer/import-manager.js | 12 ++++++++++++ core/server/data/schema/commands.js | 10 +++++----- 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/core/server/data/exporter/exporter.js b/core/server/data/exporter/exporter.js index cf56980c58..b0af633054 100644 --- a/core/server/data/exporter/exporter.js +++ b/core/server/data/exporter/exporter.js @@ -3,9 +3,13 @@ const Promise = require('bluebird'); const db = require('../../data/db'); const commands = require('../schema').commands; const ghostVersion = require('@tryghost/version'); -const i18n = require('../../../shared/i18n'); +const tpl = require('@tryghost/tpl'); const errors = require('@tryghost/errors'); +const messages = { + errorExportingData: 'Error exporting data' +}; + const { TABLES_ALLOWLIST, SETTING_KEYS_BLOCKLIST @@ -58,7 +62,7 @@ const doExport = async function doExport(options) { } catch (err) { throw new errors.DataExportError({ err: err, - context: i18n.t('errors.data.export.errorExportingData') + context: tpl(messages.errorExportingData) }); } }; diff --git a/core/server/data/importer/handlers/json.js b/core/server/data/importer/handlers/json.js index fff9a013a2..8e00a2a02d 100644 --- a/core/server/data/importer/handlers/json.js +++ b/core/server/data/importer/handlers/json.js @@ -1,8 +1,14 @@ const _ = require('lodash'); const Promise = require('bluebird'); const fs = require('fs-extra'); -const i18n = require('../../../../shared/i18n'); +const tpl = require('@tryghost/tpl'); const errors = require('@tryghost/errors'); + +const messages = { + invalidJsonFormat: 'Invalid JSON format, expected `{ db: [exportedData] }`', + checkImportJsonIsValid: 'check that the import file is valid JSON.' +}; + let JSONHandler; JSONHandler = { @@ -25,7 +31,7 @@ JSONHandler = { if (_.keys(importData).length === 1) { if (!importData.db || !Array.isArray(importData.db)) { throw new errors.GhostError({ - message: i18n.t('errors.data.importer.handlers.json.invalidJsonFormat') + message: tpl(messages.invalidJsonFormat) }); } @@ -37,7 +43,7 @@ JSONHandler = { return Promise.reject(new errors.BadRequestError({ err: err, message: err.message, - help: i18n.t('errors.data.importer.handlers.json.checkImportJsonIsValid') + help: tpl(messages.checkImportJsonIsValid) })); } }); diff --git a/core/server/data/importer/import-manager.js b/core/server/data/importer/import-manager.js index 9e796dc607..0c628efd99 100644 --- a/core/server/data/importer/import-manager.js +++ b/core/server/data/importer/import-manager.js @@ -16,6 +16,18 @@ const MarkdownHandler = require('./handlers/markdown'); const ImageImporter = require('./importers/image'); const DataImporter = require('./importers/data'); +const messages = { + couldNotCleanUpFile: { + error: 'Import could not clean up file ', + context: 'Your site will continue to work as expected' + }, + unsupportedRoonExport: 'Your zip file looks like an old format Roon export, please re-export your Roon blog and try again.', + noContentToImport: 'Zip did not include any content to import.', + invalidZipStructure: 'Invalid zip file structure.', + invalidZipFileBaseDirectory: 'Invalid zip file: base directory read failed', + zipContainsMultipleDataFormats: 'Zip file contains multiple data formats. Please split up and import separately.' +}; + // Glob levels const ROOT_ONLY = 0; diff --git a/core/server/data/schema/commands.js b/core/server/data/schema/commands.js index d9809d7008..7743619f2c 100644 --- a/core/server/data/schema/commands.js +++ b/core/server/data/schema/commands.js @@ -1,6 +1,5 @@ const _ = require('lodash'); const Promise = require('bluebird'); -const i18n = require('../../../shared/i18n'); const logging = require('@tryghost/logging'); const errors = require('@tryghost/errors'); const tpl = require('@tryghost/tpl'); @@ -10,7 +9,8 @@ const clients = require('./clients'); const messages = { hasPrimaryKeySQLiteError: 'Must use hasPrimaryKeySQLite on an SQLite3 database', - hasForeignSQLite3: 'Must use hasForeignSQLite3 on an SQLite3 database' + hasForeignSQLite3: 'Must use hasForeignSQLite3 on an SQLite3 database', + noSupportForDatabase: 'No support for database client {client}' }; function addTableColumn(tableName, table, columnName, columnSpec = schema[tableName][columnName]) { @@ -343,7 +343,7 @@ function getTables(transaction) { return clients[client].getTables(transaction); } - return Promise.reject(i18n.t('notices.data.utils.index.noSupportForDatabase', {client: client})); + return Promise.reject(tpl(messages.noSupportForDatabase, {client: client})); } function getIndexes(table, transaction) { @@ -353,7 +353,7 @@ function getIndexes(table, transaction) { return clients[client].getIndexes(table, transaction); } - return Promise.reject(i18n.t('notices.data.utils.index.noSupportForDatabase', {client: client})); + return Promise.reject(tpl(messages.noSupportForDatabase, {client: client})); } function getColumns(table, transaction) { @@ -363,7 +363,7 @@ function getColumns(table, transaction) { return clients[client].getColumns(table); } - return Promise.reject(i18n.t('notices.data.utils.index.noSupportForDatabase', {client: client})); + return Promise.reject(tpl(messages.noSupportForDatabase, {client: client})); } function checkTables(transaction) {