From 8e3ba734c173fe2cc17d3a2291d84f670951d428 Mon Sep 17 00:00:00 2001 From: Bamieh Date: Wed, 2 Jan 2019 13:31:24 +0200 Subject: [PATCH] localize job_select_list --- .../job_select_list/job_select_button.html | 9 ++- .../job_select_list/job_select_list.html | 68 +++++++++++++------ .../job_select_list_directive.js | 36 ++++++++-- .../job_select_list/job_select_service.js | 44 +++++++++--- 4 files changed, 116 insertions(+), 41 deletions(-) diff --git a/x-pack/plugins/ml/public/components/job_select_list/job_select_button.html b/x-pack/plugins/ml/public/components/job_select_list/job_select_button.html index b6d4a77fb5e1d..1ca5a8bb9f093 100644 --- a/x-pack/plugins/ml/public/components/job_select_list/job_select_button.html +++ b/x-pack/plugins/ml/public/components/job_select_list/job_select_button.html @@ -1,5 +1,8 @@
-
Job
+
{{description.txt}} diff --git a/x-pack/plugins/ml/public/components/job_select_list/job_select_list.html b/x-pack/plugins/ml/public/components/job_select_list/job_select_list.html index 72f0564926d47..ce1d3aee79f45 100644 --- a/x-pack/plugins/ml/public/components/job_select_list/job_select_list.html +++ b/x-pack/plugins/ml/public/components/job_select_list/job_select_list.html @@ -1,23 +1,28 @@
-
- Job Selection -
+

-
+

- Groups -

+ + +
@@ -25,7 +30,7 @@
-
+

- Jobs -

+ + +
@@ -73,7 +82,11 @@ value="{{job.id}}" ng-model="$parent.$parent.selectedJobRadio" ng-disabled='job.disabled' /> - {{job.id}} + + {{job.id}} +
@@ -82,13 +95,12 @@
-
@@ -97,24 +109,38 @@
-
diff --git a/x-pack/plugins/ml/public/components/job_select_list/job_select_list_directive.js b/x-pack/plugins/ml/public/components/job_select_list/job_select_list_directive.js index 6115618a1113d..b1c013e5edd80 100644 --- a/x-pack/plugins/ml/public/components/job_select_list/job_select_list_directive.js +++ b/x-pack/plugins/ml/public/components/job_select_list/job_select_list_directive.js @@ -25,7 +25,7 @@ import { timefilter } from 'ui/timefilter'; import { uiModules } from 'ui/modules'; const module = uiModules.get('apps/ml'); -module.directive('mlJobSelectList', function (Private) { +module.directive('mlJobSelectList', function (Private, i18n) { return { restrict: 'AE', replace: true, @@ -206,9 +206,20 @@ module.directive('mlJobSelectList', function (Private) { timeRange.toMoment = moment(timeRange.to); timeRange.fromMoment = moment(timeRange.from); - const fromString = timeRange.fromMoment.format('MMM Do YYYY, HH:mm'); - const toString = timeRange.toMoment.format('MMM Do YYYY, HH:mm'); - timeRange.label = `${fromString} to ${toString}`; + const fromStringMomentFormat = i18n('xpack.ml.jobSelectList.groups.timeRange.fromStringMomentFormat', { + defaultMessage: 'MMM Do YYYY, HH:mm', + }); + const fromString = timeRange.fromMoment.format(fromStringMomentFormat); + + const toStringMomentFormat = i18n('xpack.ml.jobSelectList.groups.timeRange.toStringMomentFormat', { + defaultMessage: 'MMM Do YYYY, HH:mm', + }); + const toString = timeRange.toMoment.format(toStringMomentFormat); + + timeRange.label = i18n('xpack.ml.jobSelectList.groups.timeRangeLabel', { + defaultMessage: '{fromString} to {toString}', + values: { fromString, toString } + }); group.timeRange = timeRange; return group; @@ -354,9 +365,20 @@ module.directive('mlJobSelectList', function (Private) { job.timeRange.toMoment = moment(job.timeRange.to); job.timeRange.fromMoment = moment(job.timeRange.from); - const fromString = job.timeRange.fromMoment.format('MMM Do YYYY, HH:mm'); - const toString = job.timeRange.toMoment.format('MMM Do YYYY, HH:mm'); - job.timeRange.label = `${fromString} to ${toString}`; + const fromStringMomentFormat = i18n('xpack.ml.jobSelectList.jobs.timeRange.fromStringMomentFormat', { + defaultMessage: 'MMM Do YYYY, HH:mm', + }); + const fromString = job.timeRange.fromMoment.format(fromStringMomentFormat); + + const toStringMomentFormat = i18n('xpack.ml.jobSelectList.jobs.timeRange.toStringMomentFormat', { + defaultMessage: 'MMM Do YYYY, HH:mm', + }); + const toString = job.timeRange.toMoment.format(toStringMomentFormat); + + job.timeRange.label = i18n('xpack.ml.jobSelectList.jobs.timeRangeLabel', { + defaultMessage: '{fromString} to {toString}', + values: { fromString, toString } + }); } }); diff --git a/x-pack/plugins/ml/public/components/job_select_list/job_select_service.js b/x-pack/plugins/ml/public/components/job_select_list/job_select_service.js index 9e9f31c26ab08..aab5e8b21c2f8 100644 --- a/x-pack/plugins/ml/public/components/job_select_list/job_select_service.js +++ b/x-pack/plugins/ml/public/components/job_select_list/job_select_service.js @@ -15,8 +15,7 @@ import { mlJobService } from 'plugins/ml/services/job_service'; let jobSelectService = undefined; -export function JobSelectServiceProvider($rootScope, globalState) { - +export function JobSelectServiceProvider($rootScope, globalState, i18n) { function checkGlobalState() { if (globalState.ml === undefined) { globalState.ml = {}; @@ -42,7 +41,9 @@ export function JobSelectServiceProvider($rootScope, globalState) { // if there are no valid ids, warn and then select the first job if (validIds.length === 0) { - const warningText = `No jobs selected, auto selecting first job`; + const warningText = i18n('xpack.ml.jobSelectList.noJobsSelectedToast', { + defaultMessage: 'No jobs selected, auto selecting first job', + }); toastNotifications.addWarning(warningText); if (mlJobService.jobs.length) { @@ -89,8 +90,14 @@ export function JobSelectServiceProvider($rootScope, globalState) { function warnAboutInvalidJobIds(invalidIds) { if (invalidIds.length > 0) { - const warningText = (invalidIds.length === 1) ? `Requested job ${invalidIds} does not exist` : - `Requested jobs ${invalidIds} do not exist`; + const warningText = i18n('xpack.ml.jobSelectList.invalidJobIdToast', { + defaultMessage: 'Requested {invalidIdsLength, plural, one {job} other {jobs}} {invalidIds} does not exist', + values: { + invalidIds: invalidIds, + invalidIdsLength: invalidIds.length, + } + }); + toastNotifications.addWarning(warningText); } } @@ -102,7 +109,9 @@ export function JobSelectServiceProvider($rootScope, globalState) { return sum + ((job.groups === undefined) ? 1 : job.groups.length); }, 0); if (jobs.length === count) { - txt = 'All jobs'; + txt = i18n('xpack.ml.jobSelectList.menu.description.allJobs', { + defaultMessage: 'All jobs', + }); } else { // not all jobs have been selected // add up how many jobs belong to groups and how many don't @@ -134,16 +143,31 @@ export function JobSelectServiceProvider($rootScope, globalState) { // show the whole groups first if (wholeGroups.length) { - txt = wholeGroups[0]; + const wholeGroupsTxt = wholeGroups[0]; + txt = wholeGroupsTxt; if (wholeGroups.length > 1 || groupLessJobs > 0) { const total = (wholeGroups.length - 1) + groupLessJobs; - txt += ` and ${total} other${(total > 1 ? 's' : '')}`; + txt = i18n('xpack.ml.jobSelectList.menu.description.wholeGroupsWithOthers', { + defaultMessage: '{wholeGroups} and {remainingGroups} {remainingGroups, plural, one {other} other {others}}', + values: { + wholeGroups: wholeGroupsTxt, + remainingGroups: total + } + }); } } else { // otherwise just list the job ids - txt = splitJobId(jobs[0]).job; + const jobsListText = splitJobId(jobs[0]).job; + txt = jobsListText; if (jobs.length > 1) { - txt += ` and ${jobs.length - 1} other${(jobs.length > 2 ? 's' : '')}`; + txt = i18n('xpack.ml.jobSelectList.menu.description.jobsListWithOthers', { + defaultMessage: '{jobsList} and {remainingJobs} { jobsLength, plural, one {other} two {other} other {others} }', + values: { + jobsList: jobsListText, + jobsLength: jobs.length, + remainingJobs: jobs.length - 1, + } + }); } } }