Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 6 additions & 3 deletions app/(drawer)/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { SpatialNavigationFocusableView, SpatialNavigationRoot, SpatialNavigatio
import { Direction } from '@bam.tech/lrud';
import { scaledPixels } from '@/hooks/useScale';
import { LinearGradient } from 'expo-linear-gradient';
import { useTranslation } from 'react-i18next';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please commit the package.json for the i18 npm package.



interface CardData {
Expand All @@ -30,6 +31,8 @@ export default function IndexScreen() {

const focusedItem = useMemo(() => moviesData[focusedIndex], [focusedIndex]);

const { t } = useTranslation();

const renderHeader = useCallback(() => (
<View style={styles.header}>
<Image
Expand Down Expand Up @@ -116,9 +119,9 @@ export default function IndexScreen() {
<SpatialNavigationScrollView
offsetFromStart={scaledPixels(60)}
style={styles.scrollContent}>
{renderScrollableRow("Trending Movies", trendingRef)}
{renderScrollableRow("Classics", classicsRef)}
{renderScrollableRow("Hip and Modern", hipAndModernRef)}
{renderScrollableRow(t('categories.trending_movies'), trendingRef)}
{renderScrollableRow(t('categories.classics'), classicsRef)}
{renderScrollableRow(t('categories.hip_and_modern'), hipAndModernRef)}
</SpatialNavigationScrollView>
</View>
</SpatialNavigationRoot>
Expand Down
4 changes: 4 additions & 0 deletions app/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { useCallback, useEffect } from 'react';

import { MenuProvider } from '../components/MenuContext';
import { GoBackConfiguration } from './remote-control/GoBackConfiguration';
import { I18nextProvider } from 'react-i18next';
import i18n from '@/components/i18n'; // Initialize i18n
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: please remove the comment


import "./configureRemoteControl"

Expand Down Expand Up @@ -33,6 +35,7 @@ export default function RootLayout() {

return (
<MenuProvider>
<I18nextProvider i18n={i18n}>
<ThemeProvider value={DarkTheme}>
<GoBackConfiguration />
<Stack>
Expand All @@ -42,6 +45,7 @@ export default function RootLayout() {
<Stack.Screen name="player" />
</Stack>
</ThemeProvider>
</I18nextProvider>
</MenuProvider>
);
}
33 changes: 29 additions & 4 deletions components/CustomDrawerContent.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,44 @@
import { scaledPixels } from "@/hooks/useScale";
import { DrawerContentScrollView } from "@react-navigation/drawer";
import { View, StyleSheet, Image, Platform, Text } from "react-native";
import { Picker } from '@react-native-picker/picker';
import { DefaultFocus, SpatialNavigationFocusableView, SpatialNavigationRoot } from "react-tv-space-navigation";
import { useRouter } from "expo-router";
import { useMenuContext } from "@/components/MenuContext";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import { useTranslation } from 'react-i18next';

export default function CustomDrawerContent(props: any) {
const router = useRouter();
const { isOpen: isMenuOpen, toggleMenu } = useMenuContext();
const styles = useDrawerStyles();
const {top, right, bottom, left} = useSafeAreaInsets();
const { t, i18n } = useTranslation();
const drawerItems = [
{ name: '/', label: 'Home' },
{ name: 'explore', label: 'Explore'},
{ name: 'tv', label: 'TV'},
{ name: '/', label: t('drawer.index') },
{ name: 'explore', label: t('drawer.explore')},
{ name: 'tv', label: t('drawer.tv')},
];

const changeLanguage = (language: string) => {
i18n.changeLanguage(language);
};
return (
<SpatialNavigationRoot isActive={isMenuOpen}>
<DrawerContentScrollView {...props} style={styles.container} scrollEnabled={false}>
<View style={styles.header}>
<Image source={require('@/assets/images/logo.png')} style={styles.profilePic} />
<Text style={styles.userName}>Pioneer Tom</Text>
<Text style={styles.switchAccount}>Switch account</Text>
<Text style={styles.switchLanguage}>Switch Language</Text>
<Picker
selectedValue={i18n.language}
onValueChange={(itemValue: string) => changeLanguage(itemValue)}
style={styles.picker}
>
<Picker.Item label="English" value="en" />
<Picker.Item label="Français" value="fr" />
<Picker.Item label="Español" value="es" />
</Picker>
</View>
{drawerItems.map((item, index) => (
index === 0 ? (
Expand Down Expand Up @@ -108,5 +123,15 @@ const useDrawerStyles = function () {
menuTextFocused: {
color: 'black',
},
switchLanguage: {
paddingTop: scaledPixels(10),
paddingBottom: scaledPixels(6),
color: 'white',
fontSize: scaledPixels(26),
},
picker: {
height: 40,
width: '60%'
}
});
};
13 changes: 13 additions & 0 deletions components/i18n/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

{
"drawer": {
"index": "Home",
"explore": "Explore",
"tv": "TV"
},
"categories": {
"trending_movies": "Trending Movies",
"classics": "Classics",
"hip_and_modern": "Hip and Modern"
}
}
12 changes: 12 additions & 0 deletions components/i18n/es.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"drawer": {
"index": "Inicio",
"explore": "Explorar",
"tv": "Televisión"
},
"categories": {
"trending_movies": "Películas de Tendencia",
"classics": "Clásicos",
"hip_and_modern": "Moderno y de moda"
}
}
12 changes: 12 additions & 0 deletions components/i18n/fr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"drawer": {
"index": "Accueil",
"explore": "Explorer",
"tv": "Télévision"
},
"categories": {
"trending_movies": "Films Tendance",
"classics": "Classiques",
"hip_and_modern": "À la mode et moderne"
}
}
34 changes: 34 additions & 0 deletions components/i18n/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import i18next from 'i18next';
import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
import LanguageDetector from 'i18next-browser-languagedetector';

// Import translation files
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: remove comment

import en from './en.json';
import es from './es.json';
import fr from './fr.json';

i18next
.use(initReactI18next)
.use(LanguageDetector)
.init({
compatibilityJSON: 'v3', // If you face any version-related warnings
resources: {
en: {
translation: en,
},
es: {
translation: es,
},
fr: {
translation: fr,
},
},
lng: 'en', // Default language
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: same as above. Please remove comments

fallbackLng: 'en', // Fallback language in case of missing translations
interpolation: {
escapeValue: false, // React already escapes values, so this is safe
},
});

export default i18n;