UNPKG

strapi-plugin-i18n

Version:

This plugin enables to create, to read and to update content in different languages, both from the Admin Panel and from the API

36 lines (28 loc) 885 B
import { useEffect } from 'react'; import { request } from 'strapi-helper-plugin'; import { useSelector, useDispatch } from 'react-redux'; import { RESOLVE_LOCALES } from '../constants'; const fetchLocalesList = async () => { try { const data = await request('/i18n/locales', { method: 'GET', }); return data; } catch (e) { strapi.notification.toggle({ type: 'warning', message: { id: 'notification.error' }, }); return e; } }; const useLocales = () => { const dispatch = useDispatch(); const locales = useSelector(state => state.get('i18n_locales').locales); const isLoading = useSelector(state => state.get('i18n_locales').isLoading); useEffect(() => { fetchLocalesList().then(locales => dispatch({ type: RESOLVE_LOCALES, locales })); }, [dispatch]); return { locales, isLoading }; }; export default useLocales;