Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

next-multilingual

Package Overview
Dependencies
Maintainers
1
Versions
156
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

next-multilingual - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

54

lib/config/index.js

@@ -99,3 +99,3 @@ "use strict";

locales.forEach((locale) => {
if (!__1.isLocale(locale)) {
if (!(0, __1.isLocale)(locale)) {
throw new Error("invalid locale '" +

@@ -107,3 +107,3 @@ locale +

// Set the actual desired locales of the multilingual application.
this.actualLocales = locales.map((locale) => __1.normalizeLocale(locale));
this.actualLocales = locales.map((locale) => (0, __1.normalizeLocale)(locale));
// The `mul` (multilingual) default locale is required for dynamic locale resolution for requests on `/`.

@@ -113,7 +113,7 @@ this.defaultLocale = 'mul';

this.locales = [this.defaultLocale, ...this.actualLocales];
this.pagesDirectoryPath = path_1.resolve(pagesDirectoryPath);
this.pagesDirectoryPath = (0, path_1.resolve)(pagesDirectoryPath);
if (pagesExtensions?.length) {
this.pagesExtensions = pagesExtensions.map((extension) => extension.startsWith('.') ? extension : `.${extension}`);
}
this.excludedPages = excludedPages.map((excludedPage) => path_1.resolve(this.pagesDirectoryPath, excludedPage));
this.excludedPages = excludedPages.map((excludedPage) => (0, path_1.resolve)(this.pagesDirectoryPath, excludedPage));
this.routes = this.getRoutes();

@@ -132,6 +132,6 @@ // During development, add an extra watcher to trigger recompile when a `.properties` file changes.

]) {
const sourceFilePath = messages_1.getSourceFilePath(messagesFile, sourceFileExtension);
if (fs_1.existsSync(sourceFilePath)) {
const sourceFilePath = (0, messages_1.getSourceFilePath)(messagesFile, sourceFileExtension);
if ((0, fs_1.existsSync)(sourceFilePath)) {
// "touch" the file without any changes to trigger recompile.
fs_1.utimesSync(sourceFilePath, new Date(), new Date());
(0, fs_1.utimesSync)(sourceFilePath, new Date(), new Date());
const currentRoutes = this.getRoutes();

@@ -173,11 +173,11 @@ if (JSON.stringify(currentRoutes) !== JSON.stringify(routesSnapshot)) {

let pagesFound = 0;
fs_1.readdirSync(directoryPath, { withFileTypes: true }).forEach((directoryEntry) => {
(0, fs_1.readdirSync)(directoryPath, { withFileTypes: true }).forEach((directoryEntry) => {
if (directoryEntry.isFile()) {
const directoryEntryPath = path_1.resolve(directoryPath, directoryEntry.name);
const directoryEntryExtension = path_1.extname(directoryEntryPath);
const directoryEntryPath = (0, path_1.resolve)(directoryPath, directoryEntry.name);
const directoryEntryExtension = (0, path_1.extname)(directoryEntryPath);
if (!this.pagesExtensions.includes(directoryEntryExtension)) {
return; // Skip this file if the extension is not in scope.
}
const pageFile = path_1.parse(directoryEntryPath);
const pagePathWithoutExtension = path_1.resolve(pageFile.dir, pageFile.name);
const pageFile = (0, path_1.parse)(directoryEntryPath);
const pagePathWithoutExtension = (0, path_1.resolve)(pageFile.dir, pageFile.name);
if (this.excludedPages.includes(pagePathWithoutExtension)) {

@@ -201,7 +201,7 @@ return; // Skip this file if it's excluded.

// Next.js silently ignores duplicate pages but we will at least show a warning when it occurs.
const { dir: currentDirectoryPath } = path_1.parse(directoryEntryPath);
const { dir: parentDirectoryPath } = path_1.parse(currentDirectoryPath);
const { dir: currentDirectoryPath } = (0, path_1.parse)(directoryEntryPath);
const { dir: parentDirectoryPath } = (0, path_1.parse)(currentDirectoryPath);
this.actualLocales.forEach((locale) => {
const messagesFilePath = messages_1.getMessagesFilePath(directoryEntryPath, locale);
if (fs_1.existsSync(messagesFilePath)) {
const messagesFilePath = (0, messages_1.getMessagesFilePath)(directoryEntryPath, locale);
if ((0, fs_1.existsSync)(messagesFilePath)) {
__2.log.warn(`\`${messagesFilePath}\` will be ignored since the \`${identifier}\` was already defined in \`${parentDirectoryPath}\`. If you prefer to use this directory, you can move the files associated with \`${identifier}\` to \`${currentDirectoryPath}\` using an \`index\` file.`);

@@ -245,3 +245,3 @@ }

if (!this.directoryContainsPages(currentDirectoryPath)) {
const directoryEntryPath = path_1.resolve(currentDirectoryPath, 'index');
const directoryEntryPath = (0, path_1.resolve)(currentDirectoryPath, 'index');
const identifier = fileSystemPathToUrlPath(currentDirectoryPath.replace(baseDirectoryPath, ''));

@@ -251,11 +251,11 @@ this.addRoute(directoryEntryPath, identifier, routes);

// Read through all the files of the current directory and look for pages or sub-directories.
fs_1.readdirSync(currentDirectoryPath, { withFileTypes: true }).forEach((directoryEntry) => {
const directoryEntryPath = path_1.resolve(currentDirectoryPath, directoryEntry.name);
(0, fs_1.readdirSync)(currentDirectoryPath, { withFileTypes: true }).forEach((directoryEntry) => {
const directoryEntryPath = (0, path_1.resolve)(currentDirectoryPath, directoryEntry.name);
if (directoryEntry.isFile()) {
const directoryEntryExtension = path_1.extname(directoryEntryPath);
const directoryEntryExtension = (0, path_1.extname)(directoryEntryPath);
if (!this.pagesExtensions.includes(directoryEntryExtension)) {
return; // Skip this file if the extension is not in scope.
}
const pageFile = path_1.parse(directoryEntryPath);
const pagePathWithoutExtension = path_1.resolve(pageFile.dir, pageFile.name);
const pageFile = (0, path_1.parse)(directoryEntryPath);
const pagePathWithoutExtension = (0, path_1.resolve)(pageFile.dir, pageFile.name);
if (this.excludedPages.includes(pagePathWithoutExtension)) {

@@ -286,11 +286,11 @@ return; // Skip this file if it's excluded.

getLocalizedUrlPathSegment(sourceFilePath, locale) {
const messagesFilePath = messages_1.getMessagesFilePath(sourceFilePath, locale);
if (!fs_1.existsSync(messagesFilePath)) {
__2.log.warn(`unable to use the \`${__1.normalizeLocale(locale)}\` URL segment for \`${sourceFilePath}\`. The message file \`${messagesFilePath}\` does not exist.`);
const messagesFilePath = (0, messages_1.getMessagesFilePath)(sourceFilePath, locale);
if (!(0, fs_1.existsSync)(messagesFilePath)) {
__2.log.warn(`unable to use the \`${(0, __1.normalizeLocale)(locale)}\` URL segment for \`${sourceFilePath}\`. The message file \`${messagesFilePath}\` does not exist.`);
return '';
}
const keyValueObject = properties_1.parsePropertiesFile(messagesFilePath);
const keyValueObject = (0, properties_1.parsePropertiesFile)(messagesFilePath);
const urlSegmentKey = Object.keys(keyValueObject).find((key) => key.endsWith(`.${messages_1.urlSegmentKeyId}`));
if (!urlSegmentKey) {
__2.log.warn(`unable to use the \`${__1.normalizeLocale(locale)}\` URL segment for \`${sourceFilePath}\`. The message file \`${messagesFilePath}\` must include a key with the \`${messages_1.urlSegmentKeyId}\` identifier.`);
__2.log.warn(`unable to use the \`${(0, __1.normalizeLocale)(locale)}\` URL segment for \`${sourceFilePath}\`. The message file \`${messagesFilePath}\` must include a key with the \`${messages_1.urlSegmentKeyId}\` identifier.`);
return '';

@@ -297,0 +297,0 @@ }

@@ -28,8 +28,8 @@ "use strict";

*/
const alternateLinks = use_alternate_links_1.useAlternateLinks();
const canonicalLink = use_canonical_link_1.useCanonicalLink();
return (jsx_runtime_1.jsxs(head_1.default, { children: [jsx_runtime_1.jsx("link", { rel: "canonical", href: canonicalLink.href }, canonicalLink.key), alternateLinks.map(({ href, hrefLang, key }) => {
return jsx_runtime_1.jsx("link", { rel: "alternate", href: href, hrefLang: hrefLang }, key);
const alternateLinks = (0, use_alternate_links_1.useAlternateLinks)();
const canonicalLink = (0, use_canonical_link_1.useCanonicalLink)();
return ((0, jsx_runtime_1.jsxs)(head_1.default, { children: [(0, jsx_runtime_1.jsx)("link", { rel: "canonical", href: canonicalLink.href }, canonicalLink.key), alternateLinks.map(({ href, hrefLang, key }) => {
return (0, jsx_runtime_1.jsx)("link", { rel: "alternate", href: href, hrefLang: hrefLang }, key);
}), children] }, void 0));
}
exports.MulHead = MulHead;

@@ -18,3 +18,3 @@ "use strict";

function getLocalizedUrlPath(rewrites, locale, urlPath) {
const normalizedUrlPath = normalize_url_path_1.normalizeUrlPath(urlPath);
const normalizedUrlPath = (0, normalize_url_path_1.normalizeUrlPath)(urlPath);
const destinationUrlPath = `/${locale}${normalizedUrlPath}`;

@@ -21,0 +21,0 @@ const rewrite = rewrites.find((rewrite) => rewrite.locale === false && rewrite.destination === destinationUrlPath);

@@ -19,7 +19,7 @@ "use strict";

// Get the content from the Next.js build-manifest (.next/build-manifest.json).
const buildManifestPath = path_1.resolve('.next', 'build-manifest.json');
const buildManifestContent = fs_1.readFileSync(buildManifestPath, 'utf8');
const buildManifestPath = (0, path_1.resolve)('.next', 'build-manifest.json');
const buildManifestContent = (0, fs_1.readFileSync)(buildManifestPath, 'utf8');
// Get the content of the client build-manifest (e.g. .next/static/development/_buildManifest.json).
const clientBuildManifestPath = JSON.parse(buildManifestContent).lowPriorityFiles.find((filePaths) => filePaths.includes('_buildManifest.js'));
const clientBuildManifestContent = fs_1.readFileSync(path_1.resolve('.next', clientBuildManifestPath), 'utf8');
const clientBuildManifestContent = (0, fs_1.readFileSync)((0, path_1.resolve)('.next', clientBuildManifestPath), 'utf8');
// Transform the client build-manifest file content back into a usable object.

@@ -26,0 +26,0 @@ const clientBuildManifest = {};

@@ -20,13 +20,13 @@ "use strict";

function useAlternateLinks() {
const { basePath, asPath, defaultLocale, locales, route } = router_1.useRouter();
const rewrites = use_rewrites_1.useRewrites();
const origin = get_origin_1.getOrigin();
const { basePath, asPath, defaultLocale, locales, route } = (0, router_1.useRouter)();
const rewrites = (0, use_rewrites_1.useRewrites)();
const origin = (0, get_origin_1.getOrigin)();
const [urlPath, asPathQuery] = asPath.split('?');
const urlSearchParamsString = new URLSearchParams(asPathQuery).toString();
const urlQuery = urlSearchParamsString ? `?${urlSearchParamsString}` : '';
const normalizedBasePath = normalize_url_path_1.normalizeUrlPath(basePath);
const alternateLinks = __1.getActualLocales(locales, defaultLocale).map((locale) => {
const localizedUrlPath = get_localized_url_path_1.getLocalizedUrlPath(rewrites, locale, urlPath);
const normalizedBasePath = (0, normalize_url_path_1.normalizeUrlPath)(basePath);
const alternateLinks = (0, __1.getActualLocales)(locales, defaultLocale).map((locale) => {
const localizedUrlPath = (0, get_localized_url_path_1.getLocalizedUrlPath)(rewrites, locale, urlPath);
const href = `${origin}${normalizedBasePath}${localizedUrlPath}${urlQuery}`;
const hrefLang = __1.normalizeLocale(locale);
const hrefLang = (0, __1.normalizeLocale)(locale);
const key = `alternate-link-${hrefLang}`;

@@ -33,0 +33,0 @@ return {

@@ -20,10 +20,10 @@ "use strict";

function useCanonicalLink() {
const { basePath, pathname, defaultLocale, locale, locales, route } = router_1.useRouter();
const rewrites = use_rewrites_1.useRewrites();
const origin = get_origin_1.getOrigin();
const normalizedBasePath = normalize_url_path_1.normalizeUrlPath(basePath);
const actualLocale = __1.getActualLocale(locale, defaultLocale, locales);
const { basePath, pathname, defaultLocale, locale, locales, route } = (0, router_1.useRouter)();
const rewrites = (0, use_rewrites_1.useRewrites)();
const origin = (0, get_origin_1.getOrigin)();
const normalizedBasePath = (0, normalize_url_path_1.normalizeUrlPath)(basePath);
const actualLocale = (0, __1.getActualLocale)(locale, defaultLocale, locales);
const key = 'canonical-link';
if (route === '/') {
const localePrefix = normalize_url_path_1.normalizeUrlPath(actualLocale.toLowerCase());
const localePrefix = (0, normalize_url_path_1.normalizeUrlPath)(actualLocale.toLowerCase());
const href = `${origin}${normalizedBasePath}${localePrefix}`;

@@ -36,3 +36,3 @@ return {

else {
const localizedUrlPath = get_localized_url_path_1.getLocalizedUrlPath(rewrites, actualLocale, pathname);
const localizedUrlPath = (0, get_localized_url_path_1.getLocalizedUrlPath)(rewrites, actualLocale, pathname);
const href = `${origin}${normalizedBasePath}${localizedUrlPath}`;

@@ -39,0 +39,0 @@ return {

@@ -15,5 +15,5 @@ "use strict";

function useLocalizedUrl(locale, urlPath) {
const rewrites = use_rewrites_1.useRewrites();
return get_localized_url_path_1.getLocalizedUrlPath(rewrites, locale, urlPath);
const rewrites = (0, use_rewrites_1.useRewrites)();
return (0, get_localized_url_path_1.getLocalizedUrlPath)(rewrites, locale, urlPath);
}
exports.useLocalizedUrl = useLocalizedUrl;

@@ -15,5 +15,5 @@ "use strict";

function useRewrites() {
const [rewrites, setRewrites] = react_1.useState([]);
react_1.useEffect(() => {
route_loader_1.getClientBuildManifest()
const [rewrites, setRewrites] = (0, react_1.useState)([]);
(0, react_1.useEffect)(() => {
(0, route_loader_1.getClientBuildManifest)()
.then((clientBuildManifest) => {

@@ -20,0 +20,0 @@ // Next.js needs to add types https://github.com/vercel/next.js/blob/d130f63c416b21adc67dc3c755ad6e1a707e2cc8/packages/next/build/webpack/plugins/build-manifest-plugin.ts#L41

@@ -143,3 +143,3 @@ "use strict";

function getPreferredLocale(acceptLanguageHeader, actualLocales, actualDefaultLocale) {
return resolve_accept_language_1.default(acceptLanguageHeader, actualLocales, actualDefaultLocale);
return (0, resolve_accept_language_1.default)(acceptLanguageHeader, actualLocales, actualDefaultLocale);
}

@@ -146,0 +146,0 @@ exports.getPreferredLocale = getPreferredLocale;

@@ -22,5 +22,5 @@ "use strict";

function MulLink({ children, href, locale, ...props }) {
const router = router_1.useRouter();
const router = (0, router_1.useRouter)();
locale = locale ? locale : router.locale;
const localizedUrl = use_localized_url_1.useLocalizedUrl(locale, href);
const localizedUrl = (0, use_localized_url_1.useLocalizedUrl)(locale, href);
try {

@@ -34,3 +34,3 @@ if (react_1.Children.only(children) && typeof children === 'object' && 'type' in children) {

*/
children = react_1.cloneElement(children, { suppressHydrationWarning: true });
children = (0, react_1.cloneElement)(children, { suppressHydrationWarning: true });
}

@@ -41,4 +41,4 @@ }

}
return (jsx_runtime_1.jsx(link_1.default, Object.assign({ href: localizedUrl, locale: locale }, props, { children: children }), void 0));
return ((0, jsx_runtime_1.jsx)(link_1.default, Object.assign({ href: localizedUrl, locale: locale }, props, { children: children }), void 0));
}
exports.MulLink = MulLink;

@@ -28,7 +28,7 @@ "use strict";

function MulLink({ href, locale, ...props }) {
const router = router_1.useRouter();
const router = (0, router_1.useRouter)();
locale = locale ? locale : router.locale;
const localizedUrl = get_localized_url_path_1.getLocalizedUrlPath(get_rewrites_1.getRewrites(), locale, href);
return jsx_runtime_1.jsx(link_1.default, Object.assign({ href: localizedUrl, locale: locale }, props), void 0);
const localizedUrl = (0, get_localized_url_path_1.getLocalizedUrlPath)((0, get_rewrites_1.getRewrites)(), locale, href);
return (0, jsx_runtime_1.jsx)(link_1.default, Object.assign({ href: localizedUrl, locale: locale }, props), void 0);
}
exports.MulLink = MulLink;

@@ -70,3 +70,3 @@ "use strict";

function getMessages(propertiesFilePath) {
const keyValueObject = properties_1.parsePropertiesFile(propertiesFilePath);
const keyValueObject = (0, properties_1.parsePropertiesFile)(propertiesFilePath);
let context;

@@ -117,3 +117,3 @@ const compactedKeyValueObject = {};

function getBabelifiedMessages(sourceFilePath) {
const parsedSourceFile = path_1.parse(sourceFilePath);
const parsedSourceFile = (0, path_1.parse)(sourceFilePath);
const sourceFileDirectoryPath = parsedSourceFile.dir;

@@ -123,3 +123,3 @@ const sourceFilename = parsedSourceFile.name;

const fileRegExp = new RegExp(`^${sourceFilename}.(?<locale>[\\w-]+).properties$`);
fs_1.readdirSync(sourceFileDirectoryPath, { withFileTypes: true }).forEach((directoryEntry) => {
(0, fs_1.readdirSync)(sourceFileDirectoryPath, { withFileTypes: true }).forEach((directoryEntry) => {
if (directoryEntry.isFile()) {

@@ -130,3 +130,3 @@ const directoryEntryFilename = directoryEntry.name;

const locale = regExpMatch.groups.locale;
const propertiesFilePath = path_1.resolve(sourceFileDirectoryPath, directoryEntryFilename);
const propertiesFilePath = (0, path_1.resolve)(sourceFileDirectoryPath, directoryEntryFilename);
babelifiedMessages.keyValueObjectCollection[locale.toLowerCase()] =

@@ -133,0 +133,0 @@ getMessages(propertiesFilePath);

@@ -20,4 +20,4 @@ "use strict";

function getMessagesFilePath(sourceFilePath, locale) {
const { dir: directoryPath, name: filename } = path_1.parse(sourceFilePath);
return path_1.resolve(directoryPath, `${filename}.${__1.normalizeLocale(locale)}.properties`);
const { dir: directoryPath, name: filename } = (0, path_1.parse)(sourceFilePath);
return (0, path_1.resolve)(directoryPath, `${filename}.${(0, __1.normalizeLocale)(locale)}.properties`);
}

@@ -34,5 +34,5 @@ exports.getMessagesFilePath = getMessagesFilePath;

function getSourceFilePath(messageFilePath, sourceFileExtension) {
const messagesFile = path_1.parse(messageFilePath);
const messagesFile = (0, path_1.parse)(messageFilePath);
const sourceFilename = messagesFile.name.split('.').slice(0, -1).join('.');
return path_1.resolve(messagesFile.dir, `${sourceFilename}${sourceFileExtension}`);
return (0, path_1.resolve)(messagesFile.dir, `${sourceFilename}${sourceFileExtension}`);
}

@@ -142,9 +142,9 @@ exports.getSourceFilePath = getSourceFilePath;

}
const { locale } = router_1.useRouter();
const { locale } = (0, router_1.useRouter)();
const babelifiedMessages = this;
const sourceFilePath = babelifiedMessages.sourceFilePath;
const parsedSourceFile = path_1.parse(sourceFilePath);
const parsedSourceFile = (0, path_1.parse)(sourceFilePath);
const sourceFileDirectoryPath = parsedSourceFile.dir;
const messagesFilename = `${parsedSourceFile.name}.${__1.normalizeLocale(locale)}.properties`;
const messagesFilePath = path_1.resolve(sourceFileDirectoryPath, messagesFilename);
const messagesFilename = `${parsedSourceFile.name}.${(0, __1.normalizeLocale)(locale)}.properties`;
const messagesFilePath = (0, path_1.resolve)(sourceFileDirectoryPath, messagesFilename);
if (!babelifiedMessages.keyValueObjectCollection[locale]) {

@@ -151,0 +151,0 @@ __2.log.warn(`unable to use \`useMessages()\` in \`${babelifiedMessages.sourceFilePath}\` because the messages file was not found at \`${messagesFilePath}\``);

@@ -14,5 +14,5 @@ "use strict";

function parsePropertiesFile(filePath) {
const fileContent = fs_1.readFileSync(filePath, 'utf8');
return dot_properties_1.parse(fileContent);
const fileContent = (0, fs_1.readFileSync)(filePath, 'utf8');
return (0, dot_properties_1.parse)(fileContent);
}
exports.parsePropertiesFile = parsePropertiesFile;
{
"name": "next-multilingual",
"description": "An opinionated end-to-end multilingual solution for Next.js.",
"version": "0.1.0",
"version": "0.1.1",
"license": "MIT",

@@ -72,18 +72,19 @@ "main": "lib/index.js",

"lint": "eslint --ext js,jsx,ts,tsx --fix",
"release": "dotenv release-it --only-version"
"release": "dotenv -- release-it --only-version"
},
"dependencies": {
"chokidar": "^3.5.1",
"chokidar": "^3.5.2",
"dot-properties": "^1.0.1",
"nookies": "^2.5.2",
"resolve-accept-language": "^1.0.25"
"resolve-accept-language": "^1.0.31"
},
"devDependencies": {
"@babel/core": "^7.15.0",
"@release-it/conventional-changelog": "^3.3.0",
"@types/babel__core": "^7.1.15",
"@types/node": "^16.6.1",
"@types/react": "^17.0.17",
"@types/node": "^16.7.4",
"@types/react": "^17.0.19",
"@types/react-dom": "^17.0.9",
"@typescript-eslint/eslint-plugin": "^4.29.1",
"@typescript-eslint/parser": "^4.29.1",
"@typescript-eslint/eslint-plugin": "^4.29.3",
"@typescript-eslint/parser": "^4.29.3",
"dotenv-cli": "^4.0.0",

@@ -93,6 +94,6 @@ "eslint": "^7.32.0",

"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-prettier": "^3.4.1",
"eslint-plugin-react-hooks": "^4.2.0",
"express": "^4.17.1",
"husky": "^7.0.1",
"husky": "^7.0.2",
"lint-staged": "^11.1.2",

@@ -104,3 +105,4 @@ "next": "^11.1.0",

"react-dom": "^17.0.2",
"typescript": "^4.3.5"
"release-it": "^14.11.5",
"typescript": "^4.4.2"
},

@@ -107,0 +109,0 @@ "husky": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc