using-i18n
using-i18n copied to clipboard
Simple question
Thank you for your example. I am a beginner and I'm trying to also have the pages in src/pages in several languages. If I try your solution, gatsby-mdx (BTW: is deprecated in favor of gatsby-plugin-mdx) converts all mdx files into pages (and there is as far as I see no way to prevent this) so that I get an error about 'page about/ already exists, etc'.
Which method would you recommend?
Hi Igor,
Not an expert in MDX, but my thoughts on top of my head:
- if you create physical files for pages, then you better use a plugin to have pager per language.
- if you've tried following along the blog post, you probably get the error of an existing content because the physical files.
If you like, you can share some attempts you've made or a repo with a sample setup. Easier to discuss details.
In general, the goal of this repo and the blog post around it are to demonstrate the power of the createPage helper to automate page creation. It's not to say you always have to use it, as in the end it all depends on your specific requirements.
On Wed, 11 Dec 2019, 16:25 Igor Sosa Mayor, [email protected] wrote:
Thank you for your example. I am a beginner and I'm trying to also have the pages in src/pages in several languages. If I try your solution, gatsby-mdx (BTW: is deprecated in favor of gatsby-plugin-mdx) converts all mdx files into pages (and there is as far as I see no way to prevent this) so that I get an error about 'page about/ already exists, etc'.
Which method would you recommend?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/kalinchernev/using-i18n/issues/2?email_source=notifications&email_token=AAOVTFBGNNTTGJLTTQN2RUDQYEA7XA5CNFSM4JZQY2QKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4H7ZO73A, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOVTFDGLMJAALVYY55SKDDQYEA7XANCNFSM4JZQY2QA .
thanks for your answer.
I think (as a complete beginner with react, etc.) I understand the general approach of your solution of using createPage, etc. I think I have more problems with the general framework: using context, i18next, etc. That means, I'm trying to understand your code in withI18next, etc.
Above all because I want to get rid of gatsby-plugin-layout, but I do not know how to do it, preserving the instantiation of i18next, etc. But, as I said, it is more a general problem of my understanding of react components as with your code.
withI18next is so called higher order component (HOC) In the sample project here, as well as other community projects, the idea is to have a place where i18next framework is setup (instantiated).
I also had some difficulties wrapping my head around i18next, it's a big project by itself. it's worth spending some time with the documentation though - it's a solid project with good conventions and the time investment won't be lost if you decide to use it in other frameworks.
If you remove gatsby-plugin-layout
you will switch to "vanilla" Gatsby.js. Here are the documentation pages: https://www.gatsbyjs.org/docs/layout-components/
In most generic way of thinking:
- think about a place where you instantiate i18next
- think about the way you want to feed translations resources (there are ways to do it server-side with plugins, but it's not super easy)
- think about binding the event of switching a language to changing the language context in terms of i18next.changeLanguage()
There are many examples of using i18next with client-only translations which are easier to setup.
perfect! Thanks a lot for your comments (and for the idea in the article). I managed to have my about pagese in src/pages using md files (not mdx) and using your approach. I will try to understand the idea behind i18next (I'm not a developer, just a historian...). But thanks again!
Sorry for asking again, but what is the reason you do not use in your code?
import { initReactI18next } from 'react-i18next';
As far as I see, it seems to be important? https://react.i18next.com/latest/using-with-hooks
Different ways to start the framework so to say.
On Thu, 12 Dec 2019, 15:23 Igor Sosa Mayor, [email protected] wrote:
Sorry for asking again, but what is the reason you do not use in your code?
import { initReactI18next } from 'react-i18next';
As far as I see, it seems to be important? https://react.i18next.com/latest/using-with-hooks
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kalinchernev/using-i18n/issues/2?email_source=notifications&email_token=AAOVTFGT2S4WW6ESMON6VI3QYJCPLA5CNFSM4JZQY2QKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEGW2DDA#issuecomment-565027212, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOVTFEKGODIB7FEZU2QQHDQYJCPLANCNFSM4JZQY2QA .
ok, thanks!