-
Notifications
You must be signed in to change notification settings - Fork 364
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
Pure JS interface #10
Comments
Variable namesTagged template literals don't provide name of variables passed in, so it's not possible to get // "Hello {name}"
i18n.t`Hello ${i18n.var({ name })}`
// or
i18n.t`Hello ${{ name }}` or pass variable inside object 🎉 Both options might be possible: i18n.t`Hello ${name}` // => Hello {0}
i18n.t`Hello ${{ name }}` // => Hello {name} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
React components are great because they care of updates after language/message changes. However, sometimes it's necessary to get string directly instead of React node tree, e.g: for element attributes,
document.title
, etc. Sometimes it needs to be done even out of theProvideI18n
context, e.g. inside sagas (from redux-saga).Phase 1 - Translation of raw ICU message format
This is the easiest use case. The only problem might be how to load messages into global object. Optionally add an API for precompiled messages.
This option isn't interesting at all, because many other libs already provides such functionality, but it's simple enough to keep it as a backup.
Implementation
i18n.use
i18n.t
i18n.compile
Phase 2 - ICU message format helper functions
Provide helper functions which mimic behavior of React components. Something like DSL for ICU message format:
Implementation
i18n.t
i18n.plural
i18n.select
Custom formatsThe text was updated successfully, but these errors were encountered: