Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { Login, Layout } from './layout';
import { Dashboard } from './dashboard';
import customRoutes from './routes';
import englishMessages from './i18n/en';
import visitors from './visitors';
import orders from './orders';
import products from './products';
import invoices from './invoices';
import categories from './categories';
import reviews from './reviews';
import dataProviderFactory from './dataProvider';
import fakeServerFactory from './fakeServer';
const i18nProvider = polyglotI18nProvider(locale => {
if (locale === 'fr') {
return import('./i18n/fr').then(messages => messages.default);
}
// Always fallback on english
return englishMessages;
}, 'en');
const App = () => {
const [dataProvider, setDataProvider] = useState(null);
useEffect(() => {
let restoreFetch;
const fetchDataProvider = async () => {
restoreFetch = await fakeServerFactory(
}
}
}
const prepareLanguage = (lang) => {
removeEmpty(lang)
// Make "albumSong" and "playlistTrack" resource use the same translations as "song"
lang.resources.albumSong = lang.resources.song
lang.resources.playlistTrack = lang.resources.song
// ra.boolean.null should always be empty
lang.ra.boolean.null = ''
// Fallback to english translations
return deepmerge(en, lang)
}
export default polyglotI18nProvider((locale) => {
// English is bundled
if (locale === 'en') {
return prepareLanguage(en)
}
// If the requested locale is in already loaded, return it
const current = JSON.parse(localStorage.getItem('translation'))
if (current && current.id === locale) {
return prepareLanguage(JSON.parse(current.data))
}
// If not, get it from the server, and store it in localStorage
return retrieveTranslation(locale)
}, defaultLocale())
it('should use the i18n provider when using TranslationProvider', async () => {
const i18nProvider = polyglotI18nProvider(locale => {
if (locale === 'en') return { hello: 'hello' };
if (locale === 'fr') return { hello: 'bonjour' };
});
const { getByText, queryAllByText } = renderWithRedux(
);
expect(queryAllByText('hello')).toHaveLength(1);
expect(queryAllByText('bonjour')).toHaveLength(0);
act(() => {
fireEvent.click(getByText('Français'));
});
await wait();
expect(queryAllByText('hello')).toHaveLength(0);
expect(queryAllByText('bonjour')).toHaveLength(1);