From 43d4c22add95e6693972b967d1d8f09b45b153ad Mon Sep 17 00:00:00 2001 From: Leanid Shutau Date: Thu, 22 Nov 2018 13:41:03 +0300 Subject: [PATCH] [I18n] Translate Graph (#23987) * [I18n] Add Graph translations * Fix typo * Use template strings --- .i18nrc.json | 1 + x-pack/plugins/graph/public/app.js | 150 ++++++-- .../plugins/graph/public/register_feature.js | 6 +- .../graph/public/services/outlink_encoders.js | 50 ++- .../plugins/graph/public/templates/index.html | 325 +++++++++++++----- .../public/templates/load_workspace.html | 8 +- .../public/templates/save_workspace.html | 50 ++- .../graph/public/templates/settings.html | 223 ++++++++---- .../plugins/graph/server/lib/check_license.js | 22 +- 9 files changed, 620 insertions(+), 215 deletions(-) diff --git a/.i18nrc.json b/.i18nrc.json index 0c780d84c5b1a9..45108fa6b8e63d 100644 --- a/.i18nrc.json +++ b/.i18nrc.json @@ -14,6 +14,7 @@ "tileMap": "src/core_plugins/tile_map", "timelion": "src/core_plugins/timelion", "tagCloud": "src/core_plugins/tagcloud", + "xpack.graph": "x-pack/plugins/graph", "xpack.grokDebugger": "x-pack/plugins/grokdebugger", "xpack.idxMgmt": "x-pack/plugins/index_management", "xpack.infra": "x-pack/plugins/infra", diff --git a/x-pack/plugins/graph/public/app.js b/x-pack/plugins/graph/public/app.js index f7fa2f01bf2887..77ae583ad259db 100644 --- a/x-pack/plugins/graph/public/app.js +++ b/x-pack/plugins/graph/public/app.js @@ -39,7 +39,7 @@ import { drillDownIconChoicesByClass } from './style_choices'; import { - outlinkEncoders + getOutlinkEncoders, } from './services/outlink_encoders'; const app = uiModules.get('app/graph'); @@ -96,11 +96,15 @@ uiRoutes .when('/workspace/:id', { template: appTemplate, resolve: { - savedWorkspace: function (savedGraphWorkspaces, courier, $route) { + savedWorkspace: function (savedGraphWorkspaces, courier, $route, i18n) { return savedGraphWorkspaces.get($route.current.params.id) .catch( function () { - toastNotifications.addDanger('Missing workspace'); + toastNotifications.addDanger( + i18n('xpack.graph.missingWorkspaceErrorMessage', { + defaultMessage: 'Missing workspace', + }) + ); } ); @@ -131,7 +135,7 @@ uiRoutes //======== Controller for basic UI ================== -app.controller('graphuiPlugin', function ($scope, $route, $interval, $http, kbnUrl, Private, Promise, confirmModal, kbnBaseUrl) { +app.controller('graphuiPlugin', function ($scope, $route, $interval, $http, kbnUrl, Private, Promise, confirmModal, kbnBaseUrl, i18n) { function handleSuccess(data) { return checkLicense(Private, Promise, kbnBaseUrl) @@ -151,7 +155,7 @@ app.controller('graphuiPlugin', function ($scope, $route, $interval, $http, kbnU $scope.colors = colorChoices; $scope.iconChoicesByClass = iconChoicesByClass; - $scope.outlinkEncoders = outlinkEncoders; + $scope.outlinkEncoders = getOutlinkEncoders(i18n); $scope.fields = []; $scope.canEditDrillDownUrls = chrome.getInjected('canEditDrillDownUrls'); @@ -290,9 +294,13 @@ app.controller('graphuiPlugin', function ($scope, $route, $interval, $http, kbnU const confirmModalOptions = { onConfirm: yesFn, onCancel: noFn, - confirmButtonText: 'Clear workspace' + confirmButtonText: i18n('xpack.graph.clearWorkspace.confirmButtonLabel', { + defaultMessage: 'Clear workspace', + }) }; - confirmModal('This will clear the workspace - are you sure?', confirmModalOptions); + confirmModal(i18n('xpack.graph.clearWorkspace.confirmText', { + defaultMessage: 'This will clear the workspace - are you sure?', + }), confirmModalOptions); } $scope.uiSelectIndex = function () { @@ -387,7 +395,11 @@ app.controller('graphuiPlugin', function ($scope, $route, $interval, $http, kbnU return $http.post('../api/graph/graphExplore', request) .then(function (resp) { if (resp.data.resp.timed_out) { - toastNotifications.addWarning('Exploration timed out'); + toastNotifications.addWarning( + i18n('xpack.graph.exploreGraph.timedOutWarningText', { + defaultMessage: 'Exploration timed out', + }) + ); } responseHandler(resp.data.resp); }) @@ -536,8 +548,15 @@ app.controller('graphuiPlugin', function ($scope, $route, $interval, $http, kbnU const found = $scope.newUrlTemplate.url.search(drillDownRegex) > -1; if (!found) { toastNotifications.addWarning({ - title: 'Invalid URL', - text: 'The URL must contain a {{gquery}} string', + title: i18n('xpack.graph.settings.drillDowns.invalidUrlWarningTitle', { + defaultMessage: 'Invalid URL', + }), + text: i18n('xpack.graph.settings.drillDowns.invalidUrlWarningText', { + defaultMessage: 'The URL must contain a {placeholder} string', + values: { + placeholder: '{{gquery}}' + } + }), }); return; } @@ -556,10 +575,18 @@ app.controller('graphuiPlugin', function ($scope, $route, $interval, $http, kbnU $scope.removeUrlTemplate = function (urlTemplate) { const i = $scope.urlTemplates.indexOf(urlTemplate); if (i != -1) { - confirmModal('Remove "' + urlTemplate.description + '" drill-down?', { - onConfirm: () => $scope.urlTemplates.splice(i, 1), - confirmButtonText: 'Remove drill-down' - }); + confirmModal( + i18n('xpack.graph.settings.drillDowns.removeConfirmText', { + defaultMessage: 'Remove "{urlTemplateDesciption}" drill-down?', + values: { urlTemplateDesciption: urlTemplate.description }, + }), + { + onConfirm: () => $scope.urlTemplates.splice(i, 1), + confirmButtonText: i18n('xpack.graph.settings.drillDowns.removeConfirmButtonLabel', { + defaultMessage: 'Remove drill-down', + }), + }, + ); } }; @@ -651,7 +678,9 @@ app.controller('graphuiPlugin', function ($scope, $route, $interval, $http, kbnU $scope.urlTemplates.push({ url: discoverUrl, - description: 'Raw documents', + description: i18n('xpack.graph.settings.drillDowns.defaultUrlTemplateTitle', { + defaultMessage: 'Raw documents', + }), encoder: $scope.outlinkEncoders[0] }); } @@ -730,30 +759,46 @@ app.controller('graphuiPlugin', function ($scope, $route, $interval, $http, kbnU $scope.topNavMenu = []; $scope.topNavMenu.push({ key: 'new', - description: 'New Workspace', - tooltip: 'Create a new workspace', + description: i18n('xpack.graph.topNavMenu.newWorkspaceAriaLabel', { + defaultMessage: 'New Workspace', + }), + tooltip: i18n('xpack.graph.topNavMenu.newWorkspaceTooltip', { + defaultMessage: 'Create a new workspace', + }), run: function () {canWipeWorkspace(function () {kbnUrl.change('/home', {}); }); }, }); if (!$scope.allSavingDisabled) { $scope.topNavMenu.push({ key: 'save', - description: 'Save Workspace', - tooltip: 'Save this workspace', + description: i18n('xpack.graph.topNavMenu.saveWorkspace.enabledAriaLabel', { + defaultMessage: 'Save Workspace', + }), + tooltip: i18n('xpack.graph.topNavMenu.saveWorkspace.enabledTooltip', { + defaultMessage: 'Save this workspace', + }), disableButton: function () {return $scope.selectedFields.length === 0;}, template: require('./templates/save_workspace.html') }); }else { $scope.topNavMenu.push({ key: 'save', - description: 'Save Workspace', - tooltip: 'No changes to saved workspaces are permitted by the current save policy', + description: i18n('xpack.graph.topNavMenu.saveWorkspace.disabledAriaLabel', { + defaultMessage: 'Save Workspace', + }), + tooltip: i18n('xpack.graph.topNavMenu.saveWorkspace.disabledTooltip', { + defaultMessage: 'No changes to saved workspaces are permitted by the current save policy', + }), disableButton: true }); } $scope.topNavMenu.push({ key: 'open', - description: 'Load Saved Workspace', - tooltip: 'Load a saved workspace', + description: i18n('xpack.graph.topNavMenu.loadWorkspaceAriaLabel', { + defaultMessage: 'Load Saved Workspace', + }), + tooltip: i18n('xpack.graph.topNavMenu.loadWorkspaceTooltip', { + defaultMessage: 'Load a saved workspace', + }), template: require('./templates/load_workspace.html') }); if (!$scope.allSavingDisabled) { @@ -762,35 +807,58 @@ app.controller('graphuiPlugin', function ($scope, $route, $interval, $http, kbnU disableButton: function () { return $route.current.locals === undefined || $route.current.locals.savedWorkspace === undefined; }, - description: 'Delete Saved Workspace', - tooltip: 'Delete this workspace', + description: i18n('xpack.graph.topNavMenu.deleteWorkspace.enabledAriaLabel', { + defaultMessage: 'Delete Saved Workspace', + }), + tooltip: i18n('xpack.graph.topNavMenu.deleteWorkspace.enabledAriaTooltip', { + defaultMessage: 'Delete this workspace', + }), run: function () { const title = $route.current.locals.savedWorkspace.title; function doDelete() { $route.current.locals.SavedWorkspacesProvider.delete($route.current.locals.savedWorkspace.id); kbnUrl.change('/home', {}); - toastNotifications.addSuccess(`Deleted '${title}'`); + toastNotifications.addSuccess( + i18n('xpack.graph.topNavMenu.deleteWorkspaceNotification', { + defaultMessage: `Deleted '{workspaceTitle}'`, + values: { workspaceTitle: title }, + }) + ); } const confirmModalOptions = { onConfirm: doDelete, - confirmButtonText: 'Delete workspace' + confirmButtonText: i18n('xpack.graph.topNavMenu.deleteWorkspace.confirmButtonLabel', { + defaultMessage: 'Delete workspace', + }), }; - confirmModal('Are you sure you want to delete the workspace ' + title + ' ?', confirmModalOptions); + confirmModal( + i18n('xpack.graph.topNavMenu.deleteWorkspace.confirmText', { + defaultMessage: 'Are you sure you want to delete the workspace {title} ?', + values: { title }, + }), + confirmModalOptions + ); } }); }else { $scope.topNavMenu.push({ key: 'delete', disableButton: true, - description: 'Delete Saved Workspace', - tooltip: 'No changes to saved workspaces are permitted by the current save policy' + description: i18n('xpack.graph.topNavMenu.deleteWorkspace.disabledAriaLabel', { + defaultMessage: 'Delete Saved Workspace', + }), + tooltip: i18n('xpack.graph.topNavMenu.deleteWorkspace.disabledTooltip', { + defaultMessage: 'No changes to saved workspaces are permitted by the current save policy', + }), }); } $scope.topNavMenu.push({ key: 'settings', disableButton: function () { return $scope.selectedIndex === null; }, - description: 'Settings', + description: i18n('xpack.graph.topNavMenu.settingsAriaLabel', { + defaultMessage: 'Settings', + }), template: require('./templates/settings.html') }); @@ -829,7 +897,12 @@ app.controller('graphuiPlugin', function ($scope, $route, $interval, $http, kbnU } }); if(!savedObjectIndexPattern) { - toastNotifications.addDanger(`'Missing index pattern ${wsObj.indexPattern}`); + toastNotifications.addDanger( + i18n('xpack.graph.loadWorkspace.missingIndexPatternErrorMessage', { + defaultMessage: `'Missing index pattern {indexPattern}`, + values: { indexPattern: wsObj.indexPattern }, + }) + ); return; } @@ -946,7 +1019,9 @@ app.controller('graphuiPlugin', function ($scope, $route, $interval, $http, kbnU if ($scope.allSavingDisabled) { // It should not be possible to navigate to this function if allSavingDisabled is set // but adding check here as a safeguard. - toastNotifications.addWarning('Saving is disabled'); + toastNotifications.addWarning( + i18n('xpack.graph.saveWorkspace.disabledWarning', { defaultMessage: 'Saving is disabled' }) + ); return; } initWorkspaceIfRequired(); @@ -1034,10 +1109,15 @@ app.controller('graphuiPlugin', function ($scope, $route, $interval, $http, kbnU $scope.kbnTopNav.close('save'); $scope.userHasConfirmedSaveWorkspaceData = false; //reset flag if (id) { - const title = `Saved "${$scope.savedWorkspace.title}"`; + const title = i18n('xpack.graph.saveWorkspace.successNotificationTitle', { + defaultMessage: 'Saved "{workspaceTitle}"', + values: { workspaceTitle: $scope.savedWorkspace.title }, + }); let text; if (!canSaveData && $scope.workspace.nodes.length > 0) { - text = 'The configuration was saved, but the data was not saved'; + text = i18n('xpack.graph.saveWorkspace.successNotification.noDataSavedText', { + defaultMessage: 'The configuration was saved, but the data was not saved', + }); } toastNotifications.addSuccess({ diff --git a/x-pack/plugins/graph/public/register_feature.js b/x-pack/plugins/graph/public/register_feature.js index d7806149725629..c147982dc081c5 100644 --- a/x-pack/plugins/graph/public/register_feature.js +++ b/x-pack/plugins/graph/public/register_feature.js @@ -8,11 +8,13 @@ import { FeatureCatalogueRegistryProvider, FeatureCatalogueCategory } from 'ui/registry/feature_catalogue'; -FeatureCatalogueRegistryProvider.register(() => { +FeatureCatalogueRegistryProvider.register((i18n) => { return { id: 'graph', title: 'Graph', - description: 'Surface and analyze relevant relationships in your Elasticsearch data.', + description: i18n('xpack.graph.pluginDescription', { + defaultMessage: 'Surface and analyze relevant relationships in your Elasticsearch data.', + }), icon: 'graphApp', path: '/app/graph', showOnHomePage: true, diff --git a/x-pack/plugins/graph/public/services/outlink_encoders.js b/x-pack/plugins/graph/public/services/outlink_encoders.js index e32fd090ff13d3..cfc9d745cf8e8c 100644 --- a/x-pack/plugins/graph/public/services/outlink_encoders.js +++ b/x-pack/plugins/graph/public/services/outlink_encoders.js @@ -6,38 +6,58 @@ import rison from 'rison-node'; -export const outlinkEncoders = [{ +export const getOutlinkEncoders = i18n => [{ id: 'esq-rison-loose', - title: 'elasticsearch OR query (rison encoded)', - description: 'rison-encoded JSON, minimum_should_match=1, compatible with most Kibana URLs', + title: i18n('xpack.graph.outlinkEncoders.esqRisonLooseTitle', { + defaultMessage: 'elasticsearch OR query (rison encoded)', + }), + description: i18n('xpack.graph.outlinkEncoders.esqRisonLooseDescription', { + defaultMessage: 'rison-encoded JSON, minimum_should_match=1, compatible with most Kibana URLs', + }), encode: function (workspace) { return encodeURIComponent(rison.encode(workspace.getQuery(workspace.getSelectedOrAllNodes(), true))); } }, { id: 'esq-rison', - title: 'elasticsearch AND query (rison encoded)', - description: 'rison-encoded JSON, minimum_should_match=2, compatible with most Kibana URLs', + title: i18n('xpack.graph.outlinkEncoders.esqRisonTitle', { + defaultMessage: 'elasticsearch AND query (rison encoded)', + }), + description: i18n('xpack.graph.outlinkEncoders.esqRisonDescription', { + defaultMessage: 'rison-encoded JSON, minimum_should_match=2, compatible with most Kibana URLs', + }), encode: function (workspace) { return encodeURIComponent(rison.encode(workspace.getQuery(workspace.getSelectedOrAllNodes()))); } }, { id: 'esq-similar-rison', - title: 'elasticsearch more like this query (rison encoded)', - description: 'rison-encoded JSON, "like this but not this" type query to find missing docs', + title: i18n('xpack.graph.outlinkEncoders.esqSimilarRisonTitle', { + defaultMessage: 'elasticsearch more like this query (rison encoded)', + }), + description: i18n('xpack.graph.outlinkEncoders.esqSimilarRisonDescription', { + defaultMessage: 'rison-encoded JSON, "like this but not this" type query to find missing docs', + }), encode: function (workspace) { return encodeURIComponent(rison.encode(workspace.getLikeThisButNotThisQuery(workspace.getSelectedOrAllNodes()))); } }, { id: 'esq-plain', - title: 'elasticsearch query (plain encoding)', - description: 'JSON encoded using standard url encoding', + title: i18n('xpack.graph.outlinkEncoders.esqPlainTitle', { + defaultMessage: 'elasticsearch query (plain encoding)', + }), + description: i18n('xpack.graph.outlinkEncoders.esqPlainDescription', { + defaultMessage: 'JSON encoded using standard url encoding', + }), encode: function (workspace) { return encodeURIComponent(JSON.stringify(workspace.getQuery(workspace.getSelectedOrAllNodes()))); } }, { id: 'text-plain', - title: 'plain text', - description: 'Text of selected vertex labels as a plain url-encoded string', + title: i18n('xpack.graph.outlinkEncoders.textPlainTitle', { + defaultMessage: 'plain text', + }), + description: i18n('xpack.graph.outlinkEncoders.textPlainDescription', { + defaultMessage: 'Text of selected vertex labels as a plain url-encoded string', + }), encode: function (workspace) { let q = ''; const nodes = workspace.getSelectedOrAllNodes(); @@ -52,8 +72,12 @@ export const outlinkEncoders = [{ } }, { id: 'text-lucene', - title: 'Lucene-escaped text', - description: 'Text of selected vertex labels with any Lucene special characters encoded', + title: i18n('xpack.graph.outlinkEncoders.textLuceneTitle', { + defaultMessage: 'Lucene-escaped text', + }), + description: i18n('xpack.graph.outlinkEncoders.textLuceneDescription', { + defaultMessage: 'Text of selected vertex labels with any Lucene special characters encoded', + }), encode: function (workspace) { let q = ''; const nodes = workspace.getSelectedOrAllNodes(); diff --git a/x-pack/plugins/graph/public/templates/index.html b/x-pack/plugins/graph/public/templates/index.html index 7548c60c9d0eb4..20e54d4f569e5f 100644 --- a/x-pack/plugins/graph/public/templates/index.html +++ b/x-pack/plugins/graph/public/templates/index.html @@ -5,18 +5,36 @@
- {{ savedWorkspace.lastSavedTitle || 'New Graph Workspace' }} + {{ savedWorkspace.lastSavedTitle }} +
- + @@ -27,9 +45,18 @@ - - @@ -39,7 +66,12 @@
-
@@ -51,14 +83,23 @@
- +
- +
@@ -68,13 +109,21 @@
- +
-
@@ -94,7 +143,12 @@
- +
- +
- +
-

Controls the number of terms returned each search step.

+

- Shift-clicking the field icons in the menu bar - provides a quick way to toggle this number to zero and back + + {{ + ::'xpack.graph.queryConfig.maxTermsHelpText' | i18n: { + defaultMessage: 'Shift-clicking the field icons in the menu bar provides a quick way to toggle this number to zero and back' + } + }}
@@ -137,9 +208,12 @@
- +
@@ -222,86 +296,122 @@