How to use the ra-core.useTranslate function in ra-core

To help you get started, we’ve selected a few ra-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github marmelab / react-admin / packages / ra-ui-materialui / src / list / PaginationActions.js View on Github external
function PaginationActions({
    classes: classesOverride,
    page,
    rowsPerPage,
    count,
    onChangePage,
}) {
    const classes = useStyles({ classes: classesOverride });
    const translate = useTranslate();
    /**
     * Warning: material-ui's page is 0-based
     */
    const range = () => {
        const nbPages = Math.ceil(count / rowsPerPage) || 1;
        if (isNaN(page) || nbPages === 1) {
            return [];
        }
        const input = [];
        // display page links around the current page
        if (page > 1) {
            input.push(1);
        }
        if (page === 3) {
            input.push(2);
        }
github marmelab / react-admin / packages / ra-ui-materialui / src / input / ResettableTextField.js View on Github external
function ResettableTextField({
    classes: classesOverride,
    clearAlwaysVisible,
    InputProps,
    value,
    resettable,
    disabled,
    variant = 'filled',
    margin = 'dense',
    ...props
}) {
    const classes = useStyles({ classes: classesOverride });
    const translate = useTranslate();

    const { onChange, onFocus, onBlur } = props;
    const handleClickClearButton = useCallback(
        event => {
            event.preventDefault();
            onChange('');
        },
        [onChange]
    );

    const handleFocus = useCallback(
        event => {
            onFocus && onFocus(event);
        },
        [onFocus]
    );
github marmelab / react-admin / packages / ra-ui-materialui / src / button / RefreshIconButton.js View on Github external
const RefreshIconButton = ({
    label = 'ra.action.refresh',
    icon = defaultIcon,
    onClick,
    className,
    ...rest
}) => {
    const dispatch = useDispatch();
    const translate = useTranslate();
    const handleClick = useCallback(
        event => {
            event.preventDefault();
            dispatch(refreshView());
            if (typeof onClick === 'function') {
                onClick();
            }
        },
        [dispatch, onClick]
    );

    return (
github marmelab / react-admin / packages / ra-ui-materialui / src / input / SearchInput.tsx View on Github external
> = ({ classes: classesOverride, ...props }) => {
    const translate = useTranslate();
    const classes = useStyles({ classes: classesOverride });

    return (
        
                        
                    
                ),
            }}
            className={classes.input}
github marmelab / react-admin / packages / ra-ui-materialui / src / input / InputHelperText.tsx View on Github external
const InputHelperText: FunctionComponent = ({
    helperText,
    touched,
    error,
}) => {
    const translate = useTranslate();

    return touched && error ? (
        
    ) : helperText ? (
        <>{translate(helperText, { _: helperText })}
    ) : null;
};
github marmelab / react-admin / packages / ra-ui-materialui / src / list / ExpandRowButton.tsx View on Github external
const ExpandRowButton = ({ classes, expanded, expandContentId, ...props }) => {
    const translate = useTranslate();
    return (
github marmelab / react-admin / packages / ra-ui-materialui / src / layout / Error.js View on Github external
const Error = ({
    error,
    errorInfo,
    classes: classesOverride,
    className,
    title,
    ...rest
}) => {
    const classes = useStyles({ classes: classesOverride });
    const translate = useTranslate();
    return (
        
            <title>
            &lt;div className={classnames(classes.container, className)} {...rest}&gt;
                &lt;h1 className={classes.title} role="alert"&gt;
                    &lt;ErrorIcon className={classes.icon} /&gt;
                    {translate('ra.page.error')}
                &lt;/h1&gt;
                &lt;div&gt;{translate('ra.message.error')}&lt;/div&gt;
                {process.env.NODE_ENV !== 'production' &amp;&amp; (
                    &lt;ExpansionPanel className={classes.panel}&gt;
                        &lt;ExpansionPanelSummary expandIcon={&lt;ExpandMoreIcon /&gt;}&gt;
                            {translate('ra.message.details')}
                        &lt;/ExpansionPanelSummary&gt;
                        &lt;ExpansionPanelDetails className={classes.panelDetails}&gt;
                            &lt;div&gt;</title>
github marmelab / react-admin / packages / ra-ui-materialui / src / field / BooleanField.tsx View on Github external
&gt; = ({
    className,
    classes: classesOverride,
    source,
    record = {},
    valueLabelTrue,
    valueLabelFalse,
    ...rest
}) =&gt; {
    const classes = useStyles({ classes: classesOverride });
    const translate = useTranslate();
    const value = get(record, source);
    let ariaLabel = value ? valueLabelTrue : valueLabelFalse;

    if (!ariaLabel) {
        ariaLabel = value === false ? 'ra.boolean.false' : 'ra.boolean.true';
    }

    if (value === false) {
        return (
            
                <span></span>
github marmelab / react-admin / packages / ra-ui-materialui / src / field / SelectField.tsx View on Github external
export const SelectField: SFC = ({
    className,
    source,
    record,
    choices,
    optionValue,
    optionText,
    translateChoice,
    ...rest
}) =&gt; {
    const translate = useTranslate();
    const value = get(record, source);
    const choice = choices.find(c =&gt; c[optionValue] === value);
    if (!choice) {
        return null;
    }
    let choiceIsElement = false;
    let choiceName;
    if (React.isValidElement(optionText)) {
        choiceIsElement = true;
        choiceName = React.cloneElement(optionText, { record: choice });
    } else {
        choiceName =
            typeof optionText === 'function'
                ? optionText(choice)
                : choice[optionText];
    }
github marmelab / react-admin / packages / ra-ui-materialui / src / auth / LoginForm.tsx View on Github external
const LoginForm: FunctionComponent = ({ redirectTo }) =&gt; {
    const [loading, setLoading] = useSafeSetState(false);
    const login = useLogin();
    const translate = useTranslate();
    const notify = useNotify();
    const classes = useStyles({});

    const validate = (values: FormData) =&gt; {
        const errors = { username: undefined, password: undefined };

        if (!values.username) {
            errors.username = translate('ra.validation.required');
        }
        if (!values.password) {
            errors.password = translate('ra.validation.required');
        }
        return errors;
    };

    const submit = values =&gt; {