mirror of
https://github.com/UniversityOfHelsinkiCS/oodikone.git
synced 2026-10-12 19:03:39 +03:00
[Language hook] allow string as input
Streamlines many Name | string types
This commit is contained in:
committed by
Aaro Koivukangas
parent
96f8b43732
commit
9c40be64e8
@@ -31,10 +31,9 @@ export const useLanguage = () => {
|
||||
const [changeLanguage] = useModifyLanguageMutation()
|
||||
|
||||
const getTextIn = useCallback(
|
||||
(text: Name | null | undefined, lang?: string): string | null | undefined => {
|
||||
if (text == null || Object.values(text).length === 0) {
|
||||
return null
|
||||
}
|
||||
(text: Name | null | undefined | string, lang?: string): string | null | undefined => {
|
||||
if (text == null || Object.values(text).length === 0) return null
|
||||
if (typeof text === 'string') return text
|
||||
const languageToUse = lang ?? state
|
||||
return text[languageToUse] ?? text.fi ?? text.en ?? text.sv ?? Object.values(text)[0]
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user