-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from sparcs-kaist/feat/migration-preparation
Prepare for migration
- Loading branch information
Showing
6 changed files
with
56 additions
and
5 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
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,18 @@ | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
/** | ||
* Custom hook that returns a function for translating strings based on the current language. | ||
* | ||
* @returns {function} A function that takes an object and a key and returns the translated string. | ||
* @example const translate = useTranslatedString(); | ||
* const translatedString = translate(review.lecture, 'title'); | ||
*/ | ||
export const useTranslatedString = () => { | ||
const { i18n } = useTranslation(); | ||
|
||
return <T,>(obj: T, key: keyof T extends string ? keyof T : never) => { | ||
const translatedValue = obj[(i18n.language.startsWith('ko') ? key : `${key}_en`) as keyof T]; | ||
|
||
return typeof translatedValue === 'string' ? translatedValue : null; | ||
}; | ||
}; |
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