aralroca / next-translate-plugin

Next-translate plugin for i18n in Next.js 🌍 - Load page translations and use them in an easy way!
MIT License
30 stars 17 forks source link

Fix checking `/_app` in the plugin #35

Closed TheMatrixan closed 1 year ago

TheMatrixan commented 1 year ago

Hi! πŸ‘‹

Firstly, thanks for your work on this project! πŸ™‚

Today I used patch-package to patch next-translate-plugin@2.0.5 for the project I'm working on.

Here is the diff that solved my problem which was that plugin is not working with Next.js custom page extensions:

diff --git a/node_modules/next-translate-plugin/lib/cjs/loader.js b/node_modules/next-translate-plugin/lib/cjs/loader.js
index 686d7b1..f87ebb7 100644
--- a/node_modules/next-translate-plugin/lib/cjs/loader.js
+++ b/node_modules/next-translate-plugin/lib/cjs/loader.js
@@ -31,11 +31,11 @@ function loader(rawCode) {
         return rawCode;
     }
     if (hasGetInitialPropsOnAppJs) {
-        return pageNoExt === '/_app'
+        return pageNoExt.startsWith('/_app')
             ? (0, templateWithHoc_1.default)(pagePkg, { hasLoadLocaleFrom: hasLoadLocaleFrom })
             : rawCode;
     }
-    if (pageNoExt === '/_app') {
+    if (pageNoExt.startsWith('/_app')) {
         return (0, templateWithHoc_1.default)(pagePkg, {
             skipInitialProps: true,
             hasLoadLocaleFrom: hasLoadLocaleFrom,
diff --git a/node_modules/next-translate-plugin/lib/esm/loader.js b/node_modules/next-translate-plugin/lib/esm/loader.js
index 4950f3a..6137ff7 100644
--- a/node_modules/next-translate-plugin/lib/esm/loader.js
+++ b/node_modules/next-translate-plugin/lib/esm/loader.js
@@ -26,11 +26,11 @@ export default function loader(rawCode) {
         return rawCode;
     }
     if (hasGetInitialPropsOnAppJs) {
-        return pageNoExt === '/_app'
+        return pageNoExt.startsWith('/_app')
             ? templateWithHoc(pagePkg, { hasLoadLocaleFrom: hasLoadLocaleFrom })
             : rawCode;
     }
-    if (pageNoExt === '/_app') {
+    if (pageNoExt.startsWith('/_app')) {
         return templateWithHoc(pagePkg, {
             skipInitialProps: true,
             hasLoadLocaleFrom: hasLoadLocaleFrom,

This issue body was partially generated by patch-package.

aralroca commented 1 year ago

Feel free to PR @TheMatrixan πŸ‘Œ