next-translate-plugin 2.6.0 → 2.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -0
- package/lib/cjs/loader.js +16 -3
- package/lib/cjs/utils.js +2 -2
- package/lib/esm/loader.js +16 -3
- package/lib/esm/utils.js +2 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
|
|
2
|
+
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
|
3
|
+
[](#contributors-)
|
|
4
|
+
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
|
2
5
|
<h2 align="center">
|
|
3
6
|
<b>Next-translate-plugin</b>
|
|
4
7
|
</h2>
|
|
@@ -53,5 +56,20 @@ All the documentation is in Next-translate repository:
|
|
|
53
56
|
## Contributors ✨
|
|
54
57
|
|
|
55
58
|
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
|
|
59
|
+
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
|
|
60
|
+
<!-- prettier-ignore-start -->
|
|
61
|
+
<!-- markdownlint-disable -->
|
|
62
|
+
<table>
|
|
63
|
+
<tbody>
|
|
64
|
+
<tr>
|
|
65
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/bluelakee02"><img src="https://avatars.githubusercontent.com/u/72526240?v=4?s=100" width="100px;" alt="Josef Hes"/><br /><sub><b>Josef Hes</b></sub></a><br /><a href="https://github.com/aralroca/next-translate-plugin/commits?author=bluelakee02" title="Code">💻</a></td>
|
|
66
|
+
</tr>
|
|
67
|
+
</tbody>
|
|
68
|
+
</table>
|
|
69
|
+
|
|
70
|
+
<!-- markdownlint-restore -->
|
|
71
|
+
<!-- prettier-ignore-end -->
|
|
72
|
+
|
|
73
|
+
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
|
56
74
|
|
|
57
75
|
- [Contributors list is in Next-translate GitHub repository](https://github.com/aralroca/next-translate#contributors-)
|
package/lib/cjs/loader.js
CHANGED
|
@@ -7,6 +7,7 @@ var path_1 = __importDefault(require("path"));
|
|
|
7
7
|
var templateWithHoc_1 = __importDefault(require("./templateWithHoc"));
|
|
8
8
|
var templateWithLoader_1 = __importDefault(require("./templateWithLoader"));
|
|
9
9
|
var templateAppDir_1 = __importDefault(require("./templateAppDir"));
|
|
10
|
+
var typescript_1 = __importDefault(require("typescript"));
|
|
10
11
|
var utils_1 = require("./utils");
|
|
11
12
|
var REGEX_STARTS_WITH_APP = /\/+_app.*/;
|
|
12
13
|
function loader(rawCode) {
|
|
@@ -24,12 +25,24 @@ function loader(rawCode) {
|
|
|
24
25
|
var pagesPath = (shouldUseTemplateAppDir ? appFolder : pagesFolder);
|
|
25
26
|
if (!hasAppJs &&
|
|
26
27
|
normalizedResourcePath.includes('node_modules/next/dist/pages/_app')) {
|
|
27
|
-
|
|
28
|
+
var transpileTsx = function (tsCode) {
|
|
29
|
+
var result = typescript_1.default.transpileModule(tsCode, {
|
|
30
|
+
compilerOptions: {
|
|
31
|
+
module: typescript_1.default.ModuleKind.CommonJS,
|
|
32
|
+
outDir: './lib/cjs',
|
|
33
|
+
declaration: false,
|
|
34
|
+
declarationDir: undefined,
|
|
35
|
+
jsx: typescript_1.default.JsxEmit.React,
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
return result.outputText;
|
|
39
|
+
};
|
|
40
|
+
var jsCode = transpileTsx((0, utils_1.getDefaultAppJs)(existLocalesFolder));
|
|
41
|
+
return jsCode;
|
|
28
42
|
}
|
|
29
43
|
if (normalizedResourcePath.includes('node_modules/'))
|
|
30
44
|
return rawCode;
|
|
31
|
-
if (!shouldUseTemplateAppDir &&
|
|
32
|
-
!normalizedResourcePath.includes(pagesPath))
|
|
45
|
+
if (!shouldUseTemplateAppDir && !normalizedResourcePath.includes(pagesPath))
|
|
33
46
|
return rawCode;
|
|
34
47
|
var page = normalizedResourcePath.replace(pagesPath, '/');
|
|
35
48
|
var pageNoExt = page.replace(extensionsRgx, '');
|
package/lib/cjs/utils.js
CHANGED
|
@@ -32,14 +32,14 @@ exports.INTERNAL_CONFIG_KEY = '__i18nConfig';
|
|
|
32
32
|
exports.clientLine = ['"use client"', "'use client'"];
|
|
33
33
|
exports.defaultLoader = '(l, n) => import(`@next-translate-root/locales/${l}/${n}`).then(m => m.default)';
|
|
34
34
|
function getDefaultAppJs(existLocalesFolder) {
|
|
35
|
-
return "\n
|
|
35
|
+
return "\n import * as React from 'react'\n import ".concat(exports.INTERNAL_CONFIG_KEY, " from '@next-translate-root/i18n'\n import appWithI18n from 'next-translate/appWithI18n'\n \n function MyApp({ Component, pageProps }) {\n return <Component {...pageProps} />\n }\n \n export default appWithI18n(MyApp, {\n ...").concat(exports.INTERNAL_CONFIG_KEY, ",\n skipInitialProps: true,\n isLoader: true,\n ").concat(addLoadLocalesFrom(existLocalesFolder), "\n })\n ");
|
|
36
36
|
}
|
|
37
37
|
exports.getDefaultAppJs = getDefaultAppJs;
|
|
38
38
|
function addLoadLocalesFrom(existLocalesFolder) {
|
|
39
39
|
var defaultFn = existLocalesFolder
|
|
40
40
|
? exports.defaultLoader
|
|
41
41
|
: "() => Promise.resolve({})";
|
|
42
|
-
return "loadLocaleFrom: ".concat(exports.INTERNAL_CONFIG_KEY, ".loadLocaleFrom || (").concat(defaultFn, "),");
|
|
42
|
+
return "loadLocaleFrom: ".concat(exports.INTERNAL_CONFIG_KEY, " && ").concat(exports.INTERNAL_CONFIG_KEY, ".loadLocaleFrom || (").concat(defaultFn, "),");
|
|
43
43
|
}
|
|
44
44
|
exports.addLoadLocalesFrom = addLoadLocalesFrom;
|
|
45
45
|
function getTsCompilerOptions(basePath, cutDependencies) {
|
package/lib/esm/loader.js
CHANGED
|
@@ -2,6 +2,7 @@ import path from 'path';
|
|
|
2
2
|
import templateWithHoc from './templateWithHoc';
|
|
3
3
|
import templateWithLoader from './templateWithLoader';
|
|
4
4
|
import templateAppDir from './templateAppDir';
|
|
5
|
+
import ts from 'typescript';
|
|
5
6
|
import { parseFile, getDefaultAppJs, getDefaultExport, hasExportName, hasStaticName, isPageToIgnore, hasHOC, removeCommentsFromCode, clientLine, isInsideAppDir, } from './utils';
|
|
6
7
|
var REGEX_STARTS_WITH_APP = /\/+_app.*/;
|
|
7
8
|
export default function loader(rawCode) {
|
|
@@ -19,12 +20,24 @@ export default function loader(rawCode) {
|
|
|
19
20
|
var pagesPath = (shouldUseTemplateAppDir ? appFolder : pagesFolder);
|
|
20
21
|
if (!hasAppJs &&
|
|
21
22
|
normalizedResourcePath.includes('node_modules/next/dist/pages/_app')) {
|
|
22
|
-
|
|
23
|
+
var transpileTsx = function (tsCode) {
|
|
24
|
+
var result = ts.transpileModule(tsCode, {
|
|
25
|
+
compilerOptions: {
|
|
26
|
+
module: ts.ModuleKind.CommonJS,
|
|
27
|
+
outDir: './lib/cjs',
|
|
28
|
+
declaration: false,
|
|
29
|
+
declarationDir: undefined,
|
|
30
|
+
jsx: ts.JsxEmit.React,
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
return result.outputText;
|
|
34
|
+
};
|
|
35
|
+
var jsCode = transpileTsx(getDefaultAppJs(existLocalesFolder));
|
|
36
|
+
return jsCode;
|
|
23
37
|
}
|
|
24
38
|
if (normalizedResourcePath.includes('node_modules/'))
|
|
25
39
|
return rawCode;
|
|
26
|
-
if (!shouldUseTemplateAppDir &&
|
|
27
|
-
!normalizedResourcePath.includes(pagesPath))
|
|
40
|
+
if (!shouldUseTemplateAppDir && !normalizedResourcePath.includes(pagesPath))
|
|
28
41
|
return rawCode;
|
|
29
42
|
var page = normalizedResourcePath.replace(pagesPath, '/');
|
|
30
43
|
var pageNoExt = page.replace(extensionsRgx, '');
|
package/lib/esm/utils.js
CHANGED
|
@@ -26,13 +26,13 @@ export var INTERNAL_CONFIG_KEY = '__i18nConfig';
|
|
|
26
26
|
export var clientLine = ['"use client"', "'use client'"];
|
|
27
27
|
export var defaultLoader = '(l, n) => import(`@next-translate-root/locales/${l}/${n}`).then(m => m.default)';
|
|
28
28
|
export function getDefaultAppJs(existLocalesFolder) {
|
|
29
|
-
return "\n
|
|
29
|
+
return "\n import * as React from 'react'\n import ".concat(INTERNAL_CONFIG_KEY, " from '@next-translate-root/i18n'\n import appWithI18n from 'next-translate/appWithI18n'\n \n function MyApp({ Component, pageProps }) {\n return <Component {...pageProps} />\n }\n \n export default appWithI18n(MyApp, {\n ...").concat(INTERNAL_CONFIG_KEY, ",\n skipInitialProps: true,\n isLoader: true,\n ").concat(addLoadLocalesFrom(existLocalesFolder), "\n })\n ");
|
|
30
30
|
}
|
|
31
31
|
export function addLoadLocalesFrom(existLocalesFolder) {
|
|
32
32
|
var defaultFn = existLocalesFolder
|
|
33
33
|
? defaultLoader
|
|
34
34
|
: "() => Promise.resolve({})";
|
|
35
|
-
return "loadLocaleFrom: ".concat(INTERNAL_CONFIG_KEY, ".loadLocaleFrom || (").concat(defaultFn, "),");
|
|
35
|
+
return "loadLocaleFrom: ".concat(INTERNAL_CONFIG_KEY, " && ").concat(INTERNAL_CONFIG_KEY, ".loadLocaleFrom || (").concat(defaultFn, "),");
|
|
36
36
|
}
|
|
37
37
|
export function getTsCompilerOptions(basePath, cutDependencies) {
|
|
38
38
|
if (cutDependencies === void 0) { cutDependencies = false; }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-translate-plugin",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.2",
|
|
4
4
|
"description": "Tiny and powerful i18n plugin to translate your Next.js pages.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -104,4 +104,4 @@
|
|
|
104
104
|
"^.+\\.(j|t)sx?$": "babel-jest"
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
|
-
}
|
|
107
|
+
}
|