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.7.3 to 0.7.4

15

lib/index.d.ts

@@ -1,4 +0,2 @@

/// <reference types="node" />
import type { NextPageContext } from 'next';
import type { ParsedUrlQuery } from 'querystring';
/**

@@ -122,14 +120,1 @@ * Wrapper in front of Next.js' log to only show messages in non-production environments.

export declare function getCookieLocale(nextPageContext: NextPageContext, actualLocales: string[]): string;
/**
* Hydrate a URL back with its query values.
*
* This allows to re-inject dynamic routes values back into URLs.
*
* @see https://nextjs.org/docs/routing/dynamic-routes
*
* @param pathname - The `pathname` property coming from Next.js' `useRouter()`.
* @param query - The `query` property coming from Next.js' `useRouter()`.
*
* @returns The hydrated URL containing `query` values instead of placeholders.
*/
export declare function hydrateUrlQuery(pathname: string, query: ParsedUrlQuery): string;

25

lib/index.js

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.hydrateUrlQuery = exports.getCookieLocale = exports.setCookieLocale = exports.getPreferredLocale = exports.normalizeLocale = exports.isLocale = exports.getActualDefaultLocale = exports.getActualLocales = exports.getActualLocale = exports.highlight = exports.log = void 0;
exports.getCookieLocale = exports.setCookieLocale = exports.getPreferredLocale = exports.normalizeLocale = exports.isLocale = exports.getActualDefaultLocale = exports.getActualLocales = exports.getActualLocale = exports.highlight = exports.log = void 0;
const resolve_accept_language_1 = __importDefault(require("resolve-accept-language"));

@@ -201,24 +201,1 @@ const nookies_1 = __importDefault(require("nookies"));

exports.getCookieLocale = getCookieLocale;
/**
* Hydrate a URL back with its query values.
*
* This allows to re-inject dynamic routes values back into URLs.
*
* @see https://nextjs.org/docs/routing/dynamic-routes
*
* @param pathname - The `pathname` property coming from Next.js' `useRouter()`.
* @param query - The `query` property coming from Next.js' `useRouter()`.
*
* @returns The hydrated URL containing `query` values instead of placeholders.
*/
function hydrateUrlQuery(pathname, query) {
if (!query || !Object.entries(query).length) {
return pathname;
}
let usableUrl = pathname;
for (const [queryName, queryValue] of Object.entries(query)) {
usableUrl = usableUrl.replace(`[${queryName}]`, queryValue);
}
return usableUrl;
}
exports.hydrateUrlQuery = hydrateUrlQuery;

2

package.json
{
"name": "next-multilingual",
"description": "An opinionated end-to-end solution for Next.js applications that requires multiple languages.",
"version": "0.7.3",
"version": "0.7.4",
"license": "MIT",

@@ -6,0 +6,0 @@ "main": "lib/index.js",

@@ -706,3 +706,3 @@ # ![next-multilingual](./assets/next-multilingual-banner.svg)

[Dynamic routes](https://nextjs.org/docs/routing/dynamic-routes) are very common and supported out of the box by Next.js. When using multilingual URLs, supporting dynamic routes only requires using the `hydrateUrlQuery` function available from the `next-multilingual` module. This function does simply re-injects back the value of the parameters into the localized URLs. It should mostly be used in a language picker, as in this example:
[Dynamic routes](https://nextjs.org/docs/routing/dynamic-routes) are very common and supported out of the box by Next.js. When using multilingual URLs, supporting dynamic routes only requires using the `asPath` property available from Nextj.js' `useRouter()` hook. Here is an example of how it can be used in a language picker:

@@ -719,3 +719,2 @@ ```tsx

import { MulLink } from 'next-multilingual/link';
import { hydrateUrlQuery } from 'next-multilingual';

@@ -729,6 +728,5 @@ // Locales don't need to be localized.

export default function LanguagePicker(): ReactElement {
const { pathname, locale, locales, defaultLocale, query } = useRouter();
const { locale, locales, defaultLocale, asPath } = useRouter();
const actualLocale = getActualLocale(locale, defaultLocale, locales);
const actualLocales = getActualLocales(locales, defaultLocale);
const href = hydrateUrlQuery(pathname, query);

@@ -746,3 +744,3 @@ return (

return (
<MulLink key={locale} href={href} locale={locale}>
<MulLink key={locale} href={asPath} locale={locale}>
<a

@@ -764,3 +762,3 @@ onClick={() => {

This allows a seamless experience across localized URLs when using a simple parameters such as a unique (numerical) identifiers. If your parameter itself needs to be localized, you will have to handle that logic yourself before rehydrating the URLs.
This allows a seamless experience across localized URLs when using a simple parameters such as a unique (numerical) identifiers. If your parameter itself needs to be localized, you will have to handle that logic yourself.

@@ -767,0 +765,0 @@ A fully working example can be found in the [language picker component example](./example/components/LanguagePicker.tsx).

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