From f08313297f8e3c3ee166aa02bf47e9ab53e8f711 Mon Sep 17 00:00:00 2001 From: Nox911 Date: Tue, 4 Dec 2018 19:21:22 +0300 Subject: [PATCH] [i18n] Translate courier (#26514) * Translate courier * Fix issues * Fix issues --- src/ui/public/courier/fetch/call_client.js | 7 +++- .../courier/fetch/call_response_handlers.js | 10 ++++-- src/ui/public/courier/fetch/fetch_now.js | 7 +++- .../request/search_request/search_request.js | 22 ++++++++++-- .../courier/saved_object/saved_object.js | 34 +++++++++++++++---- .../ui/saved_object_save_as_checkbox.html | 20 +++++++---- .../search_strategy/no_op_search_strategy.js | 9 +++-- 7 files changed, 87 insertions(+), 22 deletions(-) diff --git a/src/ui/public/courier/fetch/call_client.js b/src/ui/public/courier/fetch/call_client.js index 962d5366a0f93..174b7185623c3 100644 --- a/src/ui/public/courier/fetch/call_client.js +++ b/src/ui/public/courier/fetch/call_client.js @@ -23,6 +23,7 @@ import { IsRequestProvider } from './is_request'; import { MergeDuplicatesRequestProvider } from './merge_duplicate_requests'; import { RequestStatus } from './req_status'; import { SerializeFetchParamsProvider } from './request/serialize_fetch_params'; +import { i18n } from '@kbn/i18n'; export function CallClientProvider(Private, Promise, es, config) { const errorAllowExplicitIndex = Private(ErrorAllowExplicitIndexProvider); @@ -95,7 +96,11 @@ export function CallClientProvider(Private, Promise, es, config) { // handle a request being aborted while being fetched const requestWasAborted = Promise.method(function (searchRequest, index) { if (searchRequestsAndStatuses[index] === ABORTED) { - defer.reject(new Error('Request was aborted twice?')); + defer.reject(new Error( + i18n.translate('common.ui.courier.fetch.requestWasAbortedTwiceErrorMessage', { + defaultMessage: 'Request was aborted twice?', + }) + )); } requestsToFetchCount--; diff --git a/src/ui/public/courier/fetch/call_response_handlers.js b/src/ui/public/courier/fetch/call_response_handlers.js index 766ea8af3a0e8..bc3f43fb8eddf 100644 --- a/src/ui/public/courier/fetch/call_response_handlers.js +++ b/src/ui/public/courier/fetch/call_response_handlers.js @@ -21,6 +21,7 @@ import { toastNotifications } from '../../notify'; import { RequestFailure } from '../../errors'; import { RequestStatus } from './req_status'; import { SearchError } from '../search_strategy/search_error'; +import { i18n } from '@kbn/i18n'; export function CallResponseHandlersProvider(Private, Promise) { const ABORTED = RequestStatus.ABORTED; @@ -36,13 +37,18 @@ export function CallResponseHandlersProvider(Private, Promise) { if (response.timed_out) { toastNotifications.addWarning({ - title: 'Data might be incomplete because your request timed out', + title: i18n.translate('common.ui.courier.fetch.requestTimedOutNotificationMessage', { + defaultMessage: 'Data might be incomplete because your request timed out', + }) }); } if (response._shards && response._shards.failed) { toastNotifications.addWarning({ - title: `${response._shards.failed} of ${response._shards.total} shards failed`, + title: i18n.translate('common.ui.courier.fetch.shardsFailedNotificationMessage', { + defaultMessage: '{shardsFailed} of {shardsTotal} shards failed', + values: { shardsFailed: response._shards.failed, shardsTotal: response._shards.total } + }) }); } diff --git a/src/ui/public/courier/fetch/fetch_now.js b/src/ui/public/courier/fetch/fetch_now.js index 7bb3890fbf95e..5e2eda307be89 100644 --- a/src/ui/public/courier/fetch/fetch_now.js +++ b/src/ui/public/courier/fetch/fetch_now.js @@ -22,6 +22,7 @@ import { CallClientProvider } from './call_client'; import { CallResponseHandlersProvider } from './call_response_handlers'; import { ContinueIncompleteProvider } from './continue_incomplete'; import { RequestStatus } from './req_status'; +import { i18n } from '@kbn/i18n'; /** * Fetch now provider should be used if you want the results searched and returned immediately. @@ -95,7 +96,11 @@ export function FetchNowProvider(Private, Promise) { return null; case DUPLICATE: case INCOMPLETE: - throw new Error('Failed to clear incomplete or duplicate request from responses.'); + throw new Error( + i18n.translate('common.ui.courier.fetch.failedToClearRequestErrorMessage', { + defaultMessage: 'Failed to clear incomplete or duplicate request from responses.', + }) + ); default: return resp; } diff --git a/src/ui/public/courier/fetch/request/search_request/search_request.js b/src/ui/public/courier/fetch/request/search_request/search_request.js index 1471df8d35223..8d983961c4fa1 100644 --- a/src/ui/public/courier/fetch/request/search_request/search_request.js +++ b/src/ui/public/courier/fetch/request/search_request/search_request.js @@ -21,11 +21,18 @@ import moment from 'moment'; import { searchRequestQueue } from '../../../search_request_queue'; +import { i18n } from '@kbn/i18n'; + export function SearchRequestProvider(Promise) { class SearchRequest { constructor({ source, defer, errorHandler }) { if (!errorHandler) { - throw new Error('errorHandler is required'); + throw new Error( + i18n.translate('common.ui.courier.fetch.requireErrorHandlerErrorMessage', { + defaultMessage: '{errorHandler} is required', + values: { errorHandler: 'errorHandler' } + }) + ); } this.errorHandler = errorHandler; @@ -99,7 +106,11 @@ export function SearchRequestProvider(Promise) { start() { if (this.started) { - throw new TypeError('Unable to start request because it has already started'); + throw new TypeError( + i18n.translate('common.ui.courier.fetch.unableStartRequestErrorMessage', { + defaultMessage: 'Unable to start request because it has already started', + }) + ); } this.started = true; @@ -133,7 +144,12 @@ export function SearchRequestProvider(Promise) { } continue() { - throw new Error('Unable to continue ' + this.type + ' request'); + throw new Error( + i18n.translate('common.ui.courier.fetch.unableContinueRequestErrorMessage', { + defaultMessage: 'Unable to continue {type} request', + values: { type: this.type } + }) + ); } retry() { diff --git a/src/ui/public/courier/saved_object/saved_object.js b/src/ui/public/courier/saved_object/saved_object.js index 11fd135b4cf21..e2170b4240212 100644 --- a/src/ui/public/courier/saved_object/saved_object.js +++ b/src/ui/public/courier/saved_object/saved_object.js @@ -38,18 +38,23 @@ import { SearchSourceProvider } from '../search_source'; import { SavedObjectsClientProvider, findObjectByTitle } from '../../saved_objects'; import { migrateLegacyQuery } from '../../utils/migrate_legacy_query'; import { recentlyAccessed } from '../../persisted_log'; +import { i18n } from '@kbn/i18n'; /** * An error message to be used when the user rejects a confirm overwrite. * @type {string} */ -const OVERWRITE_REJECTED = 'Overwrite confirmation was rejected'; +const OVERWRITE_REJECTED = i18n.translate('common.ui.courier.savedObject.overwriteRejectedDescription', { + defaultMessage: 'Overwrite confirmation was rejected' +}); /** * An error message to be used when the user rejects a confirm save with duplicate title. * @type {string} */ -const SAVE_DUPLICATE_REJECTED = 'Save with duplicate title confirmation was rejected'; +const SAVE_DUPLICATE_REJECTED = i18n.translate('common.ui.courier.savedObject.saveDuplicateRejectedDescription', { + defaultMessage: 'Save with duplicate title confirmation was rejected' +}); /** * @param error {Error} the error @@ -312,9 +317,17 @@ export function SavedObjectProvider(Promise, Private, Notifier, confirmModalProm .catch(err => { // record exists, confirm overwriting if (_.get(err, 'res.status') === 409) { - const confirmMessage = `Are you sure you want to overwrite ${this.title}?`; + const confirmMessage = i18n.translate('common.ui.courier.savedObject.confirmModal.overwriteConfirmationMessage', { + defaultMessage: 'Are you sure you want to overwrite {title}?', + values: { title: this.title } + }); - return confirmModalPromise(confirmMessage, { confirmButtonText: `Overwrite ${this.getDisplayName()}` }) + return confirmModalPromise(confirmMessage, { + confirmButtonText: i18n.translate('common.ui.courier.savedObject.confirmModal.overwriteButtonLabel', { + defaultMessage: 'Overwrite {name}', + values: { name: this.getDisplayName() } + }) + }) .then(() => savedObjectsClient.create(esType, source, this.creationOpts({ overwrite: true }))) .catch(() => Promise.reject(new Error(OVERWRITE_REJECTED))); } @@ -323,10 +336,17 @@ export function SavedObjectProvider(Promise, Private, Notifier, confirmModalProm }; const displayDuplicateTitleConfirmModal = () => { - const confirmMessage = - `A ${this.getDisplayName()} with the title '${this.title}' already exists. Would you like to save anyway?`; + const confirmMessage = i18n.translate('common.ui.courier.savedObject.confirmModal.saveDuplicateConfirmationMessage', { + defaultMessage: `A {name} with the title '{title}' already exists. Would you like to save anyway?`, + values: { title: this.title, name: this.getDisplayName() } + }); - return confirmModalPromise(confirmMessage, { confirmButtonText: `Save ${this.getDisplayName()}` }) + return confirmModalPromise(confirmMessage, { + confirmButtonText: i18n.translate('common.ui.courier.savedObject.confirmModal.saveDuplicateButtonLabel', { + defaultMessage: 'Save {name}', + values: { name: this.getDisplayName() } + }) + }) .catch(() => Promise.reject(new Error(SAVE_DUPLICATE_REJECTED))); }; diff --git a/src/ui/public/courier/saved_object/ui/saved_object_save_as_checkbox.html b/src/ui/public/courier/saved_object/ui/saved_object_save_as_checkbox.html index 7a60990d20ed6..656fe06bca426 100644 --- a/src/ui/public/courier/saved_object/ui/saved_object_save_as_checkbox.html +++ b/src/ui/public/courier/saved_object/ui/saved_object_save_as_checkbox.html @@ -1,7 +1,12 @@
-
- In previous versions of Kibana, changing the name of a {{savedObject.getDisplayName()}} would make a copy with the new name. Use the 'Save as a new {{savedObject.getDisplayName()}}' checkbox to do this now. -
+
diff --git a/src/ui/public/courier/search_strategy/no_op_search_strategy.js b/src/ui/public/courier/search_strategy/no_op_search_strategy.js index ada96a36c4820..c4499cc870d56 100644 --- a/src/ui/public/courier/search_strategy/no_op_search_strategy.js +++ b/src/ui/public/courier/search_strategy/no_op_search_strategy.js @@ -18,6 +18,7 @@ */ import { SearchError } from './search_error'; +import { i18n } from '@kbn/i18n'; export const noOpSearchStrategy = { id: 'noOp', @@ -25,8 +26,12 @@ export const noOpSearchStrategy = { search: async () => { const searchError = new SearchError({ status: '418', // "I'm a teapot" error - title: 'No search strategy registered', - message: `Couldn't find a search strategy for the search request`, + title: i18n.translate('common.ui.courier.noSearchStrategyRegisteredErrorMessageTitle', { + defaultMessage: 'No search strategy registered', + }), + message: i18n.translate('common.ui.courier.noSearchStrategyRegisteredErrorMessageDescription', { + defaultMessage: `Couldn't find a search strategy for the search request`, + }), type: 'NO_OP_SEARCH_STRATEGY', path: '', });