Fix toot relative time does not align with app's language

This commit is contained in:
xmflsct 2022-12-03 21:56:52 +01:00
parent 0fd3fcfd3f
commit 7421ffd1bc
4 changed files with 19 additions and 18 deletions

View File

@ -1,5 +1,4 @@
import { ActionSheetProvider } from '@expo/react-native-action-sheet' import { ActionSheetProvider } from '@expo/react-native-action-sheet'
import getLanguage from '@helpers/getLanguage'
import queryClient from '@helpers/queryClient' import queryClient from '@helpers/queryClient'
import i18n from '@root/i18n/i18n' import i18n from '@root/i18n/i18n'
import Screens from '@root/Screens' import Screens from '@root/Screens'
@ -13,11 +12,12 @@ import timezone from '@root/startup/timezone'
import { persistor, store } from '@root/store' import { persistor, store } from '@root/store'
import * as Sentry from '@sentry/react-native' import * as Sentry from '@sentry/react-native'
import AccessibilityManager from '@utils/accessibility/AccessibilityManager' import AccessibilityManager from '@utils/accessibility/AccessibilityManager'
import { changeLanguage } from '@utils/slices/settingsSlice' import { changeLanguage, getSettingsLanguage } from '@utils/slices/settingsSlice'
import ThemeManager from '@utils/styles/ThemeManager' import ThemeManager from '@utils/styles/ThemeManager'
import * as Localization from 'expo-localization' import * as Localization from 'expo-localization'
import * as SplashScreen from 'expo-splash-screen' import * as SplashScreen from 'expo-splash-screen'
import React, { useCallback, useEffect, useState } from 'react' import React, { useCallback, useEffect, useState } from 'react'
import { IntlProvider } from 'react-intl'
import { LogBox, Platform } from 'react-native' import { LogBox, Platform } from 'react-native'
import { GestureHandlerRootView } from 'react-native-gesture-handler' import { GestureHandlerRootView } from 'react-native-gesture-handler'
import { SafeAreaProvider } from 'react-native-safe-area-context' import { SafeAreaProvider } from 'react-native-safe-area-context'
@ -85,7 +85,7 @@ const App: React.FC = () => {
if (bootstrapped) { if (bootstrapped) {
log('log', 'App', 'loading actual app :)') log('log', 'App', 'loading actual app :)')
log('log', 'App', `Locale: ${Localization.locale}`) log('log', 'App', `Locale: ${Localization.locale}`)
const language = getLanguage() const language = getSettingsLanguage(store.getState())
if (!language) { if (!language) {
if (Platform.OS !== 'ios') { if (Platform.OS !== 'ios') {
store.dispatch(changeLanguage('en')) store.dispatch(changeLanguage('en'))
@ -96,6 +96,7 @@ const App: React.FC = () => {
} }
return ( return (
<IntlProvider locale={language}>
<SafeAreaProvider> <SafeAreaProvider>
<ActionSheetProvider> <ActionSheetProvider>
<AccessibilityManager> <AccessibilityManager>
@ -105,6 +106,7 @@ const App: React.FC = () => {
</AccessibilityManager> </AccessibilityManager>
</ActionSheetProvider> </ActionSheetProvider>
</SafeAreaProvider> </SafeAreaProvider>
</IntlProvider>
) )
} else { } else {
return null return null

View File

@ -27,7 +27,6 @@ import * as Linking from 'expo-linking'
import { addScreenshotListener } from 'expo-screen-capture' import { addScreenshotListener } from 'expo-screen-capture'
import React, { useCallback, useEffect, useRef, useState } from 'react' import React, { useCallback, useEffect, useRef, useState } from 'react'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { IntlProvider } from 'react-intl'
import { Alert, Platform, StatusBar } from 'react-native' import { Alert, Platform, StatusBar } from 'react-native'
import ShareMenu from 'react-native-share-menu' import ShareMenu from 'react-native-share-menu'
import { useSelector } from 'react-redux' import { useSelector } from 'react-redux'
@ -271,7 +270,7 @@ const Screens: React.FC<Props> = ({ localCorrupt }) => {
}, []) }, [])
return ( return (
<IntlProvider locale={i18n.language}> <>
<StatusBar <StatusBar
backgroundColor={colors.backgroundDefault} backgroundColor={colors.backgroundDefault}
{...(Platform.OS === 'android' && { {...(Platform.OS === 'android' && {
@ -348,7 +347,7 @@ const Screens: React.FC<Props> = ({ localCorrupt }) => {
<Message /> <Message />
</NavigationContainer> </NavigationContainer>
</IntlProvider> </>
) )
} }

View File

@ -9,7 +9,7 @@ export interface Props {
const RelativeTime: React.FC<Props> = ({ time }) => { const RelativeTime: React.FC<Props> = ({ time }) => {
const [now, setNow] = useState(new Date().getTime()) const [now, setNow] = useState(new Date().getTime())
useEffect(() => { useEffect(() => {
const appStateListener = AppState.addEventListener('change', state => { const appStateListener = AppState.addEventListener('change', () => {
setNow(new Date().getTime()) setNow(new Date().getTime())
}) })

View File

@ -2,10 +2,10 @@ import * as Localization from 'expo-localization'
import log from './log' import log from './log'
const timezone = () => { const timezone = () => {
log('log', 'Timezone', Localization.timezone) log('log', 'Timezone', Localization.getCalendars()[0].timeZone || 'unknown')
if ('__setDefaultTimeZone' in Intl.DateTimeFormat) { if ('__setDefaultTimeZone' in Intl.DateTimeFormat) {
// @ts-ignore // @ts-ignore
Intl.DateTimeFormat.__setDefaultTimeZone(Localization.timezone) Intl.DateTimeFormat.__setDefaultTimeZone(Localization.getCalendars()[0].timeZone)
} }
} }