Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

Commit

Permalink
[I18n] Translate Graph (elastic#23987)
Browse files Browse the repository at this point in the history
* [I18n] Add Graph translations

* Fix typo

* Use template strings
  • Loading branch information
LeanidShutau authored Nov 22, 2018
1 parent acff23e commit 43d4c22
Show file tree
Hide file tree
Showing 9 changed files with 620 additions and 215 deletions.
1 change: 1 addition & 0 deletions .i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
150 changes: 115 additions & 35 deletions x-pack/plugins/graph/public/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
drillDownIconChoicesByClass
} from './style_choices';
import {
outlinkEncoders
getOutlinkEncoders,
} from './services/outlink_encoders';

const app = uiModules.get('app/graph');
Expand Down Expand Up @@ -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',
})
);
}
);

Expand Down Expand Up @@ -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)
Expand All @@ -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');
Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -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);
})
Expand Down Expand Up @@ -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;
}
Expand All @@ -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',
}),
},
);
}
};

Expand Down Expand Up @@ -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]
});
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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')
});

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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({
Expand Down
6 changes: 4 additions & 2 deletions x-pack/plugins/graph/public/register_feature.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
50 changes: 37 additions & 13 deletions x-pack/plugins/graph/public/services/outlink_encoders.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
Loading

0 comments on commit 43d4c22

Please sign in to comment.