Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[I18n] Translate Graph #23987

Merged
merged 9 commits into from
Nov 22, 2018
3 changes: 2 additions & 1 deletion .i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"paths": {
"common.ui": "src/ui",
"console": "src/core_plugins/console",
"inputControl":"src/core_plugins/input_control_vis",
"inputControl": "src/core_plugins/input_control_vis",
"kbn": "src/core_plugins/kibana",
"kbnVislibVisTypes": "src/core_plugins/kbn_vislib_vis_types",
"markdownVis": "src/core_plugins/markdown_vis",
Expand All @@ -13,6 +13,7 @@
"statusPage": "src/core_plugins/status_page",
"tileMap": "src/core_plugins/tile_map",
"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.licenseMgmt": "x-pack/plugins/license_management",
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 {gquery} string',
values: {
gquery: '{{gquery}}'
LeanidShutau marked this conversation as resolved.
Show resolved Hide resolved
}
}),
});
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', {
pavel06081991 marked this conversation as resolved.
Show resolved Hide resolved
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', {
pavel06081991 marked this conversation as resolved.
Show resolved Hide resolved
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', {
LeanidShutau marked this conversation as resolved.
Show resolved Hide resolved
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', {
LeanidShutau marked this conversation as resolved.
Show resolved Hide resolved
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', {
LeanidShutau marked this conversation as resolved.
Show resolved Hide resolved
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', {
LeanidShutau marked this conversation as resolved.
Show resolved Hide resolved
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', {
LeanidShutau marked this conversation as resolved.
Show resolved Hide resolved
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
Loading