Skip to content

Commit

Permalink
[i18n] Translate Agg_types(part_3) (#26118)
Browse files Browse the repository at this point in the history
* Translate agg_types - metrics

* Fix issues
  • Loading branch information
Nox911 authored Nov 27, 2018
1 parent 624f060 commit 51a418e
Show file tree
Hide file tree
Showing 27 changed files with 262 additions and 64 deletions.
10 changes: 8 additions & 2 deletions src/ui/public/agg_types/metrics/avg.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@
*/

import { MetricAggType } from './metric_agg_type';
import { i18n } from '@kbn/i18n';

export const avgMetricAgg = new MetricAggType({
name: 'avg',
title: 'Average',
title: i18n.translate('common.ui.aggTypes.metrics.averageTitle', {
defaultMessage: 'Average'
}),
makeLabel: function (aggConfig) {
return 'Average ' + aggConfig.getFieldDisplayName();
return i18n.translate('common.ui.aggTypes.metrics.averageLabel', {
defaultMessage: 'Average {field}',
values: { field: aggConfig.getFieldDisplayName() }
});
},
params: [
{
Expand Down
11 changes: 9 additions & 2 deletions src/ui/public/agg_types/metrics/bucket_avg.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,18 @@ import { get } from 'lodash';
import { MetricAggType } from './metric_agg_type';
import { makeNestedLabel } from './lib/make_nested_label';
import { siblingPipelineAggHelper } from './lib/sibling_pipeline_agg_helper';
import { i18n } from '@kbn/i18n';

const overallAverageLabel = i18n.translate('common.ui.aggTypes.metrics.overallAverageLabel', {
defaultMessage: 'overall average'
});

export const bucketAvgMetricAgg = new MetricAggType({
name: 'avg_bucket',
title: 'Average Bucket',
makeLabel: agg => makeNestedLabel(agg, 'overall average'),
title: i18n.translate('common.ui.aggTypes.metrics.averageBucketTitle', {
defaultMessage: 'Average Bucket'
}),
makeLabel: agg => makeNestedLabel(agg, overallAverageLabel),
subtype: siblingPipelineAggHelper.subtype,
params: [
...siblingPipelineAggHelper.params()
Expand Down
11 changes: 9 additions & 2 deletions src/ui/public/agg_types/metrics/bucket_max.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,18 @@
import { MetricAggType } from './metric_agg_type';
import { makeNestedLabel } from './lib/make_nested_label';
import { siblingPipelineAggHelper } from './lib/sibling_pipeline_agg_helper';
import { i18n } from '@kbn/i18n';

const overallMaxLabel = i18n.translate('common.ui.aggTypes.metrics.overallMaxLabel', {
defaultMessage: 'overall max'
});

export const bucketMaxMetricAgg = new MetricAggType({
name: 'max_bucket',
title: 'Max Bucket',
makeLabel: agg => makeNestedLabel(agg, 'overall max'),
title: i18n.translate('common.ui.aggTypes.metrics.maxBucketTitle', {
defaultMessage: 'Max Bucket'
}),
makeLabel: agg => makeNestedLabel(agg, overallMaxLabel),
subtype: siblingPipelineAggHelper.subtype,
params: [
...siblingPipelineAggHelper.params()
Expand Down
11 changes: 9 additions & 2 deletions src/ui/public/agg_types/metrics/bucket_min.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,18 @@
import { MetricAggType } from './metric_agg_type';
import { makeNestedLabel } from './lib/make_nested_label';
import { siblingPipelineAggHelper } from './lib/sibling_pipeline_agg_helper';
import { i18n } from '@kbn/i18n';

const overallMinLabel = i18n.translate('common.ui.aggTypes.metrics.overallMinLabel', {
defaultMessage: 'overall min'
});

export const bucketMinMetricAgg = new MetricAggType({
name: 'min_bucket',
title: 'Min Bucket',
makeLabel: agg => makeNestedLabel(agg, 'overall min'),
title: i18n.translate('common.ui.aggTypes.metrics.minBucketTitle', {
defaultMessage: 'Min Bucket'
}),
makeLabel: agg => makeNestedLabel(agg, overallMinLabel),
subtype: siblingPipelineAggHelper.subtype,
params: [
...siblingPipelineAggHelper.params()
Expand Down
11 changes: 9 additions & 2 deletions src/ui/public/agg_types/metrics/bucket_sum.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,18 @@
import { MetricAggType } from './metric_agg_type';
import { makeNestedLabel } from './lib/make_nested_label';
import { siblingPipelineAggHelper } from './lib/sibling_pipeline_agg_helper';
import { i18n } from '@kbn/i18n';

const overallSumLabel = i18n.translate('common.ui.aggTypes.metrics.overallSumLabel', {
defaultMessage: 'overall sum'
});

export const bucketSumMetricAgg = new MetricAggType({
name: 'sum_bucket',
title: 'Sum Bucket',
makeLabel: agg => makeNestedLabel(agg, 'overall sum'),
title: i18n.translate('common.ui.aggTypes.metrics.sumBucketTitle', {
defaultMessage: 'Sum Bucket'
}),
makeLabel: agg => makeNestedLabel(agg, overallSumLabel),
subtype: siblingPipelineAggHelper.subtype,
params: [
...siblingPipelineAggHelper.params()
Expand Down
10 changes: 8 additions & 2 deletions src/ui/public/agg_types/metrics/cardinality.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,18 @@

import { MetricAggType } from './metric_agg_type';
import { fieldFormats } from '../../registry/field_formats';
import { i18n } from '@kbn/i18n';

export const cardinalityMetricAgg = new MetricAggType({
name: 'cardinality',
title: 'Unique Count',
title: i18n.translate('common.ui.aggTypes.metrics.uniqueCountTitle', {
defaultMessage: 'Unique Count'
}),
makeLabel: function (aggConfig) {
return 'Unique count of ' + aggConfig.getFieldDisplayName();
return i18n.translate('common.ui.aggTypes.metrics.uniqueCountLabel', {
defaultMessage: 'Unique count of {field}',
values: { field: aggConfig.getFieldDisplayName() }
});
},
getFormat: function () {
return fieldFormats.getDefaultInstance('number');
Expand Down
9 changes: 7 additions & 2 deletions src/ui/public/agg_types/metrics/count.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@

import { MetricAggType } from './metric_agg_type';
import { fieldFormats } from '../../registry/field_formats';
import { i18n } from '@kbn/i18n';

export const countMetricAgg = new MetricAggType({
name: 'count',
title: 'Count',
title: i18n.translate('common.ui.aggTypes.metrics.countTitle', {
defaultMessage: 'Count'
}),
hasNoDsl: true,
makeLabel: function () {
return 'Count';
return i18n.translate('common.ui.aggTypes.metrics.countLabel', {
defaultMessage: 'Count'
});
},
getFormat: function () {
return fieldFormats.getDefaultInstance('number');
Expand Down
11 changes: 9 additions & 2 deletions src/ui/public/agg_types/metrics/cumulative_sum.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,19 @@
import { MetricAggType } from './metric_agg_type';
import { parentPipelineAggHelper } from './lib/parent_pipeline_agg_helper';
import { makeNestedLabel } from './lib/make_nested_label';
import { i18n } from '@kbn/i18n';

const cumulativeSumLabel = i18n.translate('common.ui.aggTypes.metrics.cumulativeSumLabel', {
defaultMessage: 'cumulative sum'
});

export const cumulativeSumMetricAgg = new MetricAggType({
name: 'cumulative_sum',
title: 'Cumulative Sum',
title: i18n.translate('common.ui.aggTypes.metrics.cumulativeSumTitle', {
defaultMessage: 'Cumulative Sum'
}),
subtype: parentPipelineAggHelper.subtype,
makeLabel: agg => makeNestedLabel(agg, 'cumulative sum'),
makeLabel: agg => makeNestedLabel(agg, cumulativeSumLabel),
params: [
...parentPipelineAggHelper.params()
],
Expand Down
11 changes: 9 additions & 2 deletions src/ui/public/agg_types/metrics/derivative.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,19 @@
import { MetricAggType } from './metric_agg_type';
import { parentPipelineAggHelper } from './lib/parent_pipeline_agg_helper';
import { makeNestedLabel } from './lib/make_nested_label';
import { i18n } from '@kbn/i18n';

const derivativeLabel = i18n.translate('common.ui.aggTypes.metrics.derivativeLabel', {
defaultMessage: 'derivative'
});

export const derivativeMetricAgg = new MetricAggType({
name: 'derivative',
title: 'Derivative',
title: i18n.translate('common.ui.aggTypes.metrics.derivativeTitle', {
defaultMessage: 'Derivative'
}),
subtype: parentPipelineAggHelper.subtype,
makeLabel: agg => makeNestedLabel(agg, 'derivative'),
makeLabel: agg => makeNestedLabel(agg, derivativeLabel),
params: [
...parentPipelineAggHelper.params()
],
Expand Down
9 changes: 7 additions & 2 deletions src/ui/public/agg_types/metrics/geo_bounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@
*/

import { MetricAggType } from './metric_agg_type';
import { i18n } from '@kbn/i18n';

export const geoBoundsMetricAgg = new MetricAggType({
name: 'geo_bounds',
title: 'Geo Bounds',
title: i18n.translate('common.ui.aggTypes.metrics.geoBoundsTitle', {
defaultMessage: 'Geo Bounds'
}),
makeLabel: function () {
return 'Geo Bounds';
return i18n.translate('common.ui.aggTypes.metrics.geoBoundsLabel', {
defaultMessage: 'Geo Bounds'
});
},
params: [
{
Expand Down
9 changes: 7 additions & 2 deletions src/ui/public/agg_types/metrics/geo_centroid.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@
*/

import { MetricAggType } from './metric_agg_type';
import { i18n } from '@kbn/i18n';

export const geoCentroidMetricAgg = new MetricAggType({
name: 'geo_centroid',
title: 'Geo Centroid',
title: i18n.translate('common.ui.aggTypes.metrics.geoCentroidTitle', {
defaultMessage: 'Geo Centroid'
}),
makeLabel: function () {
return 'Geo Centroid';
return i18n.translate('common.ui.aggTypes.metrics.geoCentroidLabel', {
defaultMessage: 'Geo Centroid'
});
},
params: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import _ from 'lodash';
import { safeMakeLabel } from './safe_make_label';
import { i18n } from '@kbn/i18n';

const parentPipelineAggController = function ($scope) {

Expand Down Expand Up @@ -59,8 +60,11 @@ const parentPipelineAggController = function ($scope) {
} else {
if (lastBucket) {
const type = $scope.agg.type.title;
lastBucket.error = `Last bucket aggregation must be "Date Histogram" or
"Histogram" when using "${type}" metric aggregation!`;
lastBucket.error = i18n.translate('common.ui.aggTypes.metrics.wrongLastBucketTypeErrorMessage', {
defaultMessage: 'Last bucket aggregation must be "Date Histogram" or "Histogram" when using "{type}" metric aggregation!',
values: { type },
description: 'Date Histogram and Histogram should not be translated'
});
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,26 @@ import { Schemas } from '../../../vis/editors/default/schemas';
import { parentPipelineAggController } from './parent_pipeline_agg_controller';
import { parentPipelineAggWriter } from './parent_pipeline_agg_writer';
import { forwardModifyAggConfigOnSearchRequestStart } from './nested_agg_helpers';
import { i18n } from '@kbn/i18n';


const metricAggFilter = ['!top_hits', '!percentiles', '!percentile_ranks', '!median', '!std_dev'];
const metricAggSchema = (new Schemas([
{
group: 'none',
name: 'metricAgg',
title: 'Metric Agg',
title: i18n.translate('common.ui.aggTypes.metrics.metricAggTitle', {
defaultMessage: 'Metric Agg'
}),
hideCustomLabel: true,
aggFilter: metricAggFilter
}
])).all[0];

const parentPipelineAggHelper = {
subtype: 'Parent Pipeline Aggregations',
subtype: i18n.translate('common.ui.aggTypes.metrics.parentPipelineAggregationsSubtypeTitle', {
defaultMessage: 'Parent Pipeline Aggregations'
}),
params: function () {
return [
{
Expand Down
5 changes: 4 additions & 1 deletion src/ui/public/agg_types/metrics/lib/safe_make_label.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@
* specific language governing permissions and limitations
* under the License.
*/
import { i18n } from '@kbn/i18n';

export const safeMakeLabel = function (agg) {
try {
return agg.makeLabel();
} catch (e) {
return '- agg not valid -';
return i18n.translate('common.ui.aggTypes.metrics.aggNotValidErrorMessage', {
defaultMessage: '- agg not valid -'
});
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,19 @@
*/

import { safeMakeLabel } from './safe_make_label';
import { i18n } from '@kbn/i18n';

const siblingPipelineAggController = function (type) {
return function ($scope) {
const metricTitle = i18n.translate('common.ui.aggTypes.metrics.metricTitle', {
defaultMessage: 'Metric'
});
const bucketTitle = i18n.translate('common.ui.aggTypes.metrics.bucketTitle', {
defaultMessage: 'Bucket'
});

$scope.aggType = type;
$scope.aggTitle = type === 'customMetric' ? 'Metric' : 'Bucket';
$scope.aggTitle = type === 'customMetric' ? metricTitle : bucketTitle;
$scope.aggGroup = type === 'customMetric' ? 'metrics' : 'buckets';
$scope.safeMakeLabel = safeMakeLabel;

Expand Down
13 changes: 10 additions & 3 deletions src/ui/public/agg_types/metrics/lib/sibling_pipeline_agg_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { siblingPipelineAggController } from './sibling_pipeline_agg_controller'
import { siblingPipelineAggWriter } from './sibling_pipeline_agg_writer';
import metricAggTemplate from '../../controls/sub_metric.html';
import { forwardModifyAggConfigOnSearchRequestStart } from './nested_agg_helpers';
import { i18n } from '@kbn/i18n';

const metricAggFilter = [
'!top_hits', '!percentiles', '!percentile_ranks', '!median', '!std_dev',
Expand All @@ -36,7 +37,9 @@ const metricAggSchema = (new Schemas([
{
group: 'none',
name: 'metricAgg',
title: 'Metric Agg',
title: i18n.translate('common.ui.aggTypes.metrics.metricAggTitle', {
defaultMessage: 'Metric Agg'
}),
aggFilter: metricAggFilter
}
])).all[0];
Expand All @@ -45,14 +48,18 @@ const bucketAggFilter = [];
const bucketAggSchema = (new Schemas([
{
group: 'none',
title: 'Bucket Agg',
title: i18n.translate('common.ui.aggTypes.metrics.bucketAggTitle', {
defaultMessage: 'Bucket Agg'
}),
name: 'bucketAgg',
aggFilter: bucketAggFilter
}
])).all[0];

const siblingPipelineAggHelper = {
subtype: 'Sibling Pipeline Aggregations',
subtype: i18n.translate('common.ui.aggTypes.metrics.siblingPipelineAggregationsSubtypeTitle', {
defaultMessage: 'Sibling Pipeline Aggregations'
}),
params: function () {
return [
{
Expand Down
10 changes: 8 additions & 2 deletions src/ui/public/agg_types/metrics/max.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@
*/

import { MetricAggType } from './metric_agg_type';
import { i18n } from '@kbn/i18n';

export const maxMetricAgg = new MetricAggType({
name: 'max',
title: 'Max',
title: i18n.translate('common.ui.aggTypes.metrics.maxTitle', {
defaultMessage: 'Max'
}),
makeLabel: function (aggConfig) {
return 'Max ' + aggConfig.getFieldDisplayName();
return i18n.translate('common.ui.aggTypes.metrics.maxLabel', {
defaultMessage: 'Max {field}',
values: { field: aggConfig.getFieldDisplayName() }
});
},
params: [
{
Expand Down
Loading

0 comments on commit 51a418e

Please sign in to comment.