Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TFunction external use broken without using interface (#1186)
* Make external use of TFunction type behave * Comment this pattern applies to NamespacesConsumer i18next/react-i18next#693
- Loading branch information
Showing
2 changed files
with
22 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import i18next from 'i18next'; | ||
|
||
/** | ||
* Use of the exported TFunction in external utility methods such as | ||
* NamespaceConsumer children t | ||
*/ | ||
function resolveText(t: i18next.TFunction, keyOrText?: string): undefined | string { | ||
if (keyOrText && keyOrText.startsWith(':')) { | ||
return t(keyOrText.substring(1, keyOrText.length)); | ||
} else { | ||
return keyOrText; | ||
} | ||
} |