Set once (GET/PUT /api/identity, venue.name + venue.identity); every colour field offers the venue's colours first (VenueColoursProvider in @xenia/ui); signage screens get the identity and the venue's time zone with their venue and are told on a change; logos are protected in the media library; wifiQr() for the join-the-network code. Plan 6R.14, F-111. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
54 lines
1.9 KiB
JavaScript
54 lines
1.9 KiB
JavaScript
import { useContext, useMemo } from 'react'
|
|
import { useTranslation } from 'react-i18next'
|
|
import { FormatContext } from './context.js'
|
|
import { SUPPORTED_LANGUAGES } from './locale.js'
|
|
|
|
/** formatTime, formatDateTime, formatDate, formatRelative, formatMoney, formatNumber, formatPercent, venueToday… */
|
|
export function useFormat() {
|
|
const ctx = useContext(FormatContext)
|
|
if (!ctx) throw new Error('useFormat() needs an <I18nProvider> above it')
|
|
return ctx
|
|
}
|
|
|
|
/** { language, languages, changeLanguage } for language pickers (screen only; see setUserLanguage to save). */
|
|
export function useLanguage() {
|
|
const { i18n } = useTranslation()
|
|
return {
|
|
language: i18n.resolvedLanguage || i18n.language,
|
|
languages: SUPPORTED_LANGUAGES,
|
|
changeLanguage: lng => i18n.changeLanguage(lng),
|
|
}
|
|
}
|
|
|
|
/**
|
|
* The @xenia/ui components' own texts, translated (common:ui.*). Use once at the root:
|
|
* <UiLabelsProvider labels={useUiLabels()}>
|
|
*/
|
|
export function useUiLabels() {
|
|
const { t, i18n } = useTranslation('common')
|
|
const language = i18n.resolvedLanguage || i18n.language
|
|
return useMemo(() => ({
|
|
close: t('ui.close'),
|
|
cancel: t('ui.cancel'),
|
|
dismiss: t('ui.dismiss'),
|
|
loading: t('ui.loading'),
|
|
moreInfo: t('ui.moreInfo'),
|
|
notifications: t('ui.notifications'),
|
|
backspace: t('ui.backspace'),
|
|
decrease: t('ui.decrease'),
|
|
increase: t('ui.increase'),
|
|
submit: t('ui.submit'),
|
|
search: t('ui.search'),
|
|
clear: t('ui.clear'),
|
|
all: t('ui.all'),
|
|
noOptions: t('ui.noOptions'),
|
|
selected: count => t('ui.selected', { count }),
|
|
pinProgress: (count, total) => t('ui.pinProgress', { count, total }),
|
|
colourOwn: t('ui.colourOwn'),
|
|
venueColours: t('ui.venueColours'),
|
|
colourCode: t('ui.colourCode'),
|
|
opacity: t('ui.opacity'),
|
|
noIcon: t('ui.noIcon'),
|
|
}), [t, language]) // eslint-disable-line react-hooks/exhaustive-deps
|
|
}
|