Skip to content

Commit

Permalink
refactor(react-sdk): pass translations from SDK and not from i18n pac…
Browse files Browse the repository at this point in the history
…kage (#852)

This PR is over #847
  • Loading branch information
khushal87 authored Jul 25, 2023
1 parent 0ecc931 commit f9b2fd7
Show file tree
Hide file tree
Showing 15 changed files with 53 additions and 41 deletions.
1 change: 0 additions & 1 deletion packages/i18n/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './src/StreamI18n';
export * from './src/translations';
export * from './src/types';
export * from './src/utils';
6 changes: 1 addition & 5 deletions packages/i18n/src/StreamI18n.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import i18next from 'i18next';
import defaultTranslations from './translations';
import { mapToRegistry } from './utils';
import {
TranslationLanguage,
Expand All @@ -15,10 +14,7 @@ const DEFAULT_CONFIG = {
currentLanguage: DEFAULT_LANGUAGE,
};

const DEFAULT_TRANSLATIONS_REGISTRY = mapToRegistry(
defaultTranslations,
DEFAULT_NAMESPACE,
);
const DEFAULT_TRANSLATIONS_REGISTRY = mapToRegistry({}, DEFAULT_NAMESPACE);

export const defaultTranslationFunction = (key: string) => key;

Expand Down
4 changes: 0 additions & 4 deletions packages/i18n/src/translations/index.ts

This file was deleted.

8 changes: 2 additions & 6 deletions packages/i18n/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import defaultTranslations from './translations';

export type TranslationLanguage = 'en' | 'es' | string;
export type TranslationLanguage = 'en' | string;

export type Namespace = string;

export type TranslationSheet =
| typeof defaultTranslations.en
| Record<string, string>;
export type TranslationSheet = Record<string, string>;

export type TranslationsForLanguage = Record<Namespace, TranslationSheet>;

Expand Down
12 changes: 6 additions & 6 deletions packages/react-bindings/src/contexts/StreamI18nContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ const StreamI18nContext = createContext<StreamI18nContextValue>({
t: defaultTranslationFunction,
});

type CreateI18nParams = {
i18nInstance?: StreamI18n;
language?: string;
translationsOverrides?: TranslationsMap;
};

export type StreamI18nProviderProps = CreateI18nParams;

export const StreamI18nProvider = ({
Expand All @@ -35,12 +41,6 @@ export const StreamI18nProvider = ({
);
};

type CreateI18nParams = {
i18nInstance?: StreamI18n;
language?: string;
translationsOverrides?: TranslationsMap;
};

export const useCreateI18n = ({
i18nInstance,
language,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export type StreamVideoProps = StreamI18nProviderProps & {
* @param PropsWithChildren<StreamVideoProps>
* @category Client State
*/
export const StreamVideo = ({
export const StreamVideoProvider = ({
children,
client,
i18nInstance,
Expand Down
31 changes: 18 additions & 13 deletions packages/react-native-sdk/src/providers/StreamVideo.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {
StreamVideo as StreamVideoProvider,
StreamVideoProvider,
StreamI18nProvider,
StreamVideoProps,
StreamI18nProviderProps,
} from '@stream-io/video-react-bindings';
import React, { PropsWithChildren, useEffect } from 'react';
import { StreamVideoStoreProvider } from '../contexts/StreamVideoContext';
Expand All @@ -15,7 +17,9 @@ import { usePushRegisterEffect } from '../hooks';
*
* @category Client State
*/
export const StreamVideo = (props: PropsWithChildren<StreamVideoProps>) => {
export const StreamVideo = (
props: PropsWithChildren<StreamVideoProps & StreamI18nProviderProps>,
) => {
const { client, children, translationsOverrides, i18nInstance, language } =
props;

Expand All @@ -41,17 +45,18 @@ export const StreamVideo = (props: PropsWithChildren<StreamVideoProps>) => {
}, [client]);

return (
<StreamVideoProvider
client={client}
translationsOverrides={translationsOverrides}
i18nInstance={i18nInstance}
language={language}
>
<StreamVideoStoreProvider>
<MediaDevices />
<PushRegister />
{children}
</StreamVideoStoreProvider>
<StreamVideoProvider client={client}>
<StreamI18nProvider
language={language}
translationsOverrides={translationsOverrides}
i18nInstance={i18nInstance}
>
<StreamVideoStoreProvider>
<MediaDevices />
<PushRegister />
{children}
</StreamVideoStoreProvider>
</StreamI18nProvider>
</StreamVideoProvider>
);
};
Expand Down
1 change: 1 addition & 0 deletions packages/react-sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export * from './src/core';

export * from './src/components';
export * from './src/types';
export * from './src/translations';
export {
useHorizontalScrollPosition,
useVerticalScrollPosition,
Expand Down
12 changes: 12 additions & 0 deletions packages/react-sdk/src/core/components/StreamVideo/StreamVideo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {
StreamVideoProvider,
StreamVideoProps,
} from '@stream-io/video-react-bindings';
import { PropsWithChildren } from 'react';
import { translations } from '../../../translations';

export const StreamVideo = (props: PropsWithChildren<StreamVideoProps>) => {
return (
<StreamVideoProvider translationsOverrides={translations} {...props} />
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './StreamVideo';
1 change: 1 addition & 0 deletions packages/react-sdk/src/core/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from './Audio';
export * from './ParticipantView';
export * from './StreamCall';
export * from './StreamVideo';

export { Video } from './Video';
export type { BaseVideoProps, VideoProps } from './Video';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"Waiting for recording to start...": "Waiting for recording to start...",
"Record call": "Record call",
"Reactions": "Reactions",
"You can now share your screen.": "You can now share your screen.",
"You can now share your screen.": "You can now share your screen.",
"Awaiting for an approval to share screen.": "Awaiting for an approval to share screen.",
"You can no longer share your screen.": "You can no longer share your screen.",
"Share screen": "Share screen",
Expand Down
3 changes: 3 additions & 0 deletions packages/react-sdk/src/translations/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import en from './en.json';

export const translations = { en };
4 changes: 2 additions & 2 deletions sample-apps/react/react-dogfood/pages/join/[callId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from '../../lib/getServerSideCredentialsProps';
import { useGleap } from '../../hooks/useGleap';
import { useSettings } from '../../context/SettingsContext';
import translations from '../../translations';
import appTranslations from '../../translations';
import {
DeviceSettingsCaptor,
getDeviceSettings,
Expand Down Expand Up @@ -108,7 +108,7 @@ const CallRoom = (props: ServerSideCredentialsProps) => {
<StreamVideo
client={client}
language={language}
translationsOverrides={translations}
translationsOverrides={appTranslations}
>
<StreamCall
call={call}
Expand Down
6 changes: 4 additions & 2 deletions sample-apps/react/react-dogfood/translations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ import de from './de.json';
import en from './en.json';
import es from './es.json';

const translations = { de, en, es };
export default translations;
import { translations as sdkTranslations } from '@stream-io/video-react-sdk';

const appTranslations = { de, en: { ...sdkTranslations.en, ...en }, es };
export default appTranslations;

0 comments on commit f9b2fd7

Please sign in to comment.