-
-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Effect and async function as instance #79
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ca75206
Support Effect and async function as instance
igorkamyshev 1da7aab
Merge remote-tracking branch 'origin/master' into async-init-i18next
igorkamyshev 8b74ff2
Merge remote-tracking branch 'origin/master' into async-init-i18next
igorkamyshev d292003
Reformat docs to add new overloads
igorkamyshev 50f583f
Allow to pass async `instance` to integration
igorkamyshev 57a76e5
Add new store to the docs
igorkamyshev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be cool to also add a error handling example here 🤔