Files
petfeed/mobile/app/onboarding/_layout.tsx
T
admin 462f295caa feat(mobile): add German/English i18n across the whole app
- i18next + react-i18next + expo-localization: device-locale detection,
  an MMKV-persisted DE/EN/Automatisch override (mirrors web's cookie-only
  locale, no backend field needed), and a language switcher on the Pets
  tab next to the theme toggle
- every screen and shared component converted from hardcoded German
  strings to translation keys; de.json/en.json kept in exact key-parity
  (218 keys each, verified programmatically)
- backend: src/trpc/init.ts now accepts an x-locale header as a fallback
  locale source (cookie still wins, web unaffected) since mobile has no
  cookie jar to set NEXT_LOCALE in; mobile's tRPC client sends the
  current language on every request
- fixes a latent bug: species/breed pickers were hardcoded to locale
  "de" while every other pet query resolved names via ctx.locale's
  default (English, since mobile never sent a locale cookie) — both now
  use the same current-language value
- expo-localization is a new native module (config plugin) and needs a
  native rebuild to actually link; deviceLocale() falls back to English
  instead of crashing when it isn't linked yet, so the app stays usable
  before that rebuild happens

Needs a NAS deploy (src/trpc/init.ts is shared backend code) before the
x-locale fallback and the species/breed locale fix take effect for mobile.
2026-09-06 17:31:41 +02:00

43 lines
1.5 KiB
TypeScript

import { Pressable } from "react-native";
import { Stack, useRouter } from "expo-router";
import { X } from "lucide-react-native";
import { useTranslation } from "react-i18next";
import { useTheme } from "../../src/context/ThemeContext";
import { fontFamily } from "../../src/theme/tokens";
/**
* Always closes back to /(app), never router.back() — this screen is
* reached two ways: OnboardingRedirect's replace() (no meaningful back
* history) for a zero-pet owner, and the Pets tab's "+" button (real back
* history) for an existing owner adding another pet. A zero-pet owner who
* closes gets bounced right back here by OnboardingRedirect — that's
* correct, not a bug: they can't use the app without a first pet, but they
* get an obvious "why am I back here" instead of a dead-end screen with no
* way to leave at all.
*/
function CloseButton() {
const router = useRouter();
const { colors } = useTheme();
return (
<Pressable onPress={() => router.replace("/(app)")} hitSlop={12} style={{ marginLeft: 8 }}>
<X color={colors.ink} size={22} />
</Pressable>
);
}
export default function OnboardingLayout() {
const { t } = useTranslation();
const { colors } = useTheme();
return (
<Stack
screenOptions={{
headerStyle: { backgroundColor: colors.pureWhite },
headerTitleStyle: { fontFamily: fontFamily.bold, color: colors.ink },
headerLeft: () => <CloseButton />,
}}
>
<Stack.Screen name="pet" options={{ title: t("onboarding.addPetTitle") }} />
</Stack>
);
}