-
Notifications
You must be signed in to change notification settings - Fork 37
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 #278 from masnormen/feat/aliased-t-function
feat: support aliased `t` functions from useTranslation hooks
- Loading branch information
Showing
12 changed files
with
135 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,32 @@ | ||
import { useMyTranslation, useOtherTranslation } from './i18n'; | ||
import { useThirdPartyTranslation } from 'third-party-module'; | ||
import * as I18Next from 'third-party-module' | ||
|
||
export function MyComponent0() { | ||
const [_] = useMyTranslation('ns0'); | ||
return <p>{_('key0')}{_('key1')}</p> | ||
} | ||
|
||
export function MyComponent1() { | ||
const [iceT] = useOtherTranslation(['ns1', 'noob']); | ||
return <p>{iceT('key in ns1')}</p> | ||
} | ||
|
||
export function MyComponent2() { | ||
const { translate } = I18Next.useThirdPartyTranslation('ns2'); | ||
someFunc(translate); | ||
return <p>{translate('key in ns2')}</p> | ||
} | ||
|
||
export function MyComponent3() { | ||
const foo = 'noob'; | ||
// i18next-extract-mark-ns-next-line ns3 | ||
const [myT] = useThirdPartyTranslation(foo); | ||
return <p>{myT('key in ns3')}</p> | ||
} | ||
|
||
export function MyComponent4() { | ||
const { translate: aliasedTranslate } = I18Next.useThirdPartyTranslation('ns4'); | ||
someFunc(aliasedTranslate); | ||
return <p>{aliasedTranslate('key in ns4')}</p> | ||
} |
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 @@ | ||
{ | ||
"description": "test custom useTranslation hooks giving custom instance name to t function", | ||
"pluginOptions": { | ||
"customUseTranslationHooks": [ | ||
["./tests/__fixtures__/testCustomHook/i18n", "useMyTranslation"], | ||
["./tests/__fixtures__/testCustomHook/i18n", "useOtherTranslation"], | ||
["third-party-module", "useThirdPartyTranslation"] | ||
], | ||
"tFunctionNames": ["_", "iceT", "myT", "translate"] | ||
}, | ||
"expectValues": [ | ||
[{ "key0": "", "key1": "" }, { "ns": "ns0" }], | ||
[{ "key in ns1": "" }, { "ns": "ns1" }], | ||
[{ "key in ns2": "" }, { "ns": "ns2" }], | ||
[{ "key in ns3": "" }, { "ns": "ns3" }], | ||
[{ "key in ns4": "" }, { "ns": "ns4" }] | ||
] | ||
} |
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