feat(i18n-mobile): add bilingual support (Català / Castellano) for React Native app
Run Tests on Branches / Detect Changes (push) Successful in 13s
Run Tests on Branches / Backend Tests (push) Has been skipped
Run Tests on Branches / Frontend Tests (push) Successful in 1m40s
Run Tests on Branches / Frontend Mobile Tests (push) Successful in 1m37s
Run Tests on Branches / Parapharmacy API Tests (push) Has been skipped
Run Tests on Branches / PIP Platform Tests (push) Has been skipped

Add lightweight i18n system matching the web app architecture.
Language persisted in AsyncStorage('ff-lang').

New files:
- src/i18n/locales/ca.js (~190 translation keys)
- src/i18n/locales/es.js (~190 translation keys)
- src/i18n/LanguageContext.jsx (Provider + AsyncStorage)
- src/i18n/useTranslation.js (hook)
- src/i18n/index.js (barrel export)

Modified 16 files:
- app/_layout.tsx: wrap with LanguageProvider, translate stack titles
- app/(tabs)/_layout.tsx: translate tab bar labels
- app/(tabs)/index.tsx: translate home screen
- app/(tabs)/search.tsx: translate search screen
- app/(tabs)/alerts.tsx: translate alerts screen
- app/(tabs)/profile.tsx: translate profile + add language selector (CA/ES)
- app/(tabs)/scan.tsx: translate scanner screen
- app/auth/login.tsx: translate login/register
- app/medicine/[id].tsx: translate medicine detail
- app/pharmacy/[id].tsx: translate pharmacy detail
- app/product/[source]/[id].tsx: translate product detail
- 5 components: MedicineCard, StockBadge, SearchBar, LoadingSpinner, BarcodeScanner

Language selector in Profile screen (globe icon + CA/ES toggle).
No routes changed. No API calls affected.
This commit is contained in:
Antoni Nuñez Romeu
2026-07-17 10:22:14 +02:00
parent d12c575fcf
commit ee958d4525
21 changed files with 771 additions and 198 deletions
+11 -9
View File
@@ -10,12 +10,14 @@ import { LoadingSpinner } from '../../components/LoadingSpinner';
import { useThemeContext } from '../../components/ThemeProvider';
import { spacing, borderRadius } from '../../constants/theme';
import { Pharmacy, PharmacyMedicine } from '../../types';
import { useTranslation } from '../../src/i18n';
export default function PharmacyDetailScreen() {
const { id } = useLocalSearchParams<{ id: string }>();
const router = useRouter();
const { colors } = useThemeContext();
const { isAuthenticated } = useAuth();
const { t } = useTranslation();
const [pharmacy, setPharmacy] = useState<Pharmacy | null>(null);
const [medicines, setMedicines] = useState<PharmacyMedicine[]>([]);
const [isLoading, setIsLoading] = useState(true);
@@ -77,13 +79,13 @@ export default function PharmacyDetailScreen() {
};
if (isLoading) {
return <LoadingSpinner message="Cargando farmacia..." />;
return <LoadingSpinner message={t('pharmacy.loading')} />;
}
if (!pharmacy) {
return (
<View style={[styles.errorContainer, { backgroundColor: colors.background }]}>
<Text style={[styles.errorText, { color: colors.textSecondary }]}>Farmacia no encontrada</Text>
<Text style={[styles.errorText, { color: colors.textSecondary }]}>{t('pharmacy.notFound')}</Text>
</View>
);
}
@@ -97,12 +99,12 @@ export default function PharmacyDetailScreen() {
<View style={[styles.actionsRow, { backgroundColor: colors.card, borderBottomColor: colors.separator }]}>
<TouchableOpacity style={styles.actionButton} onPress={handleCall}>
<Ionicons name="call" size={20} color={colors.primary} />
<Text style={[styles.actionText, { color: colors.primary }]}>Llamar</Text>
<Text style={[styles.actionText, { color: colors.primary }]}>{t('pharmacy.call')}</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.actionButton} onPress={handleDirections}>
<Ionicons name="navigate" size={20} color={colors.primary} />
<Text style={[styles.actionText, { color: colors.primary }]}>Cómo llegar</Text>
<Text style={[styles.actionText, { color: colors.primary }]}>{t('pharmacy.howToGet')}</Text>
</TouchableOpacity>
</View>
@@ -143,11 +145,11 @@ export default function PharmacyDetailScreen() {
<View style={styles.medicinesSection}>
<Text style={[styles.sectionTitle, { color: colors.text }]}>
Medicamentos ({medicines.length})
{t('pharmacy.medications')} ({medicines.length})
</Text>
{medicines.length === 0 ? (
<Text style={[styles.noMedicines, { color: colors.textSecondary }]}>No hay medicamentos disponibles</Text>
<Text style={[styles.noMedicines, { color: colors.textSecondary }]}>{t('pharmacy.noMedications')}</Text>
) : (
medicines.map((med) => {
const isSub = subscribedMeds.has(med.medicine_nregistro);
@@ -159,11 +161,11 @@ export default function PharmacyDetailScreen() {
>
<View style={styles.medicineInfo}>
<Text style={[styles.medicineName, { color: colors.text }]}>{med.medicine_name}</Text>
<Text style={[styles.medicineNregistro, { color: colors.textSecondary }]}>Reg: {med.medicine_nregistro}</Text>
<Text style={[styles.medicineNregistro, { color: colors.textSecondary }]}>{t('pharmacy.reg')}{med.medicine_nregistro}</Text>
</View>
<View style={styles.medicineStock}>
<Text style={[styles.price, { color: colors.primary }]}>{med.price.toFixed(2)} €</Text>
<Text style={[styles.stock, { color: colors.textSecondary }]}>Stock: {med.stock}</Text>
<Text style={[styles.stock, { color: colors.textSecondary }]}>{t('pharmacy.stock')}{med.stock}</Text>
</View>
</TouchableOpacity>
{isAuthenticated && (
@@ -177,7 +179,7 @@ export default function PharmacyDetailScreen() {
color={isSub ? '#fff' : colors.textSecondary}
/>
<Text style={[styles.bellText, { color: isSub ? '#fff' : colors.textSecondary }]}>
{isSub ? 'Notificaciones activas' : 'Notificarme cuando haya stock'}
{isSub ? t('pharmacy.notificationsActive') : t('pharmacy.notifyWhenAvailable')}
</Text>
</TouchableOpacity>
)}