diff --git a/packages/common/src/hooks/useObjectTranslation.ts b/packages/common/src/hooks/useObjectTranslation.ts index d4af16429..844136468 100644 --- a/packages/common/src/hooks/useObjectTranslation.ts +++ b/packages/common/src/hooks/useObjectTranslation.ts @@ -1,5 +1,5 @@ import { TranslationObject } from '@monkvision/types'; -import { useTranslation } from 'react-i18next'; +import { useTranslation, UseTranslationOptions } from 'react-i18next'; import { useCallback } from 'react'; import { getLanguage } from '../i18n'; @@ -17,8 +17,11 @@ export interface UseObjectTranslationResult { /** * Custom hook used to get a translation function tObj that translates TranslationObjects. */ -export function useObjectTranslation(): UseObjectTranslationResult { - const { i18n } = useTranslation(); +export function useObjectTranslation( + ns?: string, + options?: UseTranslationOptions, +): UseObjectTranslationResult { + const { i18n } = useTranslation(ns, options); const tObj = useCallback( (obj: TranslationObject) => { return obj[getLanguage(i18n.language)] ?? 'translation-not-found'; diff --git a/packages/common/test/hooks/useObjectTranslation.test.ts b/packages/common/test/hooks/useObjectTranslation.test.ts index cd9ec6e35..0da3eb68d 100644 --- a/packages/common/test/hooks/useObjectTranslation.test.ts +++ b/packages/common/test/hooks/useObjectTranslation.test.ts @@ -29,4 +29,13 @@ describe('useObjectTranslation hook', () => { expect(typeof result.current.tObj({} as TranslationObject)).toBe('string'); unmount(); }); + + it('should pass the options parameters to the useTranslation hook', () => { + const ns = 'test-ns'; + const options = { lng: 'nl' }; + const { unmount } = renderHook(() => useObjectTranslation(ns, options)); + expect(useTranslation).toHaveBeenCalledWith(ns, options); + + unmount(); + }); });