diff --git a/src/App.js b/src/App.js index feea4b0..977a236 100644 --- a/src/App.js +++ b/src/App.js @@ -47,12 +47,11 @@ const App = () => { const language = useSelector((state) => state.selectedLanguage) const activityGroups = useSelector((state) => state.activityGroups) const itemsByGuid = useSelector((state) => state.itemsByGuid) - const fetchContent = (language) => { fetchAgeGroups(language).then((ageGroups) => { dispatch(setInitialData(ageGroups)) }) - fetchTranslations().then((translations) => + fetchTranslations(language).then((translations) => dispatch(setTranslations(translations)) ) fetchActivityGroups(language).then((activityGroups) => diff --git a/src/api/index.js b/src/api/index.js index 8d012bf..044ba3f 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -53,10 +53,8 @@ export const fetchTaskDetails = async (guid, lang) => { return await res.json() } -export const fetchTranslations = async () => { - const res = await fetch( - 'https://pof-backend.partio.fi/tag-translations-json/' - ) +export const fetchTranslations = async (lang) => { + const res = await fetch(`${PARTIO_API_URL}/settings/translations/${lang}`) return await res.json() } diff --git a/src/components/AgeGroupItem/index.js b/src/components/AgeGroupItem/index.js index 3d4ef8e..04e6406 100644 --- a/src/components/AgeGroupItem/index.js +++ b/src/components/AgeGroupItem/index.js @@ -49,8 +49,8 @@ const Status = styled.div` const AgeGroupItem = ({ ageGroup, language, - translations, user, + translations, activityGroups, userTasks, }) => { @@ -59,7 +59,6 @@ const AgeGroupItem = ({ ? getAgeGroupStatus(ageGroup, userTasks) : null const icon = ageGroup.logo.url - return ( @@ -70,18 +69,14 @@ const AgeGroupItem = ({ {status && ( <> - {`${getTermInLanguage( - translations, - 'mandatory_plural', - language - )} ${status.mandatory}`} + {`${getTermInLanguage(translations, 'pakolliset')} ${ + status.mandatory + }`} - {`${getTermInLanguage( - translations, - 'optional_plural', - language - )} ${status.optional}`} + {`${getTermInLanguage(translations, 'valinnaiset')} ${ + status.optional + }`} )} diff --git a/src/components/Notifications/TaskNotification.js b/src/components/Notifications/TaskNotification.js index ab84fb4..90e4a47 100644 --- a/src/components/Notifications/TaskNotification.js +++ b/src/components/Notifications/TaskNotification.js @@ -4,10 +4,7 @@ import { Link } from 'react-router-dom' import { useSelector } from 'react-redux' import { getTaskUrl, getTimestamp } from './utils' -import { - determineLanguageFromUrl, - getTermInLanguage, -} from 'helpers' +import { getTermInLanguage } from 'helpers' const Container = styled.div` display: flex; @@ -25,23 +22,18 @@ const StyledLink = styled(Link)` color: #c86418; } ` - -// TODO: Refactor when we have translations - - const TaskNotification = ({ notification, markRead }) => { - const language = determineLanguageFromUrl(window.location) - const generalTranslations = useSelector(state => state.translations.yleiset) - const itemsByGuid = useSelector(state => state.itemsByGuid) + const translations = useSelector((state) => state.translations) + const itemsByGuid = useSelector((state) => state.itemsByGuid) const task = itemsByGuid[notification.item_guid] const timestamp = getTimestamp(notification.created_at) - const getStateMessage = state => { + const getStateMessage = (state) => { switch (state) { case 'ACCEPTED': - return getTermInLanguage(generalTranslations, 'accepted', language) + return getTermInLanguage(translations, 'hyvaksynyt') default: - return getTermInLanguage(generalTranslations, 'accepted', language) + return getTermInLanguage(translations, 'hyvaksynyt') } } @@ -49,8 +41,11 @@ const TaskNotification = ({ notification, markRead }) => { - {getTermInLanguage(generalTranslations, 'group_leader', language)} {notification.group_leader_name} {getTermInLanguage(generalTranslations, 'has', language)} {' '} - {getStateMessage(notification.notification_type)} {getTermInLanguage(generalTranslations, 'your_task', language)} {' '} + {getTermInLanguage(translations, 'ryhmanjohtaja')}{' '} + {notification.group_leader_name}{' '} + {getTermInLanguage(translations, 'on')}{' '} + {getStateMessage(notification.notification_type)}{' '} + {getTermInLanguage(translations, 'tehtavasi')}{' '} {task.item.title} diff --git a/src/components/Notifications/index.js b/src/components/Notifications/index.js index b7f191b..c6a65e7 100644 --- a/src/components/Notifications/index.js +++ b/src/components/Notifications/index.js @@ -12,10 +12,7 @@ import { markNotificationRead, toggleShowNotifications, } from '../../redux/actionCreators' -import { - determineLanguageFromUrl, - getTermInLanguage, -} from 'helpers' +import { getTermInLanguage } from 'helpers' const BUTTON_HEIGHT = '1rem' @@ -78,21 +75,20 @@ const MarkAllRead = styled.div` padding: 0rem; padding-top: 0.3rem; ` -const containsUnread = notifications => { +const containsUnread = (notifications) => { if (!notifications) return false - const unread = notifications.find(notification => !notification.viewed) + const unread = notifications.find((notification) => !notification.viewed) return !!unread } const Notifications = () => { const containerRef = useRef() - const language = determineLanguageFromUrl(window.location) const [hasUnread, setHasUnread] = useState(false) - const generalTranslations = useSelector(state => state.translations.yleiset) - const notifications = useSelector(state => state.notifications.list) - const showDropdown = useSelector(state => state.notifications.show) + const notifications = useSelector((state) => state.notifications.list) + const showDropdown = useSelector((state) => state.notifications.show) + const translations = useSelector((state) => state.translations) const dispatch = useDispatch() const [hasMore, setHasMore] = useState(true) const [displayNotifications, setDisplayNotifications] = useState([]) @@ -112,7 +108,7 @@ const Notifications = () => { notifications .slice(0, slice) .sort((a, b) => (a.viewed > b.viewed ? 1 : -1)) - .map(notification => ( + .map((notification) => ( { const nextSlice = () => { return notifications .slice(slice, slice + 10) - .map(notification => ( + .map((notification) => ( { } } - const markSingleNotificationRead = async notification => { + const markSingleNotificationRead = async (notification) => { const result = await markNotificationViewed(notification.id) if (result.success) { dispatch(markNotificationRead(notification.id)) @@ -172,7 +168,11 @@ const Notifications = () => { - {displayNotifications.length === 0 &&

{getTermInLanguage(generalTranslations, 'no_notifications', language)}

} + {displayNotifications.length === 0 && ( +

+ {getTermInLanguage(translations, 'ei-ilmoituksia')} +

+ )} {displayNotifications && ( { )}
- {getTermInLanguage(generalTranslations, 'mark_all_read', language)} + + {getTermInLanguage(translations, 'merkitse-kaikki-luetuksi')} +
)} diff --git a/src/components/TaskActions/GroupLeaderActions.js b/src/components/TaskActions/GroupLeaderActions.js index 6bc935a..38c3420 100644 --- a/src/components/TaskActions/GroupLeaderActions.js +++ b/src/components/TaskActions/GroupLeaderActions.js @@ -8,7 +8,7 @@ import { import { COMPLETION_STATUS } from '../../consts' import { useSelector } from 'react-redux' import { useParams } from 'react-router-dom' -import { determineLanguageFromUrl, getTermInLanguage } from '../../helpers' +import { getTermInLanguage } from '../../helpers' const Overlay = styled.div` width: 100%; @@ -78,13 +78,8 @@ const GroupLeaderActions = ({ const { groupId } = useParams() const { memberId } = useParams() - const language = determineLanguageFromUrl(window.location) - const groupsData = useSelector((state) => state.user.userGroups) - const generalTranslations = useSelector((state) => state.translations.yleiset) - const apiTypeTranslations = useSelector( - (state) => state.translations.api_type - ) + const translations = useSelector((state) => state.translations) const group = groupsData.find( (groups) => groups.id.toString() === groupId.toString() @@ -111,28 +106,26 @@ const GroupLeaderActions = ({ - {getTermInLanguage(generalTranslations, 'accept', language)}{' '} - {getTermInLanguage(apiTypeTranslations, 'task', language)} + {getTermInLanguage(translations, 'hyvaksy')}{' '} + {getTermInLanguage(translations, 'aktiviteetti')} )} {isCompleted === true && ( - Siirrä takaisin työn alle + {getTermInLanguage(translations, 'siirra-tyon-alle')} )} - {getTermInLanguage(generalTranslations, 'delete', language)}{' '} - {getTermInLanguage(apiTypeTranslations, 'task', language)} + {getTermInLanguage(translations, 'poista')}{' '} + {getTermInLanguage(translations, 'aktiviteetti')} - - {getTermInLanguage(generalTranslations, 'cancel', language)} - + {getTermInLanguage(translations, 'peruuta')} diff --git a/src/components/TaskActions/OpenTaskActions.js b/src/components/TaskActions/OpenTaskActions.js index 4fb2128..2ef6c7c 100644 --- a/src/components/TaskActions/OpenTaskActions.js +++ b/src/components/TaskActions/OpenTaskActions.js @@ -2,7 +2,7 @@ import React, { useState } from 'react' import styled, { keyframes } from 'styled-components' import { StyledCompletedIcon } from '../TaskActionsIcons' import { useSelector } from 'react-redux' -import { determineLanguageFromUrl, getTermInLanguage } from '../../helpers' +import { getTermInLanguage } from '../../helpers' import { Link } from 'react-router-dom' const Overlay = styled.div` @@ -48,7 +48,7 @@ const Content = styled.div` const ActivityItem = styled.div` display: flex; align-items: center; - ${props => (props.disabled ? 'opacity: 0.5;' : '')} + ${(props) => (props.disabled ? 'opacity: 0.5;' : '')} > span { padding: 1rem; @@ -72,10 +72,9 @@ const StyledLink = styled(Link)` const OpenTaskActions = ({ guid, onCancel }) => { const [disabled, setDisabled] = useState(false) - const generalTranslations = useSelector(state => state.translations.yleiset) - const language = determineLanguageFromUrl(window.location) + const translations = useSelector((state) => state.translations) - const getOnClick = onClick => + const getOnClick = (onClick) => disabled ? () => {} : () => { @@ -83,7 +82,7 @@ const OpenTaskActions = ({ guid, onCancel }) => { onClick() } - const getTaskUrl = guid => { + const getTaskUrl = (guid) => { return `/guid/${guid}` } @@ -95,16 +94,12 @@ const OpenTaskActions = ({ guid, onCancel }) => { - - {getTermInLanguage(generalTranslations, 'open_task', language)} - - + {getTermInLanguage(translations, 'aukaise-tehtava')} +
- - {getTermInLanguage(generalTranslations, 'cancel', language)} - + {getTermInLanguage(translations, 'peruuta')} diff --git a/src/components/TaskActions/UserActions.js b/src/components/TaskActions/UserActions.js index 20d051f..6d9c1cf 100644 --- a/src/components/TaskActions/UserActions.js +++ b/src/components/TaskActions/UserActions.js @@ -54,7 +54,7 @@ const Content = styled.div` const ActivityItem = styled.div` display: flex; align-items: center; - ${props => (props.disabled ? 'opacity: 0.5;' : '')} + ${(props) => (props.disabled ? 'opacity: 0.5;' : '')} > span { padding: 1rem; @@ -79,35 +79,35 @@ const TaskActions = ({ }) => { const [disabled, setDisabled] = useState(false) - const userTasks = useSelector(state => state.tasks) - const generalTranslations = useSelector(state => state.translations.yleiset) - const userGroups = useSelector(state => state.user.userGroups) + const userTasks = useSelector((state) => state.tasks) + const translations = useSelector((state) => state.translations) + const userGroups = useSelector((state) => state.user.userGroups) const history = useHistory() const language = determineLanguageFromUrl(window.location) const activeTasks = Object.keys(userTasks).filter( - guid => userTasks[guid] === COMPLETION_STATUS.ACTIVE + (guid) => userTasks[guid] === COMPLETION_STATUS.ACTIVE ) const completionRequestedTasks = Object.keys(userTasks).filter( - guid => userTasks[guid] === COMPLETION_STATUS.COMPLETION_REQUESTED + (guid) => userTasks[guid] === COMPLETION_STATUS.COMPLETION_REQUESTED ) const completedTasks = Object.keys(userTasks).filter( - guid => userTasks[guid] === COMPLETION_STATUS.COMPLETED + (guid) => userTasks[guid] === COMPLETION_STATUS.COMPLETED ) - const isActive = !!activeTasks.find(taskGuid => taskGuid === guid) + const isActive = !!activeTasks.find((taskGuid) => taskGuid === guid) const isCompletionRequested = !!completionRequestedTasks.find( - taskGuid => taskGuid === guid + (taskGuid) => taskGuid === guid ) - const isCompleted = !!completedTasks.find(taskGuid => taskGuid === guid) + const isCompleted = !!completedTasks.find((taskGuid) => taskGuid === guid) - const getOnClick = onClick => + const getOnClick = (onClick) => disabled ? () => {} : () => { @@ -124,16 +124,8 @@ const TaskActions = ({ {isActive - ? getTermInLanguage( - generalTranslations, - 'delete_from_started', - language - ) - : getTermInLanguage( - generalTranslations, - 'add_as_started', - language - )} + ? getTermInLanguage(translations, 'poista-aloitetuista') + : getTermInLanguage(translations, 'lisaa-aloitetuksi')} )} @@ -141,28 +133,16 @@ const TaskActions = ({ {isCompleted || isCompletionRequested - ? getTermInLanguage( - generalTranslations, - 'delete_from_done', - language - ) - : getTermInLanguage(generalTranslations, 'add_as_done', language)} + ? getTermInLanguage(translations, 'poista-tehdyista') + : getTermInLanguage(translations, 'lisaa-tehdyksi')} {isFavourite - ? getTermInLanguage( - generalTranslations, - 'delete_from_favourites', - language - ) - : getTermInLanguage( - generalTranslations, - 'add_as_favourite', - language - )} + ? getTermInLanguage(translations, 'poista-suosikeista') + : getTermInLanguage(translations, 'lisaa-suosikiksi')} {userGroups && userGroups.length > 0 ? ( @@ -172,18 +152,12 @@ const TaskActions = ({ > - {getTermInLanguage( - generalTranslations, - 'add_to_group_members', - language - )} + {getTermInLanguage(translations, 'lisaa-ryhmalaisille')} ) : null} - - {getTermInLanguage(generalTranslations, 'cancel', language)} - + {getTermInLanguage(translations, 'peruuta')} diff --git a/src/helpers/index.js b/src/helpers/index.js index b665886..5b1c0d2 100644 --- a/src/helpers/index.js +++ b/src/helpers/index.js @@ -10,17 +10,9 @@ export const determineLanguageFromUrl = (url) => { export const getAgeGroupTitleWithoutAges = (title) => title.split('(')[0].split(':')[0].trim() -export const getTermInLanguage = (translationGroup, termKey, language) => { - const translationsInLanguage = translationGroup.find( - (translation) => translation.lang === language - ) - if (translationsInLanguage) { - const item = translationsInLanguage.items.find( - (item) => item.key === termKey - ) - if (item && item.value) { - return item.value - } +export const getTermInLanguage = (translations, termKey) => { + if (translations) { + return translations[termKey] } } @@ -134,6 +126,9 @@ export const getAgeGroupStatus = (ageGroup, userTasks) => { } export const getActivityGroupIcon = (activityGroup) => { + if (!activityGroup.logo) { + return null + } const icon = activityGroup.logo.formats ? activityGroup.logo.formats.thumbnail.url : activityGroup.logo.url @@ -163,5 +158,3 @@ export const getAgeGroupCompletion = (ageGroup, userTasks) => { completedMandatory.length > 0 ) } - -//TODO: favourites, activeTasks, completedTasks, isFavourite, isActive and isCompleted helpers diff --git a/src/views/AcceptTasks/GroupMember.js b/src/views/AcceptTasks/GroupMember.js index 50b2047..97a8d6b 100644 --- a/src/views/AcceptTasks/GroupMember.js +++ b/src/views/AcceptTasks/GroupMember.js @@ -25,11 +25,10 @@ const GroupMember = ({ member, taskGroupTasks, mandatoryTasks, - language, taskGuid, handleChange, }) => { - const generalTranslations = useSelector((state) => state.translations.yleiset) + const translations = useSelector((state) => state.translations) function isCompleted(memberTasks) { const completedTasks = Object.keys(memberTasks).filter( @@ -70,7 +69,7 @@ const GroupMember = ({ {taskGroupTasks && ( - {getTermInLanguage(generalTranslations, 'done', language)}:{' '} + {getTermInLanguage(translations, 'tehdyt')}:{' '} {getMemberCompletedTasks(member, taskGroupTasks)} /{' '} {taskGroupTasks.length} diff --git a/src/views/AcceptTasks/group.js b/src/views/AcceptTasks/group.js index 2d90db5..ddab95b 100644 --- a/src/views/AcceptTasks/group.js +++ b/src/views/AcceptTasks/group.js @@ -15,7 +15,7 @@ import { StyledAcceptIcon } from '../../components/TaskActionsIcons' import { useDispatch } from 'react-redux' import { updateGroupMemberTask } from '../../redux/actionCreators' import { acceptGroupMemberTasks } from '../../api' -import { determineLanguageFromUrl, getTermInLanguage } from '../../helpers' +import { getTermInLanguage } from '../../helpers' import GroupMember from './GroupMember' const StyledAcceptTasks = styled.div` @@ -101,10 +101,9 @@ const getInitialCheckboxData = (group) => const Group = ({ group, isLast }) => { const dispatch = useDispatch() - const language = determineLanguageFromUrl(window.location) const { taskGuid } = useParams() const groupsData = useSelector((state) => state.user.userGroups) - const generalTranslations = useSelector((state) => state.translations.yleiset) + const translations = useSelector((state) => state.translations) const itemsByGuid = useSelector((state) => state.itemsByGuid) const activityGroupById = useSelector((state) => state.activityGroups) const [memberIdList, setMemberIdList] = React.useState(initialList) @@ -117,7 +116,7 @@ const Group = ({ group, isLast }) => { [groupsData, group] ) - if (!generalTranslations || !groupsData) return null + if (!translations || !groupsData) return null const groupName = group.name const ageGroup = group.ageGroup @@ -209,7 +208,6 @@ const Group = ({ group, isLast }) => { @@ -252,11 +250,7 @@ const Group = ({ group, isLast }) => { { - - {getTermInLanguage( - generalTranslations, - 'group_leaders', - language - )} - + {getTermInLanguage(translations, 'ryhmanjohtajat')} {checkboxData.map((member) => { return renderMember(member, (member) => isGroupLeader(member)) })} - - {getTermInLanguage( - generalTranslations, - 'group_members', - language - )} - + {getTermInLanguage(translations, 'ryhmalaiset')} {checkboxData.map((member) => { return renderMember(member, (member) => !isGroupLeader(member)) @@ -300,11 +282,7 @@ const Group = ({ group, isLast }) => { - {getTermInLanguage( - generalTranslations, - 'add_to_selected', - language - )} + {getTermInLanguage(translations, 'lisaa-valituille')} ) : null} diff --git a/src/views/AcceptTasks/index.js b/src/views/AcceptTasks/index.js index 5ddc06c..136235d 100644 --- a/src/views/AcceptTasks/index.js +++ b/src/views/AcceptTasks/index.js @@ -44,24 +44,20 @@ const AcceptTasks = () => { const history = useHistory() const language = determineLanguageFromUrl(window.location) const groupsData = useSelector((state) => state.user.userGroups) - const generalTranslations = useSelector((state) => state.translations.yleiset) - if (!generalTranslations || !groupsData) return null + const translations = useSelector((state) => state.translations) + if (!translations || !groupsData) return null return (
- {getTermInLanguage( - generalTranslations, - 'add_to_group_members', - language - )} + {getTermInLanguage(translations, 'lisaa-ryhmalaisille')} history.push(`/?lang=${language}`)} />
- {getTermInLanguage(generalTranslations, 'own_groups', language)} + {getTermInLanguage(translations, 'omat-ryhmat')} {groupsData.map((group, i) => { return ( diff --git a/src/views/AgeGroup/index.js b/src/views/AgeGroup/index.js index 9514c8e..073a39d 100644 --- a/src/views/AgeGroup/index.js +++ b/src/views/AgeGroup/index.js @@ -97,12 +97,7 @@ const MainSymbol = styled.img` const AgeGroup = () => { const history = useHistory() const dispatch = useDispatch() - const groupHeadingTranslations = useSelector( - (state) => state.translations.aktiviteettipaketin_ylakasite - ) - const activityTranslations = useSelector( - (state) => state.translations.aktiviteetin_ylakasite - ) + const translations = useSelector((state) => state.translations) const { id } = useParams() const language = determineLanguageFromUrl(window.location) @@ -118,21 +113,17 @@ const AgeGroup = () => { } }, [ageGroup, dispatch]) - if (!ageGroup || !groupHeadingTranslations) { + if (!ageGroup) { return null } const ageGroupGuid = ageGroup ? ageGroup.wp_guid : 'default' const getTitle = (subtask_term) => { - let title = getTermInLanguage( - groupHeadingTranslations, - `${subtask_term}_plural`, - language - ) + let title = getTermInLanguage(translations, `${subtask_term}_monikko`) if (subtask_term === 'askel') { - title = getTermInLanguage(activityTranslations, 'paw_plural', language) + title = getTermInLanguage(translations, 'jaljet') } return title } diff --git a/src/views/AgeGroup/userAgeGroup.js b/src/views/AgeGroup/userAgeGroup.js index 7a255d4..b7f30b1 100644 --- a/src/views/AgeGroup/userAgeGroup.js +++ b/src/views/AgeGroup/userAgeGroup.js @@ -14,7 +14,7 @@ const UserAgeGroup = ({ completedGroups, unfinishedGroups, }) => { - const generalTranslations = useSelector((state) => state.translations.yleiset) + const translations = useSelector((state) => state.translations) const userTasks = useSelector((state) => state.tasks) const activityGroupById = useSelector((state) => state.activityGroups) @@ -22,7 +22,7 @@ const UserAgeGroup = ({ const status = getTaskGroupStatus( activityGroupById[activityGroup.id], userTasks, - getTermInLanguage(generalTranslations, 'done', language) + getTermInLanguage(translations, 'tehdyt') ) return (

- Tehdyt + {getTermInLanguage(translations, 'tehdyt')}

{completedGroups.length > 0 ? ( completedGroups.map((activityGroup) => { @@ -48,11 +48,16 @@ const UserAgeGroup = ({ }) ) : (

- Ei suoritettuja aktiviteettiryhmiä + + {getTermInLanguage( + translations, + 'ei-suoritettuja-aktiviteettiryhmia' + )} +

)}

- Ei vielä tehty + {getTermInLanguage(translations, 'ei-viela-tehty')}

{unfinishedGroups.length > 0 ? ( unfinishedGroups.map((activityGroup) => { @@ -60,7 +65,12 @@ const UserAgeGroup = ({ }) ) : (

- Ei suorittamattomia aktiviteettiryhmiä + + {getTermInLanguage( + translations, + 'ei-suoritettamattomia-aktiviteettiryhmia' + )} +

)} diff --git a/src/views/AgeGroups/index.js b/src/views/AgeGroups/index.js index 0c15e27..1221a65 100644 --- a/src/views/AgeGroups/index.js +++ b/src/views/AgeGroups/index.js @@ -78,7 +78,7 @@ const AgeGroups = ({ theme }) => { const user = useSelector((state) => state.user) const userTasks = useSelector((state) => state.tasks) const [activeIndex, setActiveIndex] = useState(0) - const generalTranslations = useSelector((state) => state.translations.yleiset) + const translations = useSelector((state) => state.translations) const languages = ['fi', 'sv', 'en', 'smn'] const dispatch = useDispatch() const language = determineLanguageFromUrl(window.location) @@ -152,7 +152,7 @@ const AgeGroups = ({ theme }) => { const activeAgeGroupGuid = activeAgeGroup ? activeAgeGroup.wp_guid : '' - if (itemsByGuid.length === 0 || !generalTranslations) return null + if (itemsByGuid.length === 0 || !translations) return null return ( @@ -169,8 +169,8 @@ const AgeGroups = ({ theme }) => { activityGroups={activityGroupById} language={language} user={user} + translations={translations} userTasks={userTasks} - translations={generalTranslations} localizedAgeGroups={ageGroups} /> ) diff --git a/src/views/Group/Member.js b/src/views/Group/Member.js index 58e9b7f..e1f328e 100644 --- a/src/views/Group/Member.js +++ b/src/views/Group/Member.js @@ -8,7 +8,7 @@ import { determineLanguageFromUrl, getTermInLanguage } from '../../helpers' const Member = ({ member }) => { const history = useHistory() const language = determineLanguageFromUrl(window.location) - const generalTranslations = useSelector((state) => state.translations.yleiset) + const translations = useSelector((state) => state.translations) const { groupId } = useParams() const tasks = Object.keys(member.memberTasks).filter( (guid) => @@ -18,9 +18,9 @@ const Member = ({ member }) => { const subTitle = tasks.length + ' ' + - getTermInLanguage(generalTranslations, 'activity', language) + + getTermInLanguage(translations, 'aktiviteetti') + ' ' + - getTermInLanguage(generalTranslations, 'working_on_it', language) + getTermInLanguage(translations, 'tyon-alla') const memberId = member.memberId return ( { const history = useHistory() const language = determineLanguageFromUrl(window.location) const groupsData = useSelector((state) => state.user.userGroups) - const generalTranslations = useSelector((state) => state.translations.yleiset) + const translations = useSelector((state) => state.translations) const { groupId } = useParams() - if (!generalTranslations || !groupsData) return null + if (!translations || !groupsData) return null const group = groupsData.find( (groups) => groups.id.toString() === groupId.toString() @@ -70,17 +70,13 @@ const Group = () => {

- - {getTermInLanguage(generalTranslations, 'group_leaders', language)} - + {getTermInLanguage(translations, 'ryhmanjohtajat')}

{groupLeaders.map((member) => { return })}

- - {getTermInLanguage(generalTranslations, 'group_members', language)} - + {getTermInLanguage(translations, 'ryhmalaiset')}

{groupMembers.map((member) => { return diff --git a/src/views/Login/index.js b/src/views/Login/index.js index 76daaaf..3b5119e 100644 --- a/src/views/Login/index.js +++ b/src/views/Login/index.js @@ -3,7 +3,7 @@ import styled from 'styled-components' import { useHistory, Link } from 'react-router-dom' import { useSelector } from 'react-redux' import { X } from 'react-feather' -import { determineLanguageFromUrl, getTermInLanguage } from 'helpers' +import { getTermInLanguage } from 'helpers' import { API_URL } from '../../api' import loginBg from '../../assets/images/login-bg.jpg' import logo from '../../assets/images/logo.svg' @@ -97,11 +97,10 @@ const Languages = styled.div` const Login = () => { const history = useHistory() - const language = determineLanguageFromUrl(window.location) const languages = ['fi', 'sv', 'en', 'smn'] - const generalTranslations = useSelector(state => state.translations.yleiset) + const translations = useSelector((state) => state.translations) - if (!generalTranslations) return null + if (!translations) return null return ( @@ -113,16 +112,10 @@ const Login = () => { -

- {getTermInLanguage( - generalTranslations, - 'welcome_message', - language - )} -

+

{getTermInLanguage(translations, 'tervetuloa-viesti')}

- {getTermInLanguage(generalTranslations, 'login', language)} + {getTermInLanguage(translations, 'kirjaudu-sisaan')} diff --git a/src/views/Manage/index.js b/src/views/Manage/index.js index 6591003..621fb9f 100644 --- a/src/views/Manage/index.js +++ b/src/views/Manage/index.js @@ -47,20 +47,18 @@ const Manage = () => { const history = useHistory() const language = determineLanguageFromUrl(window.location) const groupsData = useSelector((state) => state.user.userGroups) - const generalTranslations = useSelector((state) => state.translations.yleiset) - if (!generalTranslations || !groupsData) return null + const translations = useSelector((state) => state.translations) + if (!translations || !groupsData) return null return (
- - {getTermInLanguage(generalTranslations, 'manage', language)} - + {getTermInLanguage(translations, 'hallinta')} history.push(`/?lang=${language}`)} />
- {getTermInLanguage(generalTranslations, 'own_groups', language)} + {getTermInLanguage(translations, 'omat-ryhmat')} {groupsData.map((group) => { const groupName = group.name @@ -69,11 +67,7 @@ const Manage = () => { const groupMembers = group.members.length + ' ' + - getTermInLanguage( - generalTranslations, - 'from_the_scout_law', - language - ) + getTermInLanguage(translations, 'partio-jasenta') const title = '' + groupName + ' / ' + ageGroup return ( { const history = useHistory() const language = determineLanguageFromUrl(window.location) const groupsData = useSelector((state) => state.user.userGroups) - const generalTranslations = useSelector((state) => state.translations.yleiset) const itemsByGuid = useSelector((state) => state.itemsByGuid) const activityGroups = useSelector((state) => state.activityGroups) - const activityTranslations = useSelector( - (state) => state.translations.aktiviteetin_ylakasite - ) + const translations = useSelector((state) => state.translations) const { groupId } = useParams() const { memberId } = useParams() - if (!generalTranslations || !groupsData) return null + if (!groupsData) return null - if (!itemsByGuid || !activityTranslations) return null + if (!itemsByGuid || !translations) return null const group = groupsData.find( (groups) => groups.id.toString() === groupId.toString() @@ -170,20 +167,8 @@ const Member = () => { )} -

- {getTermInLanguage( - activityTranslations, - 'aktiviteetti_plural', - language - )} -

-

- {getTermInLanguage( - generalTranslations, - 'task_completion_requested', - language - )} -

+

{getTermInLanguage(translations, 'aktiviteetit')}

+

{getTermInLanguage(translations, 'odottaa-hyvaksyntaa')}

{completionRequestedTasks.map((taskGuid) => { const task = itemsByGuid[taskGuid] @@ -205,9 +190,7 @@ const Member = () => { ) })} -

- {getTermInLanguage(generalTranslations, 'working_on_it', language)} -

+

{getTermInLanguage(translations, 'tyon-alla')}

{activeTasks.map((taskGuid) => { const task = itemsByGuid[taskGuid] @@ -226,9 +209,7 @@ const Member = () => { ) })} -

- {getTermInLanguage(generalTranslations, 'completed', language)} -

+

{getTermInLanguage(translations, 'suoritetut')}

{taskGroupsWithChildTaskGroups && ( state.tasks) - const generalTranslations = useSelector((state) => state.translations.yleiset) + const translations = useSelector((state) => state.translations) const taskGroup = itemsByGuid[taskGroupGuid] if (taskGroup.item.locale !== language) return null const status = getTaskGroupStatus( taskGroup.item, userTasks, - getTermInLanguage(generalTranslations, 'done', language) + getTermInLanguage(translations, 'tehdyt') ) const icon = getActivityGroupIcon(taskGroup.item) diff --git a/src/views/Profile/index.js b/src/views/Profile/index.js index d37dc7c..1bde41a 100644 --- a/src/views/Profile/index.js +++ b/src/views/Profile/index.js @@ -133,12 +133,9 @@ const Profile = () => { ) const activityGroups = useSelector((state) => state.activityGroups) - const activityTranslations = useSelector( - (state) => state.translations.aktiviteetin_ylakasite - ) - const generalTranslations = useSelector((state) => state.translations.yleiset) + const translations = useSelector((state) => state.translations) - if (!itemsByGuid || !activityTranslations) return null + if (!itemsByGuid || !translations) return null const completedTasks = Object.keys(userTasks).filter( (guid) => userTasks[guid] === COMPLETION_STATUS.COMPLETED @@ -234,9 +231,7 @@ const Profile = () => { )} -

- {getTermInLanguage(generalTranslations, 'favourites', language)} -

+

{getTermInLanguage(translations, 'suosikit')}

{favourites && favourites @@ -261,13 +256,8 @@ const Profile = () => { })}

- {getTermInLanguage( - activityTranslations, - 'aktiviteetti_plural', - language - )}{' '} - /{' '} - {getTermInLanguage(generalTranslations, 'working_on_it', language)} + {getTermInLanguage(translations, 'aktiviteetit')} /{' '} + {getTermInLanguage(translations, 'tyon-alla')}

{ongoingTasks.map((taskGuid) => { @@ -294,9 +284,7 @@ const Profile = () => { ) })} -

- {getTermInLanguage(generalTranslations, 'completed', language)} -

+

{getTermInLanguage(translations, 'suoritetut')}

{taskGroupsWithChildTaskGroups && ( { key={ageGroup.id} ageGroup={ageGroup} language={language} - subTitle={getTermInLanguage( - generalTranslations, - 'agegroup_completed', - language - )} + subTitle={getTermInLanguage(translations, 'ikakausi-valmis')} /> ) })} diff --git a/src/views/Task/index.js b/src/views/Task/index.js index 4945a85..df64813 100644 --- a/src/views/Task/index.js +++ b/src/views/Task/index.js @@ -5,7 +5,7 @@ import { useSelector } from 'react-redux' import striptags from 'striptags' import DetailPage from 'components/DetailPage' import Actions from 'components/Actions' -import { determineLanguageFromUrl, getTermInLanguage } from 'helpers' +import { getTermInLanguage } from 'helpers' const DetailsContainer = styled.div` display: flex; @@ -62,10 +62,9 @@ const StyledActions = styled(Actions)` const Task = () => { const { id } = useParams() const history = useHistory() - const language = determineLanguageFromUrl(window.location) const task = useSelector((state) => state.itemsByGuid[id]) const user = useSelector((state) => state.user) - const generalTranslations = useSelector((state) => state.translations.yleiset) + const translations = useSelector((state) => state.translations) const favourites = useSelector((state) => state.favourites.map((favourite) => state.itemsByGuid[favourite]) @@ -81,7 +80,7 @@ const Task = () => { {task.item.ingress && ( <> - {getTermInLanguage(generalTranslations, 'task_target', language)} + {getTermInLanguage(translations, 'tavoite')}

{striptags(task.item.ingress)}

@@ -89,7 +88,7 @@ const Task = () => { {task.item.suggestions && ( <> - {getTermInLanguage(generalTranslations, 'tips', language)} + {getTermInLanguage(translations, 'toteutusvinkit')} {task.item.suggestions.map((suggestion) => (
diff --git a/src/views/TaskGroup/index.js b/src/views/TaskGroup/index.js index 2e18c95..6990506 100644 --- a/src/views/TaskGroup/index.js +++ b/src/views/TaskGroup/index.js @@ -41,7 +41,7 @@ const TaskGroup = () => { (state) => state.activityGroups[taskGroup.item.id] ) - const generalTranslations = useSelector((state) => state.translations.yleiset) + const translations = useSelector((state) => state.translations) const favourites = useSelector((state) => state.favourites) const mandatoryTasks = [] @@ -68,11 +68,7 @@ const TaskGroup = () => { guid={task.wp_guid} ageGroupGuid={taskGroup.item.age_group.wp_guid} title={task.title} - subTitle={getTermInLanguage( - generalTranslations, - `${task_status}`, - language - )} + subTitle={getTermInLanguage(translations, `${task_status}`)} language={language} icon={icon} itemType={ITEM_TYPES.TASK} @@ -101,13 +97,7 @@ const TaskGroup = () => { {activityGroup.activities.length > 0 ? ( <>

- - {getTermInLanguage( - generalTranslations, - 'mandatory_plural', - language - )} - + {getTermInLanguage(translations, 'pakolliset')}

{mandatoryTasks.length > 0 ? ( mandatoryTasks.map((task) => { @@ -117,21 +107,15 @@ const TaskGroup = () => {

{getTermInLanguage( - generalTranslations, - 'no_mandatory_tasks', + translations, + 'ei-pakollisia-aktiviteetteja', language )}

)}

- - {getTermInLanguage( - generalTranslations, - 'optional_plural', - language - )} - + {getTermInLanguage(translations, 'valinnaiset')}

{optionalTasks.length > 0 ? ( optionalTasks.map((task) => { @@ -141,9 +125,8 @@ const TaskGroup = () => {

{getTermInLanguage( - generalTranslations, - 'no_optional_tasks', - language + translations, + 'ei-valinnaisia-aktiviteetteja' )}