next-i18next
Advanced tools
Comparing version 0.5.0 to 0.6.0
@@ -36,153 +36,159 @@ "use strict"; | ||
var _hoistNonReactStatics = _interopRequireDefault(require("hoist-non-react-statics")); | ||
function _default(WrappedComponent) { | ||
var config = this.config, | ||
i18n = this.i18n; | ||
return ( | ||
/*#__PURE__*/ | ||
function (_React$Component) { | ||
(0, _inherits2.default)(_class, _React$Component); | ||
function _class() { | ||
var _this; | ||
var AppWithTranslation = | ||
/*#__PURE__*/ | ||
function (_React$Component) { | ||
(0, _inherits2.default)(AppWithTranslation, _React$Component); | ||
(0, _classCallCheck2.default)(this, _class); | ||
_this = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(_class).call(this)); | ||
function AppWithTranslation() { | ||
var _this; | ||
if (config.localeSubpaths) { | ||
i18n.on('languageChanged', function (lng) { | ||
if (process.browser) { | ||
var originalRoute = window.location.pathname; | ||
(0, _classCallCheck2.default)(this, AppWithTranslation); | ||
_this = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(AppWithTranslation).call(this)); | ||
var _lngPathCorrector = (0, _utils.lngPathCorrector)(config, i18n, originalRoute, lng), | ||
_lngPathCorrector2 = (0, _slicedToArray2.default)(_lngPathCorrector, 2), | ||
href = _lngPathCorrector2[0], | ||
as = _lngPathCorrector2[1]; | ||
if (config.localeSubpaths) { | ||
i18n.on('languageChanged', function (lng) { | ||
if (process.browser) { | ||
var originalRoute = window.location.pathname; | ||
if (as !== originalRoute) { | ||
_router.default.replace(href, as, { | ||
shallow: true | ||
}); | ||
} | ||
var _lngPathCorrector = (0, _utils.lngPathCorrector)(config, i18n, originalRoute, lng), | ||
_lngPathCorrector2 = (0, _slicedToArray2.default)(_lngPathCorrector, 2), | ||
href = _lngPathCorrector2[0], | ||
as = _lngPathCorrector2[1]; | ||
if (as !== originalRoute) { | ||
_router.default.replace(href, as, { | ||
shallow: true | ||
}); | ||
} | ||
}); | ||
} | ||
return _this; | ||
} | ||
}); | ||
} | ||
(0, _createClass2.default)(_class, [{ | ||
key: "render", | ||
value: function render() { | ||
var _this$props = this.props, | ||
initialLanguage = _this$props.initialLanguage, | ||
initialI18nStore = _this$props.initialI18nStore; | ||
return _this; | ||
} | ||
if (!process.browser) { | ||
initialLanguage = i18n.language; | ||
initialI18nStore = i18n.store.data; | ||
} | ||
(0, _createClass2.default)(AppWithTranslation, [{ | ||
key: "render", | ||
value: function render() { | ||
var _this$props = this.props, | ||
initialLanguage = _this$props.initialLanguage, | ||
initialI18nStore = _this$props.initialI18nStore; | ||
return _react.default.createElement(_reactI18next.I18nextProvider, { | ||
i18n: i18n, | ||
initialLanguage: initialLanguage, | ||
initialI18nStore: initialI18nStore | ||
}, _react.default.createElement(_components.NextStaticProvider, null, _react.default.createElement(WrappedComponent, this.props))); | ||
if (!process.browser) { | ||
initialLanguage = i18n.language; | ||
initialI18nStore = i18n.store.data; | ||
} | ||
}], [{ | ||
key: "getInitialProps", | ||
value: function () { | ||
var _getInitialProps = (0, _asyncToGenerator2.default)( | ||
/*#__PURE__*/ | ||
_regenerator.default.mark(function _callee(_ref) { | ||
var Component, ctx, pageProps, req, initialI18nStore, initialLanguage, _req$i18n$languages; | ||
return _regenerator.default.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
Component = _ref.Component, ctx = _ref.ctx; | ||
// Recompile pre-existing getInitialProps | ||
pageProps = {}; | ||
return _react.default.createElement(_reactI18next.I18nextProvider, { | ||
i18n: i18n, | ||
initialLanguage: initialLanguage, | ||
initialI18nStore: initialI18nStore | ||
}, _react.default.createElement(_components.NextStaticProvider, null, _react.default.createElement(WrappedComponent, this.props))); | ||
} | ||
}], [{ | ||
key: "getInitialProps", | ||
value: function () { | ||
var _getInitialProps = (0, _asyncToGenerator2.default)( | ||
/*#__PURE__*/ | ||
_regenerator.default.mark(function _callee(_ref) { | ||
var Component, ctx, pageProps, req, initialI18nStore, initialLanguage, _req$i18n$languages; | ||
if (!Component.getInitialProps) { | ||
_context.next = 6; | ||
break; | ||
} | ||
return _regenerator.default.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
Component = _ref.Component, ctx = _ref.ctx; | ||
// Recompile pre-existing getInitialProps | ||
pageProps = {}; | ||
_context.next = 5; | ||
return Component.getInitialProps(ctx); | ||
if (!Component.getInitialProps) { | ||
_context.next = 6; | ||
break; | ||
} | ||
case 5: | ||
pageProps = _context.sent; | ||
_context.next = 5; | ||
return Component.getInitialProps(ctx); | ||
case 6: | ||
// Initiate vars to return | ||
req = ctx.req; | ||
initialI18nStore = {}; | ||
initialLanguage = null; // Load translations to serialize if we're serverside | ||
case 5: | ||
pageProps = _context.sent; | ||
if (!(req && req.i18n)) { | ||
_context.next = 17; | ||
break; | ||
} | ||
case 6: | ||
// Initiate vars to return | ||
req = ctx.req; | ||
initialI18nStore = {}; | ||
initialLanguage = null; // Load translations to serialize if we're serverside | ||
_req$i18n$languages = (0, _slicedToArray2.default)(req.i18n.languages, 1); | ||
initialLanguage = _req$i18n$languages[0]; | ||
_context.next = 14; | ||
return i18n.changeLanguage(initialLanguage); | ||
if (!(req && req.i18n)) { | ||
_context.next = 17; | ||
break; | ||
} | ||
case 14: | ||
req.i18n.languages.forEach(function (l) { | ||
initialI18nStore[l] = {}; | ||
i18n.nsFromReactTree.forEach(function (ns) { | ||
initialI18nStore[l][ns] = (req.i18n.services.resourceStore.data[l] || {})[ns] || {}; | ||
}); | ||
_req$i18n$languages = (0, _slicedToArray2.default)(req.i18n.languages, 1); | ||
initialLanguage = _req$i18n$languages[0]; | ||
_context.next = 14; | ||
return i18n.changeLanguage(initialLanguage); | ||
case 14: | ||
req.i18n.languages.forEach(function (l) { | ||
initialI18nStore[l] = {}; | ||
i18n.nsFromReactTree.forEach(function (ns) { | ||
initialI18nStore[l][ns] = (req.i18n.services.resourceStore.data[l] || {})[ns] || {}; | ||
}); | ||
}); | ||
_context.next = 22; | ||
break; | ||
case 17: | ||
if (!(Array.isArray(i18n.languages) && i18n.languages.length > 0)) { | ||
_context.next = 22; | ||
break; | ||
} | ||
case 17: | ||
if (!(Array.isArray(i18n.languages) && i18n.languages.length > 0)) { | ||
_context.next = 22; | ||
break; | ||
} | ||
_context.next = 20; | ||
return Promise.all(i18n.nsFromReactTree.filter(function (ns) { | ||
return !i18n.hasResourceBundle(i18n.languages[0], ns); | ||
}).map(function (ns) { | ||
return new Promise(function (resolve) { | ||
return i18n.loadNamespaces(ns, function () { | ||
return resolve(); | ||
}); | ||
_context.next = 20; | ||
return Promise.all(i18n.nsFromReactTree.filter(function (ns) { | ||
return !i18n.hasResourceBundle(i18n.languages[0], ns); | ||
}).map(function (ns) { | ||
return new Promise(function (resolve) { | ||
return i18n.loadNamespaces(ns, function () { | ||
return resolve(); | ||
}); | ||
})); | ||
}); | ||
})); | ||
case 20: | ||
initialI18nStore = i18n.store.data; | ||
initialLanguage = i18n.language; | ||
case 20: | ||
initialI18nStore = i18n.store.data; | ||
initialLanguage = i18n.language; | ||
case 22: | ||
return _context.abrupt("return", { | ||
initialI18nStore: initialI18nStore, | ||
initialLanguage: initialLanguage, | ||
pageProps: pageProps | ||
}); | ||
case 22: | ||
return _context.abrupt("return", { | ||
initialI18nStore: initialI18nStore, | ||
initialLanguage: initialLanguage, | ||
pageProps: pageProps | ||
}); | ||
case 23: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
case 23: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
}, _callee, this); | ||
})); | ||
} | ||
}, _callee, this); | ||
})); | ||
return function getInitialProps(_x) { | ||
return _getInitialProps.apply(this, arguments); | ||
}; | ||
}() | ||
}]); | ||
return _class; | ||
}(_react.default.Component) | ||
); | ||
return function getInitialProps(_x) { | ||
return _getInitialProps.apply(this, arguments); | ||
}; | ||
}() | ||
}]); | ||
return AppWithTranslation; | ||
}(_react.default.Component); | ||
return (0, _hoistNonReactStatics.default)(AppWithTranslation, WrappedComponent, { | ||
getInitialProps: true | ||
}); | ||
} |
{ | ||
"name": "next-i18next", | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"main": "dist/index.js", | ||
@@ -53,2 +53,3 @@ "repository": "git@github.com:isaachinman/next-i18next.git", | ||
"detect-node": "^2.0.4", | ||
"hoist-non-react-statics": "^3.2.0", | ||
"i18next": "^12.0.0", | ||
@@ -55,0 +56,0 @@ "i18next-browser-languagedetector": "^2.2.4", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
199525
644
10
+ Addedhoist-non-react-statics@3.3.2(transitive)