Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#277 Use i18next-parser #289

Merged
merged 9 commits into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions next/components/atoms/ShareButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import LinkedInIcon from '@/assets/icons/social-platforms/linkedin.svg'
import TwitterIcon from '@/assets/icons/social-platforms/twitter.svg'
import WhatsAppIcon from '@/assets/icons/social-platforms/whatsapp.svg'
import Link from '@/components/atoms/Link'
import { capitalizeFirstLetter } from '@/utils/capitalize'
import { getNextUrl } from '@/utils/getNextUrl'

interface ShareButtonProps {
Expand Down Expand Up @@ -50,6 +49,14 @@ const ShareButton = ({ slug, platform, title, className }: ShareButtonProps) =>
linkedin: LinkedInIcon,
}[platform]

const translationMap = {
facebook: t('common.shareOn.facebook'),
email: t('common.shareOn.email'),
twitter: t('common.shareOn.twitter'),
whatsapp: t('common.shareOn.whatsapp'),
linkedin: t('common.shareOn.linkedin'),
} satisfies Record<Platform, string>

return (
<Link
href={encodedHref}
Expand All @@ -62,7 +69,7 @@ const ShareButton = ({ slug, platform, title, className }: ShareButtonProps) =>
window.open(encodedHref, t('common.share'), 'width=600,height=600')
event.preventDefault()
}}
aria-label={t(`common.shareOn${capitalizeFirstLetter(platform)}`)}
aria-label={translationMap[platform]}
>
<span className={cx(className)}>
<ShareIcon {...size} className="dw-[32]" />
Expand Down
2 changes: 1 addition & 1 deletion next/components/molecules/CookieConsent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ interface PanelProps {
}

const Panel = ({ title, content, value, onValueChange, isOpen, setPanel }: PanelProps) => {
const { t } = useTranslation(['common'])
const { t } = useTranslation()
return (
<>
<div
Expand Down
5 changes: 4 additions & 1 deletion next/components/molecules/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ type FeaturePoint =

interface Gallery {
key: string
localisedName: string
icon: FC<SVGProps<SVGSVGElement>>
hoverIcon: FC<SVGProps<SVGSVGElement>>
coordinates: [number, number]
Expand Down Expand Up @@ -139,6 +140,7 @@ const Map = ({ mapboxAccessToken }: MapProps) => {
const galleries: Gallery[] = [
{
key: 'mirbach',
localisedName: t('map.palaceTitle.mirbach'),
icon: GmbLogoIcon,
hoverIcon: MirbachovPalacIcon,
coordinates: [17.107_771, 48.144_776],
Expand Down Expand Up @@ -169,6 +171,7 @@ const Map = ({ mapboxAccessToken }: MapProps) => {
},
{
key: 'palffy',
localisedName: t('map.palaceTitle.palffy'),
icon: GmbLogoIcon,
hoverIcon: PalffyhoPalacIcon,
coordinates: [17.107_084, 48.142_137],
Expand Down Expand Up @@ -446,7 +449,7 @@ const Map = ({ mapboxAccessToken }: MapProps) => {
className="flex items-center gap-2 text-md hover:underline"
onClick={(e) => onGalleryClick(gallery, e)}
>
<span>{t(`map.${gallery.key}Palace`)}</span>
<span>{gallery.localisedName}</span>
</button>
))}
</>
Expand Down
12 changes: 12 additions & 0 deletions next/i18next-parser.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const { i18n, reloadOnPrerender } = require('./next-i18next.config')

module.exports = {
locales: i18n.locales,
input: '(assets|components|pages|services|styles|types|utils)/**/*.{tsx,ts}',
output: './public/locales/$LOCALE/$NAMESPACE.json',
// if set to true preserves old values in a separate json file
createOldCatalogs: false,
sort: true,
// makes the translation json file flat
keySeparator: false,
}
4 changes: 1 addition & 3 deletions next/next-i18next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ module.exports = {
defaultLocale: 'sk',
locales: ['en', 'sk'],
localeDetection: false,
returnNull: false,
},
serializeConfig: false,
defaultNS: ['translation'], // Changed to match the namespace used by i18next-parser
reloadOnPrerender: process.env.NODE_ENV === 'development',
localePath: path.resolve('./public/locales'),
}
Loading