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

Vega translations #23677

Merged
merged 16 commits into from
Oct 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"kbnVislibVisTypes": "src/core_plugins/kbn_vislib_vis_types",
"markdownVis": "src/core_plugins/markdown_vis",
"metricVis": "src/core_plugins/metric_vis",
"vega": "src/core_plugins/vega",
"tableVis": "src/core_plugins/table_vis",
"regionMap": "src/core_plugins/region_map",
"statusPage": "src/core_plugins/status_page",
Expand Down
15 changes: 13 additions & 2 deletions src/core_plugins/vega/public/data_model/ems_file_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/

import { i18n } from '@kbn/i18n';
import { bypassExternalUrlCheck } from '../vega_view/vega_base_view';

/**
Expand All @@ -35,7 +36,14 @@ export class EmsFileParser {
*/
parseUrl(obj, url) {
if (typeof url.name !== 'string') {
throw new Error(`data.url with {"%type%": "emsfile"} is missing the "name" of the file`);
throw new Error(i18n.translate('vega.emsFileParser.missingNameOfFileErrorMessage', {
defaultMessage: '{dataUrlParam} with {dataUrlParamValue} requires {nameParam} parameter (name of the file)',
values: {
dataUrlParam: '"data.url"',
dataUrlParamValue: '{"%type%": "emsfile"}',
nameParam: '"name"',
},
}));
}
// Optimization: so initiate remote request as early as we know that we will need it
if (!this._fileLayersP) {
Expand All @@ -57,7 +65,10 @@ export class EmsFileParser {
for (const { obj, name } of requests) {
const foundLayer = layers.find(v => v.name === name);
if (!foundLayer) {
throw new Error(`emsfile ${JSON.stringify(name)} does not exist`);
throw new Error(i18n.translate('vega.emsFileParser.emsFileNameDoesNotExistErrorMessage', {
defaultMessage: '{emsfile} {emsfileName} does not exist',
values: { emsfileName: JSON.stringify(name), emsfile: 'emsfile' },
}));
}

// This URL can bypass loader sanitization at the later stage
Expand Down
84 changes: 72 additions & 12 deletions src/core_plugins/vega/public/data_model/es_query_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

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

const TIMEFILTER = '%timefilter%';
const AUTOINTERVAL = '%autointerval%';
Expand Down Expand Up @@ -56,20 +57,41 @@ export class EsQueryParser {
if (body === undefined) {
url.body = body = {};
} else if (!_.isPlainObject(body)) {
throw new Error('url.body must be an object');
throw new Error(i18n.translate('vega.esQueryParser.urlBodyValueTypeErrorMessage', {
defaultMessage: '{configName} must be an object',
values: { configName: 'url.body' },
}));
}

// Migrate legacy %context_query% into context & timefield values
const legacyContext = url[LEGACY_CONTEXT];
delete url[LEGACY_CONTEXT];
if (legacyContext !== undefined) {
if (body.query !== undefined) {
throw new Error(`Data url must not have legacy "${LEGACY_CONTEXT}" and "body.query" values at the same time`);
throw new Error(i18n.translate('vega.esQueryParser.dataUrlMustNotHaveLegacyAndBodyQueryValuesAtTheSameTimeErrorMessage', {
defaultMessage: '{dataUrlParam} must not have legacy {legacyContext} and {bodyQueryConfigName} values at the same time',
values: {
legacyContext: `"${LEGACY_CONTEXT}"`,
bodyQueryConfigName: '"body.query"',
dataUrlParam: '"data.url"',
},
}));
} else if (usesContext) {
throw new Error(`Data url must not have "${LEGACY_CONTEXT}" together with "${CONTEXT}" or "${TIMEFIELD}"`);
throw new Error(i18n.translate('vega.esQueryParser.dataUrlMustNotHaveLegacyContextTogetherWithContextOrTimefieldErrorMessage', {
defaultMessage: '{dataUrlParam} must not have {legacyContext} together with {context} or {timefield}',
values: {
legacyContext: `"${LEGACY_CONTEXT}"`,
context: `"${CONTEXT}"`,
timefield: `"${TIMEFIELD}"`,
dataUrlParam: '"data.url"',
},
}));
} else if (legacyContext !== true && (typeof legacyContext !== 'string' || legacyContext.length === 0)) {
throw new Error(`Legacy "${LEGACY_CONTEXT}" can either be true (ignores time range picker), ` +
'or it can be the name of the time field, e.g. "@timestamp"');
throw new Error(i18n.translate('vega.esQueryParser.legacyContextCanBeTrueErrorMessage', {
// eslint-disable-next-line max-len
defaultMessage: 'Legacy {legacyContext} can either be {trueValue} (ignores time range picker), or it can be the name of the time field, e.g. {timestampParam}',
values: { legacyContext: `"${LEGACY_CONTEXT}"`, trueValue: 'true', timestampParam: '"@timestamp"' },
}));
}

usesContext = true;
Expand All @@ -81,13 +103,26 @@ export class EsQueryParser {
}
result += '}';

this._onWarning(
`Legacy "url": {"${LEGACY_CONTEXT}": ${JSON.stringify(legacyContext)}} should change to ${result}`);
this._onWarning(i18n.translate('vega.esQueryParser.legacyUrlShouldChangeToWarningMessage', {
defaultMessage: 'Legacy {urlParam}: {legacyUrl} should change to {result}',
values: {
legacyUrl: `"${LEGACY_CONTEXT}": ${JSON.stringify(legacyContext)}`,
result,
urlParam: '"url"',
},
}));
}

if (body.query !== undefined) {
if (usesContext) {
throw new Error(`url.${CONTEXT} and url.${TIMEFIELD} must not be used when url.body.query is set`);
throw new Error(i18n.translate('vega.esQueryParser.urlContextAndUrlTimefieldMustNotBeUsedErrorMessage', {
defaultMessage: '{urlContext} and {timefield} must not be used when {queryParam} is set',
values: {
timefield: `url.${TIMEFIELD}`,
urlContext: `url.${CONTEXT}`,
queryParam: 'url.body.query',
},
}));
}
this._injectContextVars(body.query, true);
} else if (usesContext) {
Expand Down Expand Up @@ -168,7 +203,13 @@ export class EsQueryParser {
if (size === true) {
size = 50; // by default, try to get ~80 values
} else if (typeof size !== 'number') {
throw new Error(`"${AUTOINTERVAL}" must be either true or a number`);
throw new Error(i18n.translate('vega.esQueryParser.autointervalValueTypeErrorMessage', {
defaultMessage: '{autointerval} must be either {trueValue} or a number',
values: {
autointerval: `"${AUTOINTERVAL}"`,
trueValue: 'true',
},
}));
}
const bounds = this._timeCache.getTimeBounds();
obj.interval = EsQueryParser._roundInterval((bounds.max - bounds.min) / size);
Expand All @@ -190,7 +231,15 @@ export class EsQueryParser {
this._injectContextVars(subObj, isQuery);
continue;
default:
throw new Error(`"${TIMEFILTER}" property must be set to true, "min", or "max"`);
throw new Error(i18n.translate('vega.esQueryParser.timefilterValueErrorMessage', {
defaultMessage: '{timefilter} property must be set to {trueValue}, {minValue}, or {maxValue}',
values: {
timefilter: `"${TIMEFILTER}"`,
trueValue: 'true',
minValue: '"min"',
maxValue: '"max"',
},
}));
}
}
}
Expand Down Expand Up @@ -227,7 +276,12 @@ export class EsQueryParser {
if (opts.shift) {
const shift = opts.shift;
if (typeof shift !== 'number') {
throw new Error('shift must be a numeric value');
throw new Error(i18n.translate('vega.esQueryParser.shiftMustValueTypeErrorMessage', {
defaultMessage: '{shiftParam} must be a numeric value',
values: {
shiftParam: '"shift"',
},
}));
}
let multiplier;
switch (opts.unit || 'd') {
Expand All @@ -252,7 +306,13 @@ export class EsQueryParser {
multiplier = 1000;
break;
default:
throw new Error('Unknown unit value. Must be one of: [week, day, hour, minute, second]');
throw new Error(i18n.translate('vega.esQueryParser.unknownUnitValueErrorMessage', {
defaultMessage: 'Unknown {unitParamName} value. Must be one of: [{unitParamValues}]',
values: {
unitParamName: '"unit"',
unitParamValues: '"week", "day", "hour", "minute", "second"',
},
}));
}
result += shift * multiplier;
}
Expand Down
18 changes: 16 additions & 2 deletions src/core_plugins/vega/public/data_model/url_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

import $ from 'jquery';
import { i18n } from '@kbn/i18n';

/**
* This class processes all Vega spec customizations,
Expand All @@ -36,12 +37,25 @@ export class UrlParser {
parseUrl(obj, urlObj) {
let url = urlObj.url;
if (!url) {
throw new Error(`data.url requires a url parameter in a form 'https://example.org/path/subpath'`);
throw new Error(i18n.translate('vega.urlParser.dataUrlRequiresUrlParameterInFormErrorMessage', {
defaultMessage: '{dataUrlParam} requires a {urlParam} parameter in a form "{formLink}"',
values: {
dataUrlParam: '"data.url"',
urlParam: '"url"',
formLink: 'https://example.org/path/subpath',
},
}));
}

const query = urlObj.query;
if (!query) {
this._onWarning(`Using a "url": {"%type%": "url", "url": ...} should have a "query" sub-object`);
this._onWarning(i18n.translate('vega.urlParser.urlShouldHaveQuerySubObjectWarningMessage', {
defaultMessage: 'Using a {urlObject} should have a {subObjectName} sub-object',
values: {
urlObject: '"url": {"%type%": "url", "url": ...}',
subObjectName: '"query"',
},
}));
} else {
url += (url.includes('?') ? '&' : '?') + $.param(query);
}
Expand Down
Loading