Locales are not loaded when the page is re-exported
Hi! Thank you for your work
I ran into a problem. If the page is re-exported from another module, the locales are not loaded
In my project, I store modules with page code in the /src/app.pages.[page_name]/containers/Page directories and re-export them to the/pagesdirectory
I created a repository that reproduces the problem
I will be grateful for your help
The problem seems to be in the export syntax
After I changed it, everything worked
/* before */
export { Page as default, getServerSideProps } from '../src/app.pages.index/containers/Page';
/* after */
import {
Page,
getServerSideProps,
} from '../src/app.pages.index/containers/Page';
export default Page;
export { getServerSideProps };
I guess the problem is happening here:
https://github.com/vinissimus/next-translate/blob/530d01607051f84514342b83096a30561a2a5a6c/src/plugin/loader.ts#L47
The problem seems to be in the export syntax
After I changed it, everything worked
/* before */ export { Page as default, getServerSideProps } from '../src/app.pages.index/containers/Page'; /* after */ import { Page, getServerSideProps, } from '../src/app.pages.index/containers/Page'; export default Page; export { getServerSideProps };I guess the problem is happening here:
https://github.com/vinissimus/next-translate/blob/530d01607051f84514342b83096a30561a2a5a6c/src/plugin/loader.ts#L47
I have the same problem! When I tried to create some URL aliases in the pages folder by creating a different folder with different names (translation) and for reusing the same templates for different languages I put the general template in the components folder. When I try to export the general template as default in this case the locales are not loaded to the exported file. And your fix with separate import and then export looks like a working. Thanks for the fix and waiting maybe it will be fixed.
Right now it is a current limitation of the loader... It is necessary to investigate how to do it, because it will be necessary to modify the content of where the page is exported to add the translations inside the getStaticProps, getInitialProps or getServerSideProps. Alternatively, you can not use the loader and do it manually:
https://github.com/vinissimus/next-translate/tree/1.0.5/examples/without-loader
@austrokhart The idea of 2.0 version is to change the regular expressions in a better way. Currently, there are 2 proposals: with Babel parser and with TypeScript compiler.
We need feedback from the people to decide which one corrects more errors and does not generate new ones.
This bug should be fixed with the new version Can you test these two prereleases and give feedback?
With Babel: 2.0.0-experimental.1
With TypeScript compiler: 2.0.0-experimental.2
You can use this discussion to write your feedback:
https://github.com/aralroca/next-translate/discussions/881
Thank you so much!