-
Notifications
You must be signed in to change notification settings - Fork 379
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
Question: migration path from react-intl
to js-lingui
?
#154
Comments
Hello @tinynumbers, This would be great to document and once the instructions are clear, we could turn them into codemod. TLDR: There's no clear migration path at the moment. ComponentsI think the migration should could be done in two stages:
// react-intl
<FormattedMessage
id='app.greeting'
description='Greeting to welcome the user to the app'
defaultMessage='Hello, {name}!'
values={{
name: 'Eric'
}}
/>
// @lingui/react - first phase
<Trans
id='app.greeting'
// description='Greeting to welcome the user to the app'
defaults='Hello, {name}!'
values={{
name: 'Eric'
}}
/>
// @lingui/react - final phase, using babel presets
<Trans id='app.greeting'>Hello {name}</Trans> Functions (aka Injection API)
// react-intl
injectIntl(Component, options)
// @lingui/react
withI18n(options)(Component)
// without options
withI18n()(Component) Now, all
This is the area with the biggest documentation dept :/ Missing piecesThere's no FormatDateRelative at the moment. FormatHTMLMessage isn't required, because it's handled by Trans component itself. What components do you use in your project? |
The only things we're importing from
What you've written is a big help - thank you! |
Ah, I forgot. Instead of const languages = {
'english': i18nMark('English'),
'french': i18nMark('French')
}
// now you can feed `Trans` id prop with marked string.
<Trans id={languages['english']} /> Under the hood, I'll take a look at |
Follow-up question: have you ever seen projects that use |
No, I haven't heard about any. Theoretically this should be possible, because |
I recently migrated small codebase from react-intl to js-lingui (by hand) and only hiccup was with DateFormat component. It seems that react-intl's FormattedDate was internally calling new Date() so you could pass in just strings instead of just Date objects in js-lingui. |
Is it possible to use For now, in my proof-of-concept spike on this migration, I've been using A bunch of messages: const messages = {
foo: i18nMark('Foo'),
bar: i18nMark('Bar Baz {extra} Stuff'),
}; The translation: const subsituteMe = 'some text';
// 1.x:
i18n._(messages.bar, { values: { extra: substituteMe } });
// or, 2.x:
i18n._(messages.bar, { extra: substituteMe }); |
Yes, you're correct. If you use const extra = 'some text'
i18n.t`Bar Baz {extra} Stuff` |
@tricoder42 You mentioned above that react-intl's |
I'm closing this issue as it becomes a bit obsolete. If anyone recentl migrated from react-into to LinguiJS, feel free to send a PR with migration guide. |
Has there been any documented approach (or tooling) around ways to migrate an existing code-base from
react-intl
translations tojs-lingui
translations?I have a rather large codebase that was originally built around
react-intl
but I'd like to change it to usejs-lingui
everywhere... but not finding much direction on tackling this project.Any suggestions?
The text was updated successfully, but these errors were encountered: