Skip to content

Commit

Permalink
feat: reload i18n without window.location.reload (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicosantangelo authored Mar 9, 2020
1 parent 41681ba commit 9815605
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
10 changes: 2 additions & 8 deletions src/modules/translation/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
fetchTranslationsSuccess,
fetchTranslationsFailure,
FETCH_TRANSLATIONS_REQUEST,
CHANGE_LOCALE,
FetchTranslationsRequestAction
} from './actions'
import { setCurrentLocale, mergeTranslations } from './utils'
Expand All @@ -29,15 +28,15 @@ export function createTranslationSaga({
if (getTranslation) {
result = yield call(() => getTranslation(locale))
} else if (translations) {
result = flatten(translations[locale])
result = translations[locale]
} else {
throw new Error('You must provide `translations` or `getTranslations`')
}

// merge translations and defaults
result = mergeTranslations<TranslationKeys>(
flatten(defaultTranslations[locale]),
result
flatten(result)
)

setCurrentLocale(locale, result)
Expand All @@ -48,12 +47,7 @@ export function createTranslationSaga({
}
}

function handleChangeLocale() {
window.location.reload()
}

return function* translationSaga() {
yield takeEvery(FETCH_TRANSLATIONS_REQUEST, handleFetchTranslationsRequest)
yield takeEvery(CHANGE_LOCALE, handleChangeLocale)
}
}
2 changes: 1 addition & 1 deletion src/providers/TranslationProvider/TranslationProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default class TranslationProvider extends React.PureComponent<Props> {
const { children, locale, translations } = this.props

return translations && locale ? (
<I18nProvider locale={locale} messages={translations}>
<I18nProvider key={locale} locale={locale} messages={translations}>
{children}
</I18nProvider>
) : (
Expand Down

0 comments on commit 9815605

Please sign in to comment.