forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This serves to correct a specific issue related to multiple locales being specified in the pathname as well as some general i18n improvements. - Multiple locales are now parsed correctly (only taking the first locale, treating the rest of the string as the pathname) - `LocaleRouteNormalizer` has been split into `I18NProvider` and `LocaleRouteNormalizer` (tests added) - Adjusted the `I18NProvider.analyze` method (previously `LocaleRouteNormalizer.match`) to require the `defaultLocale: string | undefined` to ensure consistent behaviour - Added more comments around i18n
- Loading branch information
Showing
21 changed files
with
546 additions
and
253 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
packages/next/src/server/future/helpers/i18n-provider.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { I18NProvider } from './i18n-provider' | ||
|
||
describe('I18NProvider', () => { | ||
const provider = new I18NProvider({ | ||
defaultLocale: 'en', | ||
locales: ['en', 'fr', 'en-CA'], | ||
domains: [ | ||
{ | ||
domain: 'example.com', | ||
defaultLocale: 'en', | ||
locales: ['en-CA'], | ||
}, | ||
{ | ||
domain: 'example.fr', | ||
defaultLocale: 'fr', | ||
}, | ||
], | ||
}) | ||
|
||
it('should detect the correct domain locale', () => { | ||
expect(provider.detectDomainLocale('example.com')).toEqual({ | ||
domain: 'example.com', | ||
defaultLocale: 'en', | ||
locales: ['en-CA'], | ||
}) | ||
expect(provider.detectDomainLocale('example.fr')).toEqual({ | ||
domain: 'example.fr', | ||
defaultLocale: 'fr', | ||
}) | ||
expect(provider.detectDomainLocale('example.de')).toBeUndefined() | ||
}) | ||
|
||
describe('analyze', () => { | ||
it('should detect the correct default locale', () => { | ||
expect(provider.analyze('/fr', { defaultLocale: undefined })).toEqual({ | ||
pathname: '/', | ||
detectedLocale: 'fr', | ||
}) | ||
expect( | ||
provider.analyze('/fr/another/page', { defaultLocale: undefined }) | ||
).toEqual({ | ||
pathname: '/another/page', | ||
detectedLocale: 'fr', | ||
}) | ||
expect( | ||
provider.analyze('/another/page', { | ||
defaultLocale: 'en-CA', | ||
}) | ||
).toEqual({ | ||
pathname: '/another/page', | ||
detectedLocale: 'en-CA', | ||
}) | ||
expect( | ||
provider.analyze('/en/another/page', { | ||
defaultLocale: 'en-CA', | ||
}) | ||
).toEqual({ | ||
pathname: '/another/page', | ||
detectedLocale: 'en', | ||
}) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.