UNPKG

ra-core

Version:

Core components of react-admin, a frontend Framework for building admin applications on top of REST services, using ES6, React

32 lines 1.07 kB
import { useCallback } from 'react'; import { useI18nProvider } from './useI18nProvider'; /** * Translate a string using the current locale and the translations from the i18nProvider * * @see Polyglot.t() * @link https://airbnb.io/polyglot.js/#polyglotprototypetkey-interpolationoptions * * @return {Function} A translation function, accepting two arguments * - a string used as key in the translations * - an interpolationOptions object * * @example * * import { useTranslate } from 'react-admin'; * * const SettingsMenu = () => { * const translate = useTranslate(); * return <MenuItem>{translate('settings')}</MenuItem>; * } */ export var useTranslate = function () { var i18nProvider = useI18nProvider(); var translate = useCallback(function (key, options) { return i18nProvider.translate(key, options); }, // update the hook each time the locale changes [i18nProvider]); return i18nProvider ? translate : identity; }; var identity = function (key) { return key; }; //# sourceMappingURL=useTranslate.js.map