diff --git a/src/dev/i18n/extractors/__snapshots__/pug.test.js.snap b/src/dev/i18n/extractors/__snapshots__/pug.test.js.snap index c95fb0d149cd03..f8d0f45db63b5a 100644 --- a/src/dev/i18n/extractors/__snapshots__/pug.test.js.snap +++ b/src/dev/i18n/extractors/__snapshots__/pug.test.js.snap @@ -1,6 +1,16 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`dev/i18n/extractors/pug extracts messages from pug template 1`] = ` +exports[`dev/i18n/extractors/pug extracts messages from pug template with interpolation 1`] = ` +Array [ + "message-id", + Object { + "context": "Message context", + "message": "Default message", + }, +] +`; + +exports[`dev/i18n/extractors/pug extracts messages from pug template without interpolation 1`] = ` Array [ "message-id", Object { diff --git a/src/dev/i18n/extractors/pug.js b/src/dev/i18n/extractors/pug.js index 61b4ba0ca866c8..0f964f308403d5 100644 --- a/src/dev/i18n/extractors/pug.js +++ b/src/dev/i18n/extractors/pug.js @@ -26,7 +26,7 @@ import { createFailError } from '../../run'; /** * Matches `i18n(...)` in `#{i18n('id', { defaultMessage: 'Message text' })}` */ -const PUG_I18N_REGEX = /(?<=\#\{)i18n\((([^)']|'([^'\\]|\\.)*')*\)(?=\}))/g; +const PUG_I18N_REGEX = /i18n\((([^)']|'([^'\\]|\\.)*')*)\)/g; /** * Example: `#{i18n('message-id', { defaultMessage: 'Message text' })}` diff --git a/src/dev/i18n/extractors/pug.test.js b/src/dev/i18n/extractors/pug.test.js index 7f901d1d992dbc..3bfa2a14fa7e04 100644 --- a/src/dev/i18n/extractors/pug.test.js +++ b/src/dev/i18n/extractors/pug.test.js @@ -20,7 +20,7 @@ import { extractPugMessages } from './pug'; describe('dev/i18n/extractors/pug', () => { - test('extracts messages from pug template', () => { + test('extracts messages from pug template with interpolation', () => { const source = Buffer.from(`\ #{i18n('message-id', { defaultMessage: 'Default message', context: 'Message context' })} `); @@ -29,9 +29,18 @@ describe('dev/i18n/extractors/pug', () => { expect(messageObject).toMatchSnapshot(); }); + test('extracts messages from pug template without interpolation', () => { + const source = Buffer.from(`\ +.kibanaWelcomeText(data-error-message=i18n('message-id', { defaultMessage: 'Default message', context: 'Message context' })) +`); + const [messageObject] = extractPugMessages(source); + + expect(messageObject).toMatchSnapshot(); + }); + test('throws on empty id', () => { const source = Buffer.from(`\ -#{i18n('', { defaultMessage: 'Default message', context: 'Message context' })} +h1= i18n('', { defaultMessage: 'Default message', context: 'Message context' }) `); expect(() => extractPugMessages(source).next()).toThrowErrorMatchingSnapshot();