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

Initial go at localizing some components #1450

Merged
merged 9 commits into from
Jan 30, 2019
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"react-ace": "^5.5.0",
"react-color": "^2.13.8",
"react-input-autosize": "^2.2.1",
"react-is": "~16.3.0",
"react-virtualized": "^9.18.5",
"react-vis": "1.10.2",
"resize-observer-polyfill": "^1.5.0",
Expand All @@ -76,6 +77,7 @@
"@types/enzyme": "^3.1.13",
"@types/jest": "^23.3.9",
"@types/react": "^16.3.0",
"@types/react-is": "~16.3.0",
"@types/react-virtualized": "^9.18.6",
"@types/uuid": "^3.4.4",
"autoprefixer": "^7.1.5",
Expand Down
6 changes: 5 additions & 1 deletion src/components/bottom_bar/bottom_bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import classNames from 'classnames';

import { EuiPortal } from '../portal';
import { EuiScreenReaderOnly } from '../accessibility';
import { EuiI18n } from '../i18n';

const paddingSizeToClassNameMap = {
none: null,
Expand Down Expand Up @@ -53,7 +54,10 @@ export class EuiBottomBar extends Component {
<EuiPortal>
<EuiScreenReaderOnly>
<p aria-live="assertive">
There is a new menu opening with page level controls at the bottom of the document.
<EuiI18n
token="euiBottomBar.screenReaderAnnouncement"
default="There is a new menu opening with page level controls at the bottom of the document."
/>
</p>
</EuiScreenReaderOnly>
<div
Expand Down
24 changes: 16 additions & 8 deletions src/components/code/_code_block.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from '../overlay_mask';

import { keyCodes } from '../../services';
import { EuiI18n } from '../i18n';

const fontSizeToClassNameMap = {
s: 'euiCodeBlock--fontSmall',
Expand Down Expand Up @@ -143,14 +144,21 @@ export class EuiCodeBlockImpl extends Component {

if (!inline && overflowHeight) {
fullScreenButton = (
<EuiButtonIcon
className="euiCodeBlock__fullScreenButton"
size="s"
onClick={this.toggleFullScreen}
iconType={this.state.isFullScreen ? 'cross' : 'fullScreen'}
color="text"
aria-label={this.state.isFullScreen ? 'Collapse' : 'Expand'}
/>
<EuiI18n
tokens={['euiCodeBlock.fullscreenCollapse', 'euiCodeBlock.fullscreenExpand']}
defaults={['Collapse', 'Expand']}
>
{([fullscreenCollapse, fullscreenExpand]) => (
<EuiButtonIcon
className="euiCodeBlock__fullScreenButton"
size="s"
onClick={this.toggleFullScreen}
iconType={this.state.isFullScreen ? 'cross' : 'fullScreen'}
color="text"
aria-label={this.state.isFullScreen ? fullscreenCollapse : fullscreenExpand}
/>
)}
</EuiI18n>
);
}

Expand Down
32 changes: 10 additions & 22 deletions src/components/code_editor/__snapshots__/code_editor.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,12 @@ exports[`EuiCodeEditor behavior hint element should be disabled when the ui ace
<p
class="euiText"
>
Press Enter to start
editing
.
Press Enter to start editing.
</p>
<p
class="euiText"
>
When you’re done, press Escape to stop
editing
.
When you're done, press Escape to stop editing.
</p>
</div>
`;
Expand All @@ -36,16 +32,12 @@ exports[`EuiCodeEditor behavior hint element should be enabled when the ui ace b
<p
class="euiText"
>
Press Enter to start
editing
.
Press Enter to start editing.
</p>
<p
class="euiText"
>
When you’re done, press Escape to stop
editing
.
When you're done, press Escape to stop editing.
</p>
</div>
`;
Expand All @@ -61,16 +53,12 @@ exports[`EuiCodeEditor behavior hint element should be tabable 1`] = `
<p
class="euiText"
>
Press Enter to start
editing
.
Press Enter to start editing.
</p>
<p
class="euiText"
>
When you’re done, press Escape to stop
editing
.
When you're done, press Escape to stop editing.
</p>
</div>
`;
Expand All @@ -95,7 +83,7 @@ exports[`EuiCodeEditor is rendered 1`] = `
<p
class="euiText"
>
When youre done, press Escape to stop editing.
When you're done, press Escape to stop editing.
</p>
</div>
<div
Expand Down Expand Up @@ -211,7 +199,7 @@ exports[`EuiCodeEditor props aria attributes allows setting aria-describedby on
<p
class="euiText"
>
When youre done, press Escape to stop editing.
When you're done, press Escape to stop editing.
</p>
</div>
<div
Expand Down Expand Up @@ -327,7 +315,7 @@ exports[`EuiCodeEditor props aria attributes allows setting aria-labelledby on t
<p
class="euiText"
>
When youre done, press Escape to stop editing.
When you're done, press Escape to stop editing.
</p>
</div>
<div
Expand Down Expand Up @@ -443,7 +431,7 @@ exports[`EuiCodeEditor props isReadOnly renders alternate hint text 1`] = `
<p
class="euiText"
>
When youre done, press Escape to stop interacting with the code.
When you're done, press Escape to stop interacting with the code.
</p>
</div>
<div
Expand Down
15 changes: 12 additions & 3 deletions src/components/code_editor/code_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import classNames from 'classnames';
import AceEditor from 'react-ace';

import { htmlIdGenerator, keyCodes } from '../../services';
import { EuiI18n } from '../i18n';

function setOrRemoveAttribute(element, attributeName, value) {
if (value === null || value === undefined) {
Expand Down Expand Up @@ -141,11 +142,11 @@ export class EuiCodeEditor extends Component {
filteredCursorStart = cursorStart;
}

const activityLabel = isReadOnly ? 'Interacting' : 'Editing';
const activity = isReadOnly
? 'interacting with the code'
: 'editing';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this getting localised too? Not obvious that it is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, activityLabel is used in forming the tokens later. However, how I'm using it here breaks the planned static analysis of tokens, I'll refactor.



// Don't use EuiKeyboardAccessible here because it doesn't play nicely with onKeyDown.
const prompt = (
<div
Expand All @@ -159,11 +160,19 @@ export class EuiCodeEditor extends Component {
data-test-subj="codeEditorHint"
>
<p className="euiText">
Press Enter to start {activity}.
<EuiI18n
token={`euiCodeEditor.start${activityLabel}`}
default={`Press Enter to start ${activity}.`}
values={{ activity }}
/>
</p>

<p className="euiText">
When you&rsquo;re done, press Escape to stop {activity}.
<EuiI18n
token={`euiCodeEditor.stop${activityLabel}`}
default={` When you're done, press Escape to stop ${activity}.`}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case whitespace matters:

Suggested change
default={` When you're done, press Escape to stop ${activity}.`}
default={`When you're done, press Escape to stop ${activity}.`}

values={{ activity }}
/>
</p>
</div>
);
Expand Down
32 changes: 25 additions & 7 deletions src/components/color_picker/color_picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ChromePicker } from 'react-color';
import { EuiOutsideClickDetector } from '../outside_click_detector';

import { EuiColorPickerSwatch } from './color_picker_swatch';
import { EuiI18n } from '../i18n';

export class EuiColorPicker extends Component {
constructor(props) {
Expand All @@ -30,15 +31,32 @@ export class EuiColorPicker extends Component {
};

getColorLabel() {
const { color } = this.props;
const colorValue = color === null ? '(transparent)' : color;
return (
<div
className="euiColorPicker__label"
aria-label={`Color selection is ${ colorValue }`}
<EuiI18n
token="euiColorPicker.transparentColor"
default="transparent"
>
{ colorValue }
</div>
{transparentColor => {
const { color } = this.props;
const colorValue = color === null ? `(${transparentColor})` : color;
return (
<EuiI18n
token="euiColorPicker.colorSelectionLabel"
default="Color selection is {colorValue}"
values={{ colorValue }}
>
{colorSelectionLabel => (
<div
className="euiColorPicker__label"
aria-label={colorSelectionLabel}
>
{ colorValue }
</div>
)}
</EuiI18n>
);
}}
</EuiI18n>
);
}

Expand Down
41 changes: 25 additions & 16 deletions src/components/combo_box/combo_box_input/combo_box_pill.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
import classNames from 'classnames';

import { EuiBadge } from '../../badge';
import { EuiI18n } from '../../i18n';

export class EuiComboBoxPill extends Component {
static propTypes = {
Expand Down Expand Up @@ -47,23 +48,31 @@ export class EuiComboBoxPill extends Component {

if (onClose) {
return (
<EuiBadge
className={classes}
title={children}
iconOnClick={this.onCloseButtonClick}
iconOnClickAriaLabel={`Remove ${children} from selection in this group`}
iconType="cross"
iconSide="right"
color={color}
closeButtonProps={{
tabIndex: '-1',
}}
onClick={onClick}
onClickAriaLabel={onClickAriaLabel}
{...rest}
<EuiI18n
token="euiComboBoxPill.removeSelection"
default="Remove {children} from selection in this group"
values={{ children }}
>
{children}
</EuiBadge>
{removeSelection => (
<EuiBadge
className={classes}
title={children}
iconOnClick={this.onCloseButtonClick}
iconOnClickAriaLabel={removeSelection}
iconType="cross"
iconSide="right"
color={color}
closeButtonProps={{
tabIndex: '-1',
}}
onClick={onClick}
onClickAriaLabel={onClickAriaLabel}
{...rest}
>
{children}
</EuiBadge>
)}
</EuiI18n>
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { EuiText } from '../../text';
import { EuiLoadingSpinner } from '../../loading';
import { EuiComboBoxOption } from './combo_box_option';
import { EuiComboBoxTitle } from './combo_box_title';
import { EuiI18n } from '../../i18n';

const positionToClassNameMap = {
top: 'euiComboBoxOptionsList--top',
Expand Down Expand Up @@ -129,7 +130,7 @@ export class EuiComboBoxOptionsList extends Component {
<EuiLoadingSpinner size="m" />
</EuiFlexItem>
<EuiFlexItem grow={false}>
Loading options
<EuiI18n token="euiComboBoxOptionsList.loadingOptions" default="Loading options"/>
</EuiFlexItem>
</EuiFlexGroup>
);
Expand All @@ -139,22 +140,48 @@ export class EuiComboBoxOptionsList extends Component {
if (selectedOptionForValue) {
// Disallow duplicate custom options.
emptyStateContent = (
<p><strong>{selectedOptionForValue.value}</strong> has already been added</p>
<p>
<EuiI18n
token="euiComboBoxOptionsList.alreadyAdded"
default="{label} has already been added"
values={{ label: <strong>{selectedOptionForValue.label}</strong> }}
/>
</p>
);
} else {
emptyStateContent = (
<p>Hit <EuiCode>ENTER</EuiCode> to add <strong>{searchValue}</strong> as a custom option</p>
<p>
<EuiI18n
token="euiComboBoxOptionsList.createCustomOption"
default="Hit {key} to add {searchValue} as a custom option"
values={{ key: <EuiCode>ENTER</EuiCode>, searchValue: <strong>{searchValue}</strong> }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should ENTER be localised?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is still localizable, the consumer can ignore that default value in their formatting:

'euiComboBoxOptionsList.createCustomOption': ({ searchValue }) => {
  return i18n.translate(
    'common.ui.euiComboBoxOptionsList.createCustomOption',
    {
      defaultMessage: 'Hit <EuiCode>ENTER</EuiCode> to add {searchValue} as a custom option',
      values: { searchValue // forwarded from EUI's call into this function }
    }
  );
}

Since react-intl allows JSX in the translations, the key value can be ignored and the localized value put directly into the message.

/>
</p>
);
}
} else {
emptyStateContent = (
<p><strong>{searchValue}</strong> doesn&rsquo;t match any options</p>
<p>
<EuiI18n
token="euiComboBoxOptionsList.noMatchingOptions"
default="{searchValue} doesn't match any options"
values={{ searchValue: <strong>{searchValue}</strong> }}
/>
</p>
);
}
} else if (!options.length) {
emptyStateContent = <p>There aren&rsquo;t any options available</p>;
emptyStateContent = (
<p>
<EuiI18n token="euiComboBoxOptionsList.noAvailableOptions" default="There aren't any options available"/>
</p>
);
} else if (areAllOptionsSelected) {
emptyStateContent = <p>You&rsquo;ve selected all available options</p>;
emptyStateContent = (
<p>
<EuiI18n token="euiComboBoxOptionsList.allOptionsSelected" default="You've selected all available options"/>
</p>
);
}

const emptyState = emptyStateContent ? (
Expand Down
Loading