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

[I18n] Fix pseudo-localization of i18n directive placeholders #26948

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`translateUsingPseudoLocale() should translate @I18N@ placeholders with wrong reference name 1`] = `"Ṁéšššàĝĝé ŵîîţĥ àà @Î18Ñ@ññôñ-ššîñĝĝļé-ŵŵôŕðð@Î18Ñ@ þþļàççéĥôôļðééŕ."`;

exports[`translateUsingPseudoLocale() shouldn't translate @I18N@ placeholders 1`] = `"Ṁéšššàĝĝé ŵîîţĥ àà @I18N@value@I18N@ þļààçéĥĥôļððéŕ."`;

exports[`translateUsingPseudoLocale() shouldn't translate @I18N@ placeholders with underscore 1`] = `"Ṁéšššàĝĝé ŵîîţĥ àà @I18N@snake_case_value@I18N@ þļààçéĥĥôļððéŕ."`;
40 changes: 40 additions & 0 deletions packages/kbn-i18n/src/core/pseudo_locale.test.ts
@@ -0,0 +1,40 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { translateUsingPseudoLocale } from './pseudo_locale';

describe('translateUsingPseudoLocale()', () => {
it(`shouldn't translate @I18N@ placeholders`, () => {
const message = 'Message with a @I18N@value@I18N@ placeholder.';

expect(translateUsingPseudoLocale(message)).toMatchSnapshot();
});

it(`shouldn't translate @I18N@ placeholders with underscore`, () => {
const message = 'Message with a @I18N@snake_case_value@I18N@ placeholder.';

expect(translateUsingPseudoLocale(message)).toMatchSnapshot();
});

it(`should translate @I18N@ placeholders with wrong reference name`, () => {
const message = 'Message with a @I18N@non-single-word@I18N@ placeholder.';

expect(translateUsingPseudoLocale(message)).toMatchSnapshot();
});
});
4 changes: 2 additions & 2 deletions packages/kbn-i18n/src/core/pseudo_locale.ts
Expand Up @@ -18,9 +18,9 @@
*/

/**
* Matches every single [A-Za-z] character, `<tag attr="any > text">` and `](markdown-link-address)`
* Matches every single [A-Za-z] character, `<tag attr="any > text">`, `](markdown-link-address)` and `@I18N@valid_variable_name@I18N@`
*/
const CHARS_FOR_PSEUDO_LOCALIZATION_REGEX = /[A-Za-z]|(\]\([\s\S]*?\))|(<([^"<>]|("[^"]*?"))*?>)/g;
const CHARS_FOR_PSEUDO_LOCALIZATION_REGEX = /[A-Za-z]|(\]\([\s\S]*?\))|(<([^"<>]|("[^"]*?"))*?>)|(@I18N@\w*?@I18N@)/g;
const PSEUDO_ACCENTS_LOCALE = 'en-xa';

export function isPseudoLocale(locale: string) {
Expand Down