Commit cef2bf0c by Vladislav Lagunov

Рефакторинг gettext

parent e5927de2
...@@ -195,7 +195,7 @@ export default class AutoComplete<A=string> extends React.Component<Props<A>, St ...@@ -195,7 +195,7 @@ export default class AutoComplete<A=string> extends React.Component<Props<A>, St
{!observable && (children ? React.cloneElement(children, this.childrenProps()) : <TextField {...this.childrenProps() as any} {...textFieldProps}/>)} {!observable && (children ? React.cloneElement(children, this.childrenProps()) : <TextField {...this.childrenProps() as any} {...textFieldProps}/>)}
<Suggestions <Suggestions
{...suggestionProps} {...suggestionProps}
ctx={ctx} ctx={ctx!}
anchorEl={anchorEl || this.anchorEl || undefined} anchorEl={anchorEl || this.anchorEl || undefined}
open={open} open={open}
suggestions={suggestions} suggestions={suggestions}
......
...@@ -8,12 +8,13 @@ import Paper from '@material-ui/core/Paper'; ...@@ -8,12 +8,13 @@ import Paper from '@material-ui/core/Paper';
import withStyles, { WithStyles, StyleRules } from '@material-ui/core/styles/withStyles'; import withStyles, { WithStyles, StyleRules } from '@material-ui/core/styles/withStyles';
import { StandardProps } from '@material-ui/core'; import { StandardProps } from '@material-ui/core';
import PendingOverlay from '@bitmaster/components/PendingOverlay'; import PendingOverlay from '@bitmaster/components/PendingOverlay';
import { Ctx, pgettext } from '@bitmaster/utils/gettext'; import { LocaleCtx, Gettext, withGettext } from '~/gettext';
// props // props
export type Props<A=any> = StandardProps<React.HTMLProps<HTMLDivElement>, string> & WithStyles<string> & { export type Props<A=any> = StandardProps<React.HTMLProps<HTMLDivElement>, string> & WithStyles<string> & {
ctx?: Ctx; __: Gettext;
ctx: LocaleCtx;
suggestions: A[]; suggestions: A[];
renderSuggestion?(a: A): React.ReactElement<MenuItemProps>|string; renderSuggestion?(a: A): React.ReactElement<MenuItemProps>|string;
anchorEl?: HTMLElement; anchorEl?: HTMLElement;
...@@ -178,9 +179,8 @@ class Suggestions<A> extends React.Component<Props<A>, State> { ...@@ -178,9 +179,8 @@ class Suggestions<A> extends React.Component<Props<A>, State> {
} }
render() { render() {
const { classes, open, pending, suggestions, ctx } = this.props; const { __, classes, open, pending, suggestions } = this.props;
const PaperProps = { ref: this.handlePaperRef, className: classes.paper }; const PaperProps = { ref: this.handlePaperRef, className: classes.paper };
const __ = k => pgettext(ctx || null, 'autocomplete', k);
return <Modal className={classes.modal} open={!!open} onClose={this.handleClose} disableAutoFocus disableEnforceFocus disableRestoreFocus hideBackdrop> return <Modal className={classes.modal} open={!!open} onClose={this.handleClose} disableAutoFocus disableEnforceFocus disableRestoreFocus hideBackdrop>
<Paper {...PaperProps}> <Paper {...PaperProps}>
...@@ -192,7 +192,7 @@ class Suggestions<A> extends React.Component<Props<A>, State> { ...@@ -192,7 +192,7 @@ class Suggestions<A> extends React.Component<Props<A>, State> {
} }
} }
export default withStyles(styles)(Suggestions); export default withStyles(styles)(withGettext(require('./i18n'))(Suggestions));
// Styles // Styles
......
import * as React from 'react'; import * as React from 'react';
import { pgettext } from '@bitmaster/utils/gettext';
import { Theme } from '@material-ui/core/styles/createMuiTheme'; import { Theme } from '@material-ui/core/styles/createMuiTheme';
import withStyles, { StyleRules, WithStyles } from '@material-ui/core/styles/withStyles'; import withStyles, { StyleRules, WithStyles } from '@material-ui/core/styles/withStyles';
import * as classNames from 'classnames'; import * as classNames from 'classnames';
import { FieldProps } from './'; import { FieldProps } from './';
import { StandardProps } from '@material-ui/core'; import { StandardProps } from '@material-ui/core';
import { withGettext, Gettext, LocaleCtx } from '~/gettext';
const eye = require('./eye.svg'); const eye = require('./eye.svg');
const eyeSlash = require('./eye-slash.svg'); const eyeSlash = require('./eye-slash.svg');
// Props // Props
export type Props = StandardProps<React.HTMLProps<HTMLDivElement>, ClassKey, 'ref'|'onKeyDown'|'disabled'> & FieldProps<string> & WithStyles<ClassKey> & { export type Props = StandardProps<React.HTMLProps<HTMLDivElement>, ClassKey, 'ref'|'onKeyDown'|'disabled'> & FieldProps<string> & WithStyles<ClassKey> & {
__: Gettext;
ctx?: LocaleCtx;
type?: React.HTMLProps<HTMLInputElement>['type']; type?: React.HTMLProps<HTMLInputElement>['type'];
filter?(s: string): boolean; filter?(s: string): boolean;
regexFilter?: RegExp; regexFilter?: RegExp;
...@@ -54,6 +55,7 @@ export class TextField extends React.Component<Props, State> { ...@@ -54,6 +55,7 @@ export class TextField extends React.Component<Props, State> {
render() { render() {
const { const {
__,
ctx, ctx,
classes, classes,
// dirty, // dirty,
...@@ -84,7 +86,6 @@ export class TextField extends React.Component<Props, State> { ...@@ -84,7 +86,6 @@ export class TextField extends React.Component<Props, State> {
const inputClass = classNames(classes.input, { const inputClass = classNames(classes.input, {
[classes.error]: error, [classes.error]: error,
}); });
const __ = k => ctx ? pgettext(ctx, 'fields', k) : k;
const Input: any = InputProp || 'input'; const Input: any = InputProp || 'input';
const endAdornment = type !== 'password-switch' ? _endAdornment : <React.Fragment> const endAdornment = type !== 'password-switch' ? _endAdornment : <React.Fragment>
{_endAdornment} {_endAdornment}
...@@ -112,7 +113,7 @@ export class TextField extends React.Component<Props, State> { ...@@ -112,7 +113,7 @@ export class TextField extends React.Component<Props, State> {
} }
} }
export default withStyles(styles)(TextField); export default withStyles(styles)(withGettext(require('./i18n'))(TextField));
// CSS классы // CSS классы
......
export default { export default {
"ru-RU": { "ru-RU": {
"Fill out this field": "Заполните это поле", "Fill out this field": "Заполните это поле",
"Nothing found…": "Ничего не найдено…",
}, },
"lt-LT": { "lt-LT": {
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment