diff --git a/x-pack/plugins/canvas/public/lib/aeroelastic_kibana.js b/x-pack/plugins/canvas/public/lib/aeroelastic_kibana.js index 9e00538ab37d8..6436e2402d417 100644 --- a/x-pack/plugins/canvas/public/lib/aeroelastic_kibana.js +++ b/x-pack/plugins/canvas/public/lib/aeroelastic_kibana.js @@ -4,6 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ +import { i18n } from '@kbn/i18n'; import aero from './aeroelastic'; const stores = new Map(); @@ -35,7 +36,14 @@ export const aeroelastic = { getStore(page) { const store = stores.get(page); - if (!store) throw new Error('An aeroelastic store should exist for page ' + page); + if (!store) { + throw new Error( + i18n.translate('xpack.canvas.aeroelasticKibana.storeDoesNotExistForPageErrorMessage', { + defaultMessage: 'An aeroelastic store should exist for page {page}', + values: { page }, + }) + ); + } return store.getCurrentState(); }, diff --git a/x-pack/plugins/canvas/public/lib/arg_helpers.js b/x-pack/plugins/canvas/public/lib/arg_helpers.js index e53e26b62dd15..06a2f30b70049 100644 --- a/x-pack/plugins/canvas/public/lib/arg_helpers.js +++ b/x-pack/plugins/canvas/public/lib/arg_helpers.js @@ -5,6 +5,7 @@ */ import { includes } from 'lodash'; +import { i18n } from '@kbn/i18n'; import { getType } from '../../common/lib/get_type'; /* @@ -17,7 +18,13 @@ import { getType } from '../../common/lib/get_type'; // TODO: With the removal of objectified literals in the AST I don't think we need this anymore. const allowedTypes = ['string', 'number', 'boolean']; -const badType = () => new Error(`Arg setting helpers only support ${allowedTypes.join(',')}`); +const badType = () => + new Error( + i18n.translate('xpack.canvas.argHelpers.allowedTypesErrorMessage', { + defaultMessage: 'Arg setting helpers only support {allowedTypes}', + values: { allowedTypes: allowedTypes.join(',') }, + }) + ); const isAllowed = type => includes(allowedTypes, type); diff --git a/x-pack/plugins/canvas/public/lib/element.js b/x-pack/plugins/canvas/public/lib/element.js index f2ebe9af8702b..077105f04b00f 100644 --- a/x-pack/plugins/canvas/public/lib/element.js +++ b/x-pack/plugins/canvas/public/lib/element.js @@ -4,6 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ +import { i18n } from '@kbn/i18n'; import defaultHeader from './default_header.png'; export function Element(config) { @@ -19,7 +20,13 @@ export function Element(config) { // A sentence or few about what this element does this.help = config.help; - if (!config.expression) throw new Error('Element types must have a default expression'); + if (!config.expression) { + throw new Error( + i18n.translate('xpack.canvas.element.elementTypesDefaultExpressionErrorMessage', { + defaultMessage: 'Element types must have a default expression', + }) + ); + } this.expression = config.expression; this.filter = config.filter; this.width = config.width || 500; diff --git a/x-pack/plugins/canvas/public/lib/es_service.js b/x-pack/plugins/canvas/public/lib/es_service.js index 879bf69624819..e4d2b2c9db541 100644 --- a/x-pack/plugins/canvas/public/lib/es_service.js +++ b/x-pack/plugins/canvas/public/lib/es_service.js @@ -5,6 +5,7 @@ */ import chrome from 'ui/chrome'; +import { i18n } from '@kbn/i18n'; import { API_ROUTE } from '../../common/lib/constants'; import { fetch } from '../../common/lib/fetch'; import { notify } from './notify'; @@ -21,7 +22,12 @@ export const getFields = (index = '_all') => { .sort() ) .catch(err => - notify.error(err, { title: `Couldn't fetch Elasticsearch fields for '${index}'` }) + notify.error(err, { + title: i18n.translate('xpack.canvas.esService.fetchElasticsearchFieldsErrorMessageTitle', { + defaultMessage: "Couldn't fetch Elasticsearch fields for '{index}'", + values: { index }, + }), + }) ); }; @@ -29,5 +35,11 @@ export const getIndices = () => { return fetch .get(`${apiPath}/es_indices`) .then(({ data: indices }) => indices) - .catch(err => notify.error(err, { title: `Couldn't fetch Elasticsearch indices` })); + .catch(err => + notify.error(err, { + title: i18n.translate('xpack.canvas.esService.fetchElasticsearchIndicesErrorMessageTitle', { + defaultMessage: "Couldn't fetch Elasticsearch indices", + }), + }) + ); }; diff --git a/x-pack/plugins/canvas/public/lib/find_expression_type.js b/x-pack/plugins/canvas/public/lib/find_expression_type.js index c70a1ec719fe8..c2d3a009bdde1 100644 --- a/x-pack/plugins/canvas/public/lib/find_expression_type.js +++ b/x-pack/plugins/canvas/public/lib/find_expression_type.js @@ -4,6 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ +import { i18n } from '@kbn/i18n'; import { datasourceRegistry } from '../expression_types/datasource'; import { transformRegistry } from '../expression_types/transform'; import { modelRegistry } from '../expression_types/model'; @@ -36,6 +37,16 @@ export function findExpressionType(name, type) { } }, []); - if (matches.length > 1) throw new Error(`Found multiple expressions with name "${name}"`); + if (matches.length > 1) { + throw new Error( + i18n.translate( + 'xpack.canvas.findExpressionType.multipleExpressionWithTheSameNameErrorMessage', + { + defaultMessage: 'Found multiple expressions with name "{name}"', + values: { name }, + } + ) + ); + } return matches[0] || null; } diff --git a/x-pack/plugins/canvas/public/lib/history_provider.js b/x-pack/plugins/canvas/public/lib/history_provider.js index 9b7f907ceeedf..49e58e896957d 100644 --- a/x-pack/plugins/canvas/public/lib/history_provider.js +++ b/x-pack/plugins/canvas/public/lib/history_provider.js @@ -6,6 +6,7 @@ import chrome from 'ui/chrome'; import lzString from 'lz-string'; +import { i18n } from '@kbn/i18n'; import { createBrowserHistory, createMemoryHistory, parsePath, createPath } from 'history'; import { get } from 'lodash'; import { APP_ROUTE } from '../../common/lib/constants'; @@ -52,7 +53,12 @@ function wrapHistoryInstance(history) { const stateJSON = JSON.stringify(state); return lzString.compress(stateJSON); } catch (e) { - throw new Error('Could not encode state: ', e.message); + throw new Error( + i18n.translate('xpack.canvas.historyProvider.encodeStateErrorMessage', { + defaultMessage: 'Could not encode state: {errorMessage}', + values: { errorMessage: e.message }, + }) + ); } }, diff --git a/x-pack/plugins/canvas/public/lib/legend_options.js b/x-pack/plugins/canvas/public/lib/legend_options.js index 0b72f164c6dc3..c732199a94295 100644 --- a/x-pack/plugins/canvas/public/lib/legend_options.js +++ b/x-pack/plugins/canvas/public/lib/legend_options.js @@ -4,25 +4,37 @@ * you may not use this file except in compliance with the Elastic License. */ +import { i18n } from '@kbn/i18n'; + export const legendOptions = [ { - name: 'Hidden', + name: i18n.translate('xpack.canvas.legendOptions.hiddenNameText', { + defaultMessage: 'Hidden', + }), value: false, }, { - name: 'Top Left', + name: i18n.translate('xpack.canvas.legendOptions.topLeftNameText', { + defaultMessage: 'Top Left', + }), value: 'nw', }, { - name: 'Top Right', + name: i18n.translate('xpack.canvas.legendOptions.topRightNameText', { + defaultMessage: 'Top Right', + }), value: 'ne', }, { - name: 'Bottom Left', + name: i18n.translate('xpack.canvas.legendOptions.bottomLeftNameText', { + defaultMessage: 'Bottom Left', + }), value: 'sw', }, { - name: 'Bottom Right', + name: i18n.translate('xpack.canvas.legendOptions.bottomRightNameText', { + defaultMessage: 'Bottom Right', + }), value: 'se', }, ]; diff --git a/x-pack/plugins/canvas/public/lib/parse_single_function_chain.js b/x-pack/plugins/canvas/public/lib/parse_single_function_chain.js index f8eec880af624..0fbfb04efba9b 100644 --- a/x-pack/plugins/canvas/public/lib/parse_single_function_chain.js +++ b/x-pack/plugins/canvas/public/lib/parse_single_function_chain.js @@ -5,6 +5,7 @@ */ import { get, mapValues, map } from 'lodash'; +import { i18n } from '@kbn/i18n'; import { fromExpression } from '../../common/lib/ast'; export function parseSingleFunctionChain(filterString) { @@ -13,7 +14,16 @@ export function parseSingleFunctionChain(filterString) { // Check if the current column is what we expect it to be. If the user changes column this will be called again, // but we don't want to run setFilter() unless we have to because it will cause a data refresh const name = get(ast, 'chain[0].function'); - if (!name) throw new Error('Could not find function name in chain'); + if (!name) { + throw new Error( + i18n.translate( + 'xpack.canvas.parseSingleFunctionChain.functionNameInChainNotFindErrorMessage', + { + defaultMessage: 'Could not find function name in chain', + } + ) + ); + } const args = mapValues(get(ast, 'chain[0].arguments'), val => { // TODO Check for literals only diff --git a/x-pack/plugins/canvas/public/lib/router_provider.js b/x-pack/plugins/canvas/public/lib/router_provider.js index eac87fd51a2a7..33a143cb47e3d 100644 --- a/x-pack/plugins/canvas/public/lib/router_provider.js +++ b/x-pack/plugins/canvas/public/lib/router_provider.js @@ -5,6 +5,7 @@ */ import createRouter from '@scant/router'; +import { i18n } from '@kbn/i18n'; import { getWindow } from './get_window'; import { historyProvider } from './history_provider'; @@ -51,8 +52,16 @@ export function routerProvider(routes) { updateLocation(name, params, state, true); }, onPathChange(fn) { - if (componentListener != null) - throw new Error('Only one route component listener is allowed'); + if (componentListener != null) { + throw new Error( + i18n.translate( + 'xpack.canvas.routerProvider.multipleRouteComponentListenersErrorMessage', + { + defaultMessage: 'Only one route component listener is allowed', + } + ) + ); + } const execOnMatch = location => { const { pathname } = location; diff --git a/x-pack/plugins/canvas/public/lib/run_interpreter.js b/x-pack/plugins/canvas/public/lib/run_interpreter.js index cc0d9a7544786..6b9f1465f5961 100644 --- a/x-pack/plugins/canvas/public/lib/run_interpreter.js +++ b/x-pack/plugins/canvas/public/lib/run_interpreter.js @@ -4,6 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ +import { i18n } from '@kbn/i18n'; import { fromExpression } from '../../common/lib/ast'; import { getType } from '../../common/lib/get_type'; import { interpretAst } from './interpreter'; @@ -30,7 +31,12 @@ export function runInterpreter(ast, context = null, options = {}) { }); } - return new Error(`Ack! I don't know how to render a '${getType(renderable)}'`); + return new Error( + i18n.translate('xpack.canvas.runInterpreter.unknownTypeForRenderErrorMessage', { + defaultMessage: "Unknown type '{getType}' for render", + values: { getType: getType(renderable) }, + }) + ); }) .catch(err => { notify.error(err); diff --git a/x-pack/plugins/canvas/public/lib/window_error_handler.js b/x-pack/plugins/canvas/public/lib/window_error_handler.js index b0b1c14a336d6..c2ef70670d0ee 100644 --- a/x-pack/plugins/canvas/public/lib/window_error_handler.js +++ b/x-pack/plugins/canvas/public/lib/window_error_handler.js @@ -4,6 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ +import { i18n } from '@kbn/i18n'; import * as knownErrors from '../../common/lib/errors'; const oldHandler = window.onerror; @@ -21,10 +22,21 @@ function showError(err) { }; notice.appendChild(close); - notice.insertAdjacentHTML('beforeend', '
Check console for more information
`); + const checkConsoleMessage = i18n.translate( + 'xpack.canvas.windowErrorHandler.checkConsoleMessage', + { + defaultMessage: 'Check console for more information', + } + ); + + // eslint-disable-next-line no-unsanitized/method + notice.insertAdjacentHTML('beforeend', `${checkConsoleMessage}
`); body.appendChild(notice); }