UNPKG

@webpro/next-translate-plugin

Version:

Tiny and powerful i18n plugin to translate your Next.js pages.

11 lines (10 loc) 1.05 kB
import { INTERNAL_CONFIG_KEY, interceptExport, addLoadLocalesFrom, } from './utils'; export default function templateWithHoc(pagePkg, _a) { var _b = _a === void 0 ? {} : _a, _c = _b.skipInitialProps, skipInitialProps = _c === void 0 ? false : _c, _d = _b.existLocalesFolder, existLocalesFolder = _d === void 0 ? true : _d; var hash = Date.now().toString(16); var pageVariableName = interceptExport(pagePkg, 'default', "__Next_Translate__Page__".concat(hash, "__")); var hasDefaultExport = Boolean(pageVariableName); if (!hasDefaultExport) return pagePkg.getCode(); return "\n import ".concat(INTERNAL_CONFIG_KEY, " from '@next-translate-root/i18n'\n import __appWithI18n from 'next-translate/appWithI18n'\n ").concat(pagePkg.getCode(), "\n export default __appWithI18n(").concat(pageVariableName, ", {\n ...").concat(INTERNAL_CONFIG_KEY, ",\n isLoader: true,\n skipInitialProps: ").concat(skipInitialProps, ",\n ").concat(addLoadLocalesFrom(existLocalesFolder), "\n });\n "); }