next-multilingual
Advanced tools
Comparing version 0.7.0 to 0.7.1
@@ -94,7 +94,7 @@ import type { Rewrite, Redirect } from 'next/dist/lib/load-custom-routes'; | ||
/** | ||
* Is a specific directory path under Next.js' API routes directory. | ||
* Is a multilingual route identifier an API Route? | ||
* | ||
* @param directoryPath - A directory path relative to Next.js' `pages` directory. | ||
* @param identifier - A unique multilingual route identifier. | ||
* | ||
* @return True if the directory path is under Next.js' API routes directory, otherwise false. | ||
* @return True if the multilingual route identifier is an API Route, otherwise false. | ||
*/ | ||
@@ -101,0 +101,0 @@ private isApiRoute; |
@@ -219,12 +219,10 @@ "use strict"; | ||
/** | ||
* Is a specific directory path under Next.js' API routes directory. | ||
* Is a multilingual route identifier an API Route? | ||
* | ||
* @param directoryPath - A directory path relative to Next.js' `pages` directory. | ||
* @param identifier - A unique multilingual route identifier. | ||
* | ||
* @return True if the directory path is under Next.js' API routes directory, otherwise false. | ||
* @return True if the multilingual route identifier is an API Route, otherwise false. | ||
*/ | ||
isApiRoute(directoryPath) { | ||
const ApiRouteDirectory = `${path_1.sep}api`; | ||
return (directoryPath === ApiRouteDirectory || | ||
directoryPath.startsWith(`${ApiRouteDirectory}${path_1.sep}`)); | ||
isApiRoute(identifier) { | ||
return identifier === '/api' || identifier.startsWith('/api/'); | ||
} | ||
@@ -240,15 +238,16 @@ /** | ||
getRoutes(baseDirectoryPath = this.pagesDirectoryPath, currentDirectoryPath = this.pagesDirectoryPath, routes = []) { | ||
if (this.isApiRoute(currentDirectoryPath.replace(baseDirectoryPath, ''))) { | ||
return; // Skip if the directory is under Next.js' API routes directory. | ||
const rootRelativePath = currentDirectoryPath.replace(baseDirectoryPath, ''); | ||
const identifier = fileSystemPathToUrlPath(rootRelativePath); | ||
if (this.isApiRoute(identifier)) { | ||
return; // Skip if the identifier it's a Next.js' API Route. | ||
} | ||
// When there is a directory without pages, we can localized it using "index" messages files. | ||
// When there is a directory without pages, we can localize it using "index" messages files. | ||
if (!this.directoryContainsPages(currentDirectoryPath)) { | ||
const directoryEntryPath = (0, path_1.resolve)(currentDirectoryPath, 'index'); | ||
const identifier = fileSystemPathToUrlPath(currentDirectoryPath.replace(baseDirectoryPath, '')); | ||
this.addRoute(directoryEntryPath, identifier, routes); | ||
} | ||
// Read through all the files of the current directory and look for pages or sub-directories. | ||
// Add pages routes from the current directory. | ||
(0, fs_1.readdirSync)(currentDirectoryPath, { withFileTypes: true }).forEach((directoryEntry) => { | ||
const directoryEntryPath = (0, path_1.resolve)(currentDirectoryPath, directoryEntry.name); | ||
if (directoryEntry.isFile()) { | ||
const directoryEntryPath = (0, path_1.resolve)(currentDirectoryPath, directoryEntry.name); | ||
const directoryEntryExtension = (0, path_1.extname)(directoryEntryPath); | ||
@@ -269,4 +268,7 @@ if (!this.pagesExtensions.includes(directoryEntryExtension)) { | ||
} | ||
else if (directoryEntry.isDirectory()) { | ||
// If the entry is a directory, call recursively to build child routes. | ||
}); | ||
// Look for sub-directories to build child routes. | ||
(0, fs_1.readdirSync)(currentDirectoryPath, { withFileTypes: true }).forEach((directoryEntry) => { | ||
if (directoryEntry.isDirectory()) { | ||
const directoryEntryPath = (0, path_1.resolve)(currentDirectoryPath, directoryEntry.name); | ||
this.getRoutes(baseDirectoryPath, directoryEntryPath, routes); | ||
@@ -297,3 +299,3 @@ } | ||
} | ||
return keyValueObject[slugKey].replace(/[ /-]+/g, '-').toLocaleLowerCase(); | ||
return keyValueObject[slugKey].replace(/[ /-']+/g, '-').toLocaleLowerCase(); | ||
} | ||
@@ -300,0 +302,0 @@ /** |
{ | ||
"name": "next-multilingual", | ||
"description": "An opinionated end-to-end solution for Next.js applications that requires multiple languages.", | ||
"version": "0.7.0", | ||
"version": "0.7.1", | ||
"license": "MIT", | ||
@@ -94,3 +94,3 @@ "main": "lib/index.js", | ||
"eslint": "^8.1.0", | ||
"eslint-config-next": "^v11.1.3-canary.97", | ||
"eslint-config-next": "v11.1.3-canary.67", | ||
"eslint-config-prettier": "^8.3.0", | ||
@@ -102,3 +102,3 @@ "eslint-plugin-prettier": "^4.0.0", | ||
"lint-staged": "^11.2.4", | ||
"next": "^v11.1.3-canary.97", | ||
"next": "v11.1.3-canary.67", | ||
"npm-watch": "^0.11.0", | ||
@@ -105,0 +105,0 @@ "prettier": "^2.4.1", |
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
2258
143680