forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[i18n tooling] throw when a variable is passed to template literal in…
… default message (elastic#190582) With the new i18n tooling, we now allow template literals to be used for the `defaultMessage` however they cannot contain variable substitutions. This PR adds a check in the parser that throws an error when there is a variable inside the template literal asking the developer to use `values` instead. Previously the parser simply skipped extracting the message which causes confusion for developers as they expect the CI to fail on errors instead of just silently allowing it bypassing translations. Thankfully we dont have any cases in the codebase that are doing direct substituion yet so this bug fix came at the right time :) thanks @maryam-saeidi for catching it!
- Loading branch information
Showing
3 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
src/dev/i18n_tools/__fixtures__/extraction_signatures/template_literal_var.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
|
||
const e = new Error('Should not work'); | ||
|
||
i18n.translate('contains_variable', { | ||
defaultMessage: `value passed into literal directly (e: ${e.message})`, | ||
}); | ||
|
||
i18n.translate('no_variable', { | ||
defaultMessage: `template literal without any variable expressions (e: {errorMessage})`, | ||
values: { errorMessage: e.message }, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters