Commit cef2bf0c by Vladislav Lagunov

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

parent e5927de2
......@@ -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}/>)}
<Suggestions
{...suggestionProps}
ctx={ctx}
ctx={ctx!}
anchorEl={anchorEl || this.anchorEl || undefined}
open={open}
suggestions={suggestions}
......
......@@ -8,12 +8,13 @@ import Paper from '@material-ui/core/Paper';
import withStyles, { WithStyles, StyleRules } from '@material-ui/core/styles/withStyles';
import { StandardProps } from '@material-ui/core';
import PendingOverlay from '@bitmaster/components/PendingOverlay';
import { Ctx, pgettext } from '@bitmaster/utils/gettext';
import { LocaleCtx, Gettext, withGettext } from '~/gettext';
// props
export type Props<A=any> = StandardProps<React.HTMLProps<HTMLDivElement>, string> & WithStyles<string> & {
ctx?: Ctx;
__: Gettext;
ctx: LocaleCtx;
suggestions: A[];
renderSuggestion?(a: A): React.ReactElement<MenuItemProps>|string;
anchorEl?: HTMLElement;
......@@ -178,9 +179,8 @@ class Suggestions<A> extends React.Component<Props<A>, State> {
}
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 __ = k => pgettext(ctx || null, 'autocomplete', k);
return <Modal className={classes.modal} open={!!open} onClose={this.handleClose} disableAutoFocus disableEnforceFocus disableRestoreFocus hideBackdrop>
<Paper {...PaperProps}>
......@@ -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
......
import * as React from 'react';
import { pgettext } from '@bitmaster/utils/gettext';
import { Theme } from '@material-ui/core/styles/createMuiTheme';
import withStyles, { StyleRules, WithStyles } from '@material-ui/core/styles/withStyles';
import * as classNames from 'classnames';
import { FieldProps } from './';
import { StandardProps } from '@material-ui/core';
import { withGettext, Gettext, LocaleCtx } from '~/gettext';
const eye = require('./eye.svg');
const eyeSlash = require('./eye-slash.svg');
// Props
export type Props = StandardProps<React.HTMLProps<HTMLDivElement>, ClassKey, 'ref'|'onKeyDown'|'disabled'> & FieldProps<string> & WithStyles<ClassKey> & {
__: Gettext;
ctx?: LocaleCtx;
type?: React.HTMLProps<HTMLInputElement>['type'];
filter?(s: string): boolean;
regexFilter?: RegExp;
......@@ -54,6 +55,7 @@ export class TextField extends React.Component<Props, State> {
render() {
const {
__,
ctx,
classes,
// dirty,
......@@ -84,7 +86,6 @@ export class TextField extends React.Component<Props, State> {
const inputClass = classNames(classes.input, {
[classes.error]: error,
});
const __ = k => ctx ? pgettext(ctx, 'fields', k) : k;
const Input: any = InputProp || 'input';
const endAdornment = type !== 'password-switch' ? _endAdornment : <React.Fragment>
{_endAdornment}
......@@ -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 классы
......
export default {
"ru-RU": {
"Fill out this field": "Заполните это поле",
"Nothing found…": "Ничего не найдено…",
},
"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