More translations, also trying to get localise jest language to work

This commit is contained in:
Viktor Sarström 2021-04-13 21:49:30 +02:00
parent 4098b7d442
commit 2dfe675579
6 changed files with 63 additions and 20 deletions

View File

@ -13,11 +13,11 @@ const getNumberFormatSettings = () => ({
groupingSeparator: ',',
})
const getCalendar = () => 'gregorian' // or "japanese", "buddhist"
const getCountry = () => 'US' // the country code you want
const getCurrencies = () => ['USD', 'EUR'] // can be empty array
const getTemperatureUnit = () => 'celsius' // or "fahrenheit"
const getTimeZone = () => 'Europe/Paris' // the timezone you want
const getCalendar = () => 'gregorian'
const getCountry = () => 'SE'
const getCurrencies = () => ['USD', 'SEK']
const getTemperatureUnit = () => 'celsius'
const getTimeZone = () => 'Europe/Stockholm'
const uses24HourClock = () => true
const usesMetricSystem = () => true

View File

@ -3,16 +3,23 @@ import { render } from '../../utils/testHelpers'
import React from 'react'
import { Auth } from '../auth.component'
import { useAsyncStorage } from 'use-async-storage'
import { findBestAvailableLanguage } from 'react-native-localize'
jest.mock('@skolplattformen/api-hooks')
jest.mock('use-async-storage')
jest.mock('react-native-localize')
const setup = () => {
const setup = (lang = 'sv') => {
useApi.mockReturnValue({
api: { on: jest.fn(), off: jest.fn() },
isLoggedIn: false,
})
findBestAvailableLanguage.mockReturnValue({
languageTag: lang,
isRTL: false,
})
const navigation = {
navigate: jest.fn(),
}
@ -28,3 +35,10 @@ test('renders a random fun argument state', () => {
expect(screen.getByText(/öppna skolplattformen/i)).toBeTruthy()
expect(screen.getByText(/det [a-zåäö]+ alternativet/i)).toBeTruthy()
})
test('renders a random fun argument state in english', () => {
const screen = setup('en')
expect(screen.getByText(/open school platform/i)).toBeTruthy()
expect(screen.getByText(/the [a-zåäö]+ alternative/i)).toBeTruthy()
})

View File

@ -193,21 +193,25 @@ export const ChildListItem = ({ child, color }: ChildListItemProps) => {
))}
{notificationsThisWeek.slice(0, 3).map((notification, i) => (
<Text appearance="hint" category="c1" key={i}>
{`Avisering: ${notification.message} (${displayDate(
notification.dateCreated
)})`}
{translate('notifications.notificationTitle', {
message: notification.message,
dateCreated: displayDate(notification.dateCreated),
})}
</Text>
))}
{newsThisWeek.slice(0, 3).map((newsItem, i) => (
<Text appearance="hint" category="c1" key={i}>
{`Nyhet: ${newsItem.header} (${displayDate(newsItem.published)})`}
{translate('notifications.notificationTitle', {
header: newsItem.header,
published: displayDate(newsItem.published),
})}
</Text>
))}
{scheduleAndCalendarThisWeek.length ||
notificationsThisWeek.length ||
newsThisWeek.length ? null : (
<Text appearance="hint" category="c1">
Inga nya inlägg denna vecka.
{translate('news.noNewNewsItemsThisWeek')}
</Text>
)}
<View style={styles.itemFooterAbsence}>

View File

@ -4,6 +4,7 @@ import React from 'react'
import { StyleSheet } from 'react-native'
import RNCalendarEvents from 'react-native-calendar-events'
import Toast from 'react-native-simple-toast'
import { translate } from '../utils/translation'
import { CalendarOutlineIcon, MoreIcon } from './icon.component'
interface SaveToCalendarProps {
@ -15,7 +16,7 @@ export const SaveToCalendar = ({ event }: SaveToCalendarProps) => {
const renderToggleButton = () => (
<Button
accessibilityLabel="Visa kalender actions"
accessibilityLabel={translate('calender.showCalenderActions')}
onPress={() => setVisible(true)}
appearance="ghost"
accessoryLeft={MoreIcon}
@ -59,13 +60,13 @@ export const SaveToCalendar = ({ event }: SaveToCalendarProps) => {
await RNCalendarEvents.saveEvent(title, detailsWithoutEmpty)
toast('✔️ Sparad till kalender')
toast(translate('calender.saveToCalenderSuccess'))
} catch (err) {
toast('Något gick fel')
toast(translate('calender.saveToCalenderError'))
}
closeOverflowMenu()
} else {
toast('Du måste godkänna access till kalender')
toast(translate('calender.approveAccessToCalender'))
}
}
@ -77,9 +78,9 @@ export const SaveToCalendar = ({ event }: SaveToCalendarProps) => {
onBackdropPress={closeOverflowMenu}
>
<MenuItem
accessibilityLabel="Spara till kalender"
accessibilityLabel={translate('calender.saveToCalender')}
accessoryLeft={CalendarOutlineIcon}
title="Spara till kalender"
title={translate('calender.saveToCalender')}
onPress={() => requestPermissionsAndSave(event)}
/>
</OverflowMenu>

View File

@ -53,10 +53,22 @@
"abscense": {
"title": "Report absence",
"selectAbscenseEndTime": "Choose end time",
"entireDay": "Whole day"
"entireDay": "Whole day",
"newsTitle": "News item: {{header}} ({{published}})"
},
"news": {
"title": "News from the school platform",
"backToChild": "Back to child"
"backToChild": "Back to child",
"noNewNewsItemsThisWeek": "No new news items this week.",
"notificationTitle": "Notification: {{message}} ({{dateCreated}})"
},
"notifications": {
"notificationTitle": "Notification: {{message}} ({{dateCreated}})"
},
"calender": {
"showCalenderActions": "Show calender actions",
"saveToCalenderSuccess": "✔️ Saved to calender",
"saveToCalenderError": "Something went wrong",
"approveAccessToCalender": "You have to approve access to your calender"
}
}

View File

@ -57,6 +57,18 @@
},
"news": {
"title": "Nyhet från skolplattformen",
"backToChild": "Tillbaka till barn"
"backToChild": "Tillbaka till barn",
"noNewNewsItemsThisWeek": "Inga nya inlägg denna vecka.",
"newsTitle": "Nyhet: {{message}} ({{dateCreated}})"
},
"notifications": {
"notificationTitle": "Avisering: {{message}} ({{dateCreated}})"
},
"calender": {
"saveToCalender": "Spara till kalender",
"showCalenderActions": "Visa kalender actions",
"saveToCalenderSuccess": "✔️ Sparad till kalender",
"saveToCalenderError": "Något gick fel",
"approveAccessToCalender": "Du måste godkänna access till kalender"
}
}