next-translate 1.3.2 → 1.3.5

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 CHANGED
@@ -959,6 +959,8 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
959
959
  <td align="center"><a href="https://github.com/testerez"><img src="https://avatars.githubusercontent.com/u/815236?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Tom Esterez</b></sub></a><br /><a href="https://github.com/vinissimus/next-translate/commits?author=testerez" title="Code">💻</a></td>
960
960
  <td align="center"><a href="http://www.dan-needham.com"><img src="https://avatars.githubusercontent.com/u/1122983?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Dan Needham</b></sub></a><br /><a href="https://github.com/vinissimus/next-translate/commits?author=dndhm" title="Code">💻</a> <a href="https://github.com/vinissimus/next-translate/commits?author=dndhm" title="Tests">⚠️</a> <a href="https://github.com/vinissimus/next-translate/commits?author=dndhm" title="Documentation">📖</a></td>
961
961
  <td align="center"><a href="https://www.youtube.com/BrunoAntunesPT"><img src="https://avatars.githubusercontent.com/u/9042965?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Bruno Antunes</b></sub></a><br /><a href="https://github.com/vinissimus/next-translate/commits?author=bmvantunes" title="Code">💻</a></td>
962
+ <td align="center"><a href="https://github.com/kaan-atakan"><img src="https://avatars.githubusercontent.com/u/56063979?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Kaan Atakan</b></sub></a><br /><a href="https://github.com/vinissimus/next-translate/commits?author=kaan-atakan" title="Code">💻</a></td>
963
+ <td align="center"><a href="https://github.com/groomain"><img src="https://avatars.githubusercontent.com/u/3601848?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Romain</b></sub></a><br /><a href="https://github.com/vinissimus/next-translate/commits?author=groomain" title="Code">💻</a></td>
962
964
  </tr>
963
965
  </table>
964
966
 
package/index.d.ts CHANGED
@@ -36,6 +36,7 @@ export interface I18nConfig {
36
36
  pages?: Record<string, PageValue>;
37
37
  logger?: I18nLogger;
38
38
  staticsHoc?: Function;
39
+ extensionsRgx?: string;
39
40
  loader?: boolean;
40
41
  logBuild?: boolean;
41
42
  revalidate?: number;
@@ -5,7 +5,7 @@ function templateWithHoc(code, _a) {
5
5
  var _b = _a === void 0 ? {} : _a, _c = _b.skipInitialProps, skipInitialProps = _c === void 0 ? false : _c, _d = _b.typescript, typescript = _d === void 0 ? false : _d, _e = _b.pageName, pageName = _e === void 0 ? '__Page_Next_Translate__' : _e, _f = _b.hasLoadLocaleFrom, hasLoadLocaleFrom = _f === void 0 ? false : _f;
6
6
  var tokenToReplace = "__CODE_TOKEN_".concat(Date.now().toString(16), "__");
7
7
  var codeWithoutComments = code.replace(utils_1.clearCommentsRgx, '');
8
- var modifiedCode = codeWithoutComments.replace(/export +default/g, "const ".concat(pageName, " ="));
8
+ var modifiedCode = code.replace(/export +default/g, "const ".concat(pageName, " ="));
9
9
  var _g = codeWithoutComments.match(/export +default +(function|class) +([A-Z]\w*)/) || [], componentName = _g[2];
10
10
  if (componentName) {
11
11
  modifiedCode = modifiedCode.replace(new RegExp("\\W".concat(componentName, "\\.getInitialProps"), 'g'), "".concat(pageName, ".getInitialProps"));
@@ -4,7 +4,7 @@ var utils_1 = require("./utils");
4
4
  function templateWithLoader(rawCode, _a) {
5
5
  var _b = _a === void 0 ? {} : _a, _c = _b.page, page = _c === void 0 ? '' : _c, _d = _b.typescript, typescript = _d === void 0 ? false : _d, _e = _b.loader, loader = _e === void 0 ? 'getStaticProps' : _e, _f = _b.hasLoader, hasLoader = _f === void 0 ? false : _f, _g = _b.hasLoadLocaleFrom, hasLoadLocaleFrom = _g === void 0 ? false : _g, _h = _b.revalidate, revalidate = _h === void 0 ? 0 : _h;
6
6
  var tokenToReplace = "__CODE_TOKEN_".concat(Date.now().toString(16), "__");
7
- var modifiedCode = rawCode.replace(utils_1.clearCommentsRgx, '');
7
+ var modifiedCode = rawCode;
8
8
  if (hasLoader) {
9
9
  modifiedCode = modifiedCode
10
10
  .replace(new RegExp("(const|var|let|async +function|function|import|import {.* as) +".concat(loader, "\\W")), function (v) {
@@ -94,7 +94,7 @@ function plural(pluralRules, dic, key, config, query) {
94
94
  if (getDicValue(dic, numKey, config) !== undefined)
95
95
  return numKey;
96
96
  var pluralKey = "".concat(key, "_").concat(pluralRules.select(query.count));
97
- if (query.count > 0 && getDicValue(dic, pluralKey, config) !== undefined) {
97
+ if (getDicValue(dic, pluralKey, config) !== undefined) {
98
98
  return pluralKey;
99
99
  }
100
100
  var nestedNumKey = "".concat(key, ".").concat(query.count);
@@ -113,7 +113,7 @@ function interpolation(_a) {
113
113
  return str.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
114
114
  };
115
115
  var _b = config.interpolation || {}, _c = _b.format, format = _c === void 0 ? null : _c, _d = _b.prefix, prefix = _d === void 0 ? '{{' : _d, _e = _b.suffix, suffix = _e === void 0 ? '}}' : _e;
116
- var regexEnd = suffix === '' ? '' : "\\s*,?\\s*([\\w-]+)?\\s*".concat(escapeRegex(suffix));
116
+ var regexEnd = suffix === '' ? '' : "(?:[\\s,]+([\\w-]*))?\\s*".concat(escapeRegex(suffix));
117
117
  return Object.keys(query).reduce(function (all, varKey) {
118
118
  var regex = new RegExp("".concat(escapeRegex(prefix), "\\s*").concat(varKey).concat(regexEnd), 'gm');
119
119
  return all.replace(regex, function (_match, $1) {
@@ -3,7 +3,7 @@ export default function templateWithHoc(code, _a) {
3
3
  var _b = _a === void 0 ? {} : _a, _c = _b.skipInitialProps, skipInitialProps = _c === void 0 ? false : _c, _d = _b.typescript, typescript = _d === void 0 ? false : _d, _e = _b.pageName, pageName = _e === void 0 ? '__Page_Next_Translate__' : _e, _f = _b.hasLoadLocaleFrom, hasLoadLocaleFrom = _f === void 0 ? false : _f;
4
4
  var tokenToReplace = "__CODE_TOKEN_".concat(Date.now().toString(16), "__");
5
5
  var codeWithoutComments = code.replace(clearCommentsRgx, '');
6
- var modifiedCode = codeWithoutComments.replace(/export +default/g, "const ".concat(pageName, " ="));
6
+ var modifiedCode = code.replace(/export +default/g, "const ".concat(pageName, " ="));
7
7
  var _g = codeWithoutComments.match(/export +default +(function|class) +([A-Z]\w*)/) || [], componentName = _g[2];
8
8
  if (componentName) {
9
9
  modifiedCode = modifiedCode.replace(new RegExp("\\W".concat(componentName, "\\.getInitialProps"), 'g'), "".concat(pageName, ".getInitialProps"));
@@ -1,8 +1,8 @@
1
- import { clearCommentsRgx, overwriteLoadLocales } from './utils';
1
+ import { overwriteLoadLocales } from './utils';
2
2
  export default function templateWithLoader(rawCode, _a) {
3
3
  var _b = _a === void 0 ? {} : _a, _c = _b.page, page = _c === void 0 ? '' : _c, _d = _b.typescript, typescript = _d === void 0 ? false : _d, _e = _b.loader, loader = _e === void 0 ? 'getStaticProps' : _e, _f = _b.hasLoader, hasLoader = _f === void 0 ? false : _f, _g = _b.hasLoadLocaleFrom, hasLoadLocaleFrom = _g === void 0 ? false : _g, _h = _b.revalidate, revalidate = _h === void 0 ? 0 : _h;
4
4
  var tokenToReplace = "__CODE_TOKEN_".concat(Date.now().toString(16), "__");
5
- var modifiedCode = rawCode.replace(clearCommentsRgx, '');
5
+ var modifiedCode = rawCode;
6
6
  if (hasLoader) {
7
7
  modifiedCode = modifiedCode
8
8
  .replace(new RegExp("(const|var|let|async +function|function|import|import {.* as) +".concat(loader, "\\W")), function (v) {
@@ -91,7 +91,7 @@ function plural(pluralRules, dic, key, config, query) {
91
91
  if (getDicValue(dic, numKey, config) !== undefined)
92
92
  return numKey;
93
93
  var pluralKey = "".concat(key, "_").concat(pluralRules.select(query.count));
94
- if (query.count > 0 && getDicValue(dic, pluralKey, config) !== undefined) {
94
+ if (getDicValue(dic, pluralKey, config) !== undefined) {
95
95
  return pluralKey;
96
96
  }
97
97
  var nestedNumKey = "".concat(key, ".").concat(query.count);
@@ -110,7 +110,7 @@ function interpolation(_a) {
110
110
  return str.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
111
111
  };
112
112
  var _b = config.interpolation || {}, _c = _b.format, format = _c === void 0 ? null : _c, _d = _b.prefix, prefix = _d === void 0 ? '{{' : _d, _e = _b.suffix, suffix = _e === void 0 ? '}}' : _e;
113
- var regexEnd = suffix === '' ? '' : "\\s*,?\\s*([\\w-]+)?\\s*".concat(escapeRegex(suffix));
113
+ var regexEnd = suffix === '' ? '' : "(?:[\\s,]+([\\w-]*))?\\s*".concat(escapeRegex(suffix));
114
114
  return Object.keys(query).reduce(function (all, varKey) {
115
115
  var regex = new RegExp("".concat(escapeRegex(prefix), "\\s*").concat(varKey).concat(regexEnd), 'gm');
116
116
  return all.replace(regex, function (_match, $1) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-translate",
3
- "version": "1.3.2",
3
+ "version": "1.3.5",
4
4
  "description": "Tiny and powerful i18n tools (Next plugin + API) to translate your Next.js pages.",
5
5
  "license": "MIT",
6
6
  "keywords": [