Skip to content

Commit

Permalink
[i18n] Translate Agg_types(part_1) (elastic#24259) (elastic#26178)
Browse files Browse the repository at this point in the history
* translate ui-agg_types-bucket

* Fix name of id

* Delete extra i18n import

* Rename some parameters
  • Loading branch information
maryia-lapata authored and Nox911 committed Nov 27, 2018
1 parent 83511cd commit 9016da0
Show file tree
Hide file tree
Showing 12 changed files with 142 additions and 33 deletions.
41 changes: 31 additions & 10 deletions src/ui/public/agg_types/buckets/_interval_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/
import { i18n } from '@kbn/i18n';

export const intervalOptions = [
{
display: 'Auto',
display: i18n.translate('common.ui.aggTypes.buckets.intervalOptions.autoDisplayName', {
defaultMessage: 'Auto',
}),
val: 'auto',
enabled: function (agg) {
// not only do we need a time field, but the selected field needs
Expand All @@ -28,39 +31,57 @@ export const intervalOptions = [
}
},
{
display: 'Millisecond',
display: i18n.translate('common.ui.aggTypes.buckets.intervalOptions.millisecondDisplayName', {
defaultMessage: 'Millisecond',
}),
val: 'ms'
},
{
display: 'Second',
display: i18n.translate('common.ui.aggTypes.buckets.intervalOptions.secondDisplayName', {
defaultMessage: 'Second',
}),
val: 's'
},
{
display: 'Minute',
display: i18n.translate('common.ui.aggTypes.buckets.intervalOptions.minuteDisplayName', {
defaultMessage: 'Minute',
}),
val: 'm'
},
{
display: 'Hourly',
display: i18n.translate('common.ui.aggTypes.buckets.intervalOptions.hourlyDisplayName', {
defaultMessage: 'Hourly',
}),
val: 'h'
},
{
display: 'Daily',
display: i18n.translate('common.ui.aggTypes.buckets.intervalOptions.dailyDisplayName', {
defaultMessage: 'Daily',
}),
val: 'd'
},
{
display: 'Weekly',
display: i18n.translate('common.ui.aggTypes.buckets.intervalOptions.weeklyDisplayName', {
defaultMessage: 'Weekly',
}),
val: 'w'
},
{
display: 'Monthly',
display: i18n.translate('common.ui.aggTypes.buckets.intervalOptions.monthlyDisplayName', {
defaultMessage: 'Monthly',
}),
val: 'M'
},
{
display: 'Yearly',
display: i18n.translate('common.ui.aggTypes.buckets.intervalOptions.yearlyDisplayName', {
defaultMessage: 'Yearly',
}),
val: 'y'
},
{
display: 'Custom',
display: i18n.translate('common.ui.aggTypes.buckets.intervalOptions.customDisplayName', {
defaultMessage: 'Custom',
}),
val: 'custom'
}
];
13 changes: 11 additions & 2 deletions src/ui/public/agg_types/buckets/date_histogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { intervalOptions } from './_interval_options';
import intervalTemplate from '../controls/time_interval.html';
import { timefilter } from '../../timefilter';
import dropPartialTemplate from '../controls/drop_partials.html';
import { i18n } from '@kbn/i18n';

const config = chrome.getUiSettingsClient();
const detectedTimezone = tzDetect.determine().name();
Expand All @@ -53,14 +54,22 @@ function setBounds(agg, force) {

export const dateHistogramBucketAgg = new BucketAggType({
name: 'date_histogram',
title: 'Date Histogram',
title: i18n.translate('common.ui.aggTypes.buckets.dateHistogramTitle', {
defaultMessage: 'Date Histogram',
}),
ordered: {
date: true
},
makeLabel: function (agg) {
const output = this.params.write(agg);
const field = agg.getFieldDisplayName();
return field + ' per ' + (output.metricScaleText || output.bucketInterval.description);
return i18n.translate('common.ui.aggTypes.buckets.dateHistogramLabel', {
defaultMessage: '{fieldName} per {intervalDescription}',
values: {
fieldName: field,
intervalDescription: output.metricScaleText || output.bucketInterval.description,
}
});
},
createFilter: createFilterDateHistogram,
decorateAggConfig: function () {
Expand Down
5 changes: 4 additions & 1 deletion src/ui/public/agg_types/buckets/date_range.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ import { BucketAggType } from './_bucket_agg_type';
import { createFilterDateRange } from './create_filter/date_range';
import { fieldFormats } from '../../registry/field_formats';
import dateRangesTemplate from '../controls/date_ranges.html';
import { i18n } from '@kbn/i18n';

export const dateRangeBucketAgg = new BucketAggType({
name: 'date_range',
title: 'Date Range',
title: i18n.translate('common.ui.aggTypes.buckets.dateRangeTitle', {
defaultMessage: 'Date Range',
}),
createFilter: createFilterDateRange,
getKey: function (bucket, key, agg) {
const formatter = agg.fieldOwnFormatter('text', fieldFormats.getDefaultInstance('date'));
Expand Down
5 changes: 4 additions & 1 deletion src/ui/public/agg_types/buckets/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@
*/

import { BucketAggType } from './_bucket_agg_type';
import { i18n } from '@kbn/i18n';

export const filterBucketAgg = new BucketAggType({
name: 'filter',
title: 'Filter',
title: i18n.translate('common.ui.aggTypes.buckets.filterTitle', {
defaultMessage: 'Filter',
}),
params: [
{
name: 'geo_bounding_box'
Expand Down
5 changes: 4 additions & 1 deletion src/ui/public/agg_types/buckets/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ import { BucketAggType } from './_bucket_agg_type';
import { createFilterFilters } from './create_filter/filters';
import { decorateQuery, luceneStringToDsl } from '../../courier';
import filtersTemplate from '../controls/filters.html';
import { i18n } from '@kbn/i18n';

export const filtersBucketAgg = new BucketAggType({
name: 'filters',
title: 'Filters',
title: i18n.translate('common.ui.aggTypes.buckets.filtersTitle', {
defaultMessage: 'Filters',
}),
createFilter: createFilterFilters,
customLabels: false,
params: [
Expand Down
5 changes: 4 additions & 1 deletion src/ui/public/agg_types/buckets/geo_hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { BucketAggType } from './_bucket_agg_type';
import precisionTemplate from '../controls/precision.html';
import { geohashColumns } from '../../utils/decode_geo_hash';
import { geoContains, scaleBounds } from '../../utils/geo_utils';
import { i18n } from '@kbn/i18n';

const config = chrome.getUiSettingsClient();

Expand Down Expand Up @@ -68,7 +69,9 @@ function isOutsideCollar(bounds, collar) {

export const geoHashBucketAgg = new BucketAggType({
name: 'geohash_grid',
title: 'Geohash',
title: i18n.translate('common.ui.aggTypes.buckets.geohashGridTitle', {
defaultMessage: 'Geohash',
}),
params: [
{
name: 'field',
Expand Down
6 changes: 4 additions & 2 deletions src/ui/public/agg_types/buckets/histogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import _ from 'lodash';

import { i18n } from '@kbn/i18n';
import { toastNotifications } from 'ui/notify';
import '../../validate_date_interval';
import chrome from 'ui/chrome';
Expand All @@ -28,11 +27,14 @@ import { createFilterHistogram } from './create_filter/histogram';
import intervalTemplate from '../controls/number_interval.html';
import minDocCountTemplate from '../controls/min_doc_count.html';
import extendedBoundsTemplate from '../controls/extended_bounds.html';
import { i18n } from '@kbn/i18n';

const config = chrome.getUiSettingsClient();
export const histogramBucketAgg = new BucketAggType({
name: 'histogram',
title: 'Histogram',
title: i18n.translate('common.ui.aggTypes.buckets.histogramTitle', {
defaultMessage: 'Histogram',
}),
ordered: {},
makeLabel: function (aggConfig) {
return aggConfig.getFieldDisplayName();
Expand Down
12 changes: 10 additions & 2 deletions src/ui/public/agg_types/buckets/ip_range.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ import '../../directives/validate_cidr_mask';
import { BucketAggType } from './_bucket_agg_type';
import { createFilterIpRange } from './create_filter/ip_range';
import ipRangesTemplate from '../controls/ip_ranges.html';
import { i18n } from '@kbn/i18n';

export const ipRangeBucketAgg = new BucketAggType({
name: 'ip_range',
title: 'IPv4 Range',
title: i18n.translate('common.ui.aggTypes.buckets.ipRangeTitle', {
defaultMessage: 'IPv4 Range',
}),
createFilter: createFilterIpRange,
getKey: function (bucket, key) {
if (key) return key;
Expand All @@ -35,7 +38,12 @@ export const ipRangeBucketAgg = new BucketAggType({
return `${from} to ${to}`;
},
makeLabel: function (aggConfig) {
return aggConfig.getFieldDisplayName() + ' IP ranges';
return i18n.translate('common.ui.aggTypes.buckets.ipRangeLabel', {
defaultMessage: '{fieldName} IP ranges',
values: {
fieldName: aggConfig.getFieldDisplayName()
}
});
},
params: [
{
Expand Down
20 changes: 17 additions & 3 deletions src/ui/public/agg_types/buckets/range.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,24 @@ import { createFilterRange } from './create_filter/range';
import { FieldFormat } from '../../../field_formats/field_format';
import { RangeKey } from './range_key';
import rangesTemplate from '../controls/ranges.html';
import { i18n } from '@kbn/i18n';

const keyCaches = new WeakMap();
const formats = new WeakMap();

export const rangeBucketAgg = new BucketAggType({
name: 'range',
title: 'Range',
title: i18n.translate('common.ui.aggTypes.buckets.rangeTitle', {
defaultMessage: 'Range',
}),
createFilter: createFilterRange,
makeLabel: function (aggConfig) {
return aggConfig.getFieldDisplayName() + ' ranges';
return i18n.translate('common.ui.aggTypes.buckets.rangesLabel', {
defaultMessage: '{fieldName} ranges',
values: {
fieldName: aggConfig.getFieldDisplayName()
}
});
},
getKey: function (bucket, key, agg) {
let keys = keyCaches.get(agg);
Expand All @@ -57,7 +65,13 @@ export const rangeBucketAgg = new BucketAggType({

const RangeFormat = FieldFormat.from(function (range) {
const format = agg.fieldOwnFormatter();
return `${format(range.gte)} to ${format(range.lt)}`;
return i18n.translate('common.ui.aggTypes.buckets.ranges.rangesFormatMessage', {
defaultMessage: '{from} to {to}',
values: {
from: format(range.gte),
to: format(range.lt)
}
});
});

format = new RangeFormat();
Expand Down
13 changes: 11 additions & 2 deletions src/ui/public/agg_types/buckets/significant_terms.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,21 @@
import { BucketAggType } from './_bucket_agg_type';
import { createFilterTerms } from './create_filter/terms';
import orderAndSizeTemplate from '../controls/order_and_size.html';
import { i18n } from '@kbn/i18n';

export const significantTermsBucketAgg = new BucketAggType({
name: 'significant_terms',
title: 'Significant Terms',
title: i18n.translate('common.ui.aggTypes.buckets.significantTermsTitle', {
defaultMessage: 'Significant Terms',
}),
makeLabel: function (aggConfig) {
return 'Top ' + aggConfig.params.size + ' unusual terms in ' + aggConfig.getFieldDisplayName();
return i18n.translate('common.ui.aggTypes.buckets.significantTermsLabel', {
defaultMessage: 'Top {size} unusual terms in {fieldName}',
values: {
size: aggConfig.params.size,
fieldName: aggConfig.getFieldDisplayName(),
}
});
},
createFilter: createFilterTerms,
params: [
Expand Down
31 changes: 25 additions & 6 deletions src/ui/public/agg_types/buckets/terms.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { createFilterTerms } from './create_filter/terms';
import orderAggTemplate from '../controls/order_agg.html';
import orderAndSizeTemplate from '../controls/order_and_size.html';
import otherBucketTemplate from '../controls/other_bucket.html';
import { i18n } from '@kbn/i18n';

import { getRequestInspectorStats, getResponseInspectorStats } from '../../courier/utils/courier_inspector_utils';
import { buildOtherBucketAgg, mergeOtherBucketAggResponse, updateMissingBucket } from './_terms_other_bucket_helper';
Expand All @@ -40,7 +41,9 @@ const orderAggSchema = (new Schemas([
{
group: 'none',
name: 'orderAgg',
title: 'Order Agg',
title: i18n.translate('common.ui.aggTypes.buckets.terms.orderAggTitle', {
defaultMessage: 'Order Agg',
}),
hideCustomLabel: true,
aggFilter: aggFilter
}
Expand Down Expand Up @@ -70,7 +73,9 @@ const migrateIncludeExcludeFormat = {

export const termsBucketAgg = new BucketAggType({
name: 'terms',
title: 'Terms',
title: i18n.translate('common.ui.aggTypes.buckets.termsTitle', {
defaultMessage: 'Terms',
}),
makeLabel: function (agg) {
const params = agg.params;
return agg.getFieldDisplayName() + ': ' + params.order.display;
Expand Down Expand Up @@ -254,8 +259,18 @@ export const termsBucketAgg = new BucketAggType({
default: 'desc',
editor: orderAndSizeTemplate,
options: [
{ display: 'Descending', val: 'desc' },
{ display: 'Ascending', val: 'asc' }
{
display: i18n.translate('common.ui.aggTypes.buckets.terms.orderDescendingTitle', {
defaultMessage: 'Descending',
}),
val: 'desc'
},
{
display: i18n.translate('common.ui.aggTypes.buckets.terms.orderAscendingTitle', {
defaultMessage: 'Ascending',
}),
val: 'asc'
}
],
write: _.noop // prevent default write, it's handled by orderAgg
},
Expand All @@ -270,15 +285,19 @@ export const termsBucketAgg = new BucketAggType({
write: _.noop
}, {
name: 'otherBucketLabel',
default: 'Other',
default: i18n.translate('common.ui.aggTypes.buckets.terms.otherBucketLabel', {
defaultMessage: 'Other',
}),
write: _.noop
}, {
name: 'missingBucket',
default: false,
write: _.noop
}, {
name: 'missingBucketLabel',
default: 'Missing',
default: i18n.translate('common.ui.aggTypes.buckets.terms.missingBucketLabel', {
defaultMessage: 'Missing',
}),
write: _.noop
},
{
Expand Down
Loading

0 comments on commit 9016da0

Please sign in to comment.