-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support Effect and async function as instance (#79)
- Loading branch information
1 parent
f8b24f4
commit 6989158
Showing
12 changed files
with
275 additions
and
122 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@withease/i18next': minor | ||
--- | ||
|
||
Allow to pass async `instance` to integration |
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,15 @@ | ||
# `changeLanguageFx` | ||
|
||
An [_Effect_](https://effector.dev/en/api/effector/effect/) that can be called with a language code to change the current language. | ||
|
||
```ts | ||
const { changeLanguageFx } = createI18nextIntegration({ | ||
/* ... */ | ||
}); | ||
|
||
sample({ | ||
clock: someButtonClicked, | ||
fn: () => 'en', | ||
target: changeLanguageFx, | ||
}); | ||
``` |
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,3 @@ | ||
# `$instance` | ||
|
||
The instance of i18next that is used by the integration can be accessed via the `$instance` [_Store_](https://effector.dev/docs/api/effector/store). |
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,9 @@ | ||
# `$isReady` | ||
|
||
A [_Store_](https://effector.dev/docs/api/effector/store) containing a boolean value that indicates whether the integration is ready to use. | ||
|
||
```ts | ||
const { $isReady } = createI18nextIntegration({ | ||
/* ... */ | ||
}); | ||
``` |
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,9 @@ | ||
# `$language` <Badge text="since v23.2.0" /> | ||
|
||
A [_Store_](https://effector.dev/docs/api/effector/store) containing the current language. | ||
|
||
```ts | ||
const { $language } = createI18nextIntegration({ | ||
/* ... */ | ||
}); | ||
``` |
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 @@ | ||
# `reporting` | ||
|
||
An object with the following fields: | ||
|
||
- `missingKey`, [_Event_](https://effector.dev/en/api/effector/event/) will be triggered when a key is missing in the translation resources, requires [adding `saveMissing` option to the i18next instance](https://www.i18next.com/overview/api#onmissingkey). | ||
|
||
```ts | ||
const { reporting } = createI18nextIntegration({ | ||
/* ... */ | ||
}); | ||
|
||
sample({ clock: reporting.missingKey, target: sendWarningToSentry }); | ||
``` |
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,29 @@ | ||
# `$t` | ||
|
||
A [_Store_](https://effector.dev/docs/api/effector/store) containing a [translation function](https://www.i18next.com/overview/api#t), can be used anywhere in your app. | ||
|
||
```ts | ||
const { $t } = createI18nextIntegration({ | ||
/* ... */ | ||
}); | ||
|
||
const $someTranslatedString = $t.map((t) => t('cityPois.buttonText')); | ||
``` | ||
|
||
The second argument is an optional object with options for the translation function. | ||
|
||
```ts | ||
const $city = createStore({ name: 'Moscow' }); | ||
|
||
const { $t } = createI18nextIntegration({ | ||
/* ... */ | ||
}); | ||
|
||
const $someTranslatedString = combine({ city: $city, t: $t }, ({ city, t }) => | ||
t('cityPois.buttonText', { | ||
cityName: city.name, | ||
}) | ||
); | ||
``` | ||
|
||
In both cases, result will be a [_Store_](https://effector.dev/docs/api/effector/store) containing a translated string. It will be updated automatically when the language or available translations will be changed. |
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,39 @@ | ||
# `translated` | ||
|
||
A factory that returns [_Store_](https://effector.dev/docs/api/effector/store) containing a translated string. | ||
|
||
```ts | ||
const { translated } = createI18nextIntegration({ | ||
/* ... */ | ||
}); | ||
|
||
const $someTranslatedString = translated('premiumLabel.BrandOne'); | ||
``` | ||
|
||
The second argument is an optional object with options for the translation function. Options can be a [_Store_](https://effector.dev/docs/api/effector/store) or a plain value. | ||
|
||
```ts | ||
const $city = createStore({ name: 'Moscow' }); | ||
|
||
const { translated } = createI18nextIntegration({ | ||
/* ... */ | ||
}); | ||
|
||
const $someTranslatedString = translated('cityPois.buttonText', { | ||
cityName: $city.map((city) => city.name), | ||
}); | ||
``` | ||
|
||
Also, you can pass a template string with [_Store_](https://effector.dev/docs/api/effector/store) parts of a key: | ||
|
||
```ts | ||
const $pathOfAKey = createStore('BrandOne'); | ||
|
||
const { translated } = createI18nextIntegration({ | ||
/* ... */ | ||
}); | ||
|
||
const $someTranslatedString = translated`premiumLabel.${$pathOfAKey}`; | ||
``` | ||
|
||
Result of the factory will be a [_Store_](https://effector.dev/docs/api/effector/store) containing a translated string. It will be updated automatically when the language or available translations will be changed. |
Oops, something went wrong.