-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add useTolgeeSSR for compatibility with react 18 and next.js 13 (…
- Loading branch information
Showing
29 changed files
with
1,913 additions
and
1,515 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
cypress/screenshots | ||
cypress/videos | ||
cypress/downloads | ||
node_modules | ||
testapps/dist | ||
extension |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { | ||
getTranslateProps, | ||
TolgeeInstance, | ||
TolgeeStaticData, | ||
} from '@tolgee/web'; | ||
import { useEffect, useMemo, useState } from 'react'; | ||
|
||
function getTolgeeWithDeactivatedWrapper( | ||
tolgee: TolgeeInstance | ||
): TolgeeInstance { | ||
return { | ||
...tolgee, | ||
t(...args) { | ||
// @ts-ignore | ||
const props = getTranslateProps(...args); | ||
return tolgee.t({ ...props, noWrap: true }); | ||
}, | ||
}; | ||
} | ||
|
||
export function useTolgeeSSR( | ||
tolgeeInstance: TolgeeInstance, | ||
locale?: string, | ||
staticData?: TolgeeStaticData | undefined | ||
) { | ||
const initialInstance = useMemo( | ||
() => getTolgeeWithDeactivatedWrapper(tolgeeInstance), | ||
[] | ||
); | ||
|
||
const [tolgee, setTolgee] = useState(initialInstance); | ||
|
||
useEffect(() => { | ||
setTolgee(tolgeeInstance); | ||
}, []); | ||
|
||
useMemo(() => { | ||
// we have to prepare tolgee before rendering children | ||
// so translations are available right away | ||
// events emitting must be off, to not trigger re-render while rendering | ||
tolgee.setEmmiterActive(false); | ||
tolgee.addStaticData(staticData); | ||
tolgee.changeLanguage(locale!); | ||
tolgee.setEmmiterActive(true); | ||
}, [locale, staticData, tolgee]); | ||
|
||
return tolgee; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.