Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add .ts and .js as supported file extensions #1576

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions specs/fixtures/lazy/lang/pl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
home: 'Strona główna',
about: 'O nas',
posts: 'Publikacje',
dynamic: 'Dynamiczne'
}
45 changes: 41 additions & 4 deletions specs/lazy_load.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ await setup({
iso: 'fr-FR',
file: 'fr.json5',
name: 'Français'
},
{
code: 'pl',
iso: 'pl-PL',
file: 'pl.ts',
name: 'Polski'
}
]
}
Expand All @@ -41,12 +47,14 @@ test('can access to no prefix locale (en): /', async () => {
expect(await getText(page, '#link-about')).toEqual('About us')

// lang switcher rendering
expect(await getText(page, '#lang-switcher-with-nuxt-link a')).toEqual('Français')
expect(await getText(page, '#lang-switcher-with-nuxt-link a >> nth=0')).toEqual('Français')
expect(await getText(page, '#lang-switcher-with-nuxt-link a >> nth=1')).toEqual('Polski')
expect(await getText(page, '#set-locale-link-fr')).toEqual('Français')

// page path
expect(await getData(page, '#home-use-async-data')).toMatchObject({ aboutPath: '/about' })
expect(await page.getAttribute('#lang-switcher-with-nuxt-link a', 'href')).toEqual('/fr')
expect(await page.getAttribute('#lang-switcher-with-nuxt-link a >> nth=0', 'href')).toEqual('/fr')
expect(await page.getAttribute('#lang-switcher-with-nuxt-link a >> nth=1', 'href')).toEqual('/pl')

// current locale
expect(await getText(page, '#lang-switcher-current-locale code')).toEqual('en')
Expand All @@ -66,16 +74,45 @@ test('can access to prefix locale: /fr', async () => {
expect(await getText(page, '#link-about')).toEqual('À propos')

// lang switcher rendering
expect(await getText(page, '#lang-switcher-with-nuxt-link a')).toEqual('English')
expect(await getText(page, '#lang-switcher-with-nuxt-link a >> nth=0')).toEqual('English')
expect(await getText(page, '#lang-switcher-with-nuxt-link a >> nth=1')).toEqual('Polski')
expect(await getText(page, '#set-locale-link-en')).toEqual('English')

// page path
expect(await getData(page, '#home-use-async-data')).toMatchObject({ aboutPath: '/fr/about' })
expect(await page.getAttribute('#lang-switcher-with-nuxt-link a', 'href')).toEqual('/')
expect(await page.getAttribute('#lang-switcher-with-nuxt-link a >> nth=0', 'href')).toEqual('/')
expect(await page.getAttribute('#lang-switcher-with-nuxt-link a >> nth=1', 'href')).toEqual('/pl')

// current locale
expect(await getText(page, '#lang-switcher-current-locale code')).toEqual('fr')

// html tag `lang` attriute with iso code
expect(await page.getAttribute('html', 'lang')).toEqual('fr-FR')
})

test('can access to prefix locale: /pl', async () => {
const home = url('/pl')
const page = await createPage()
await page.goto(home)

// `pl` rendering
expect(await getText(page, '#home-header')).toEqual('Strona główna')
expect(await getText(page, 'title')).toEqual('Strona główna')
expect(await getText(page, '#link-about')).toEqual('O nas')

// lang switcher rendering
expect(await getText(page, '#lang-switcher-with-nuxt-link a >> nth=0')).toEqual('English')
expect(await getText(page, '#lang-switcher-with-nuxt-link a >> nth=1')).toEqual('Français')
expect(await getText(page, '#set-locale-link-fr')).toEqual('Français')

// page path
expect(await getData(page, '#home-use-async-data')).toMatchObject({ aboutPath: '/pl/about' })
expect(await page.getAttribute('#lang-switcher-with-nuxt-link a >> nth=0', 'href')).toEqual('/')
expect(await page.getAttribute('#lang-switcher-with-nuxt-link a >> nth=1', 'href')).toEqual('/fr')

// current locale
expect(await getText(page, '#lang-switcher-current-locale code')).toEqual('pl')

// html tag `lang` attriute with iso code
expect(await page.getAttribute('html', 'lang')).toEqual('pl-PL')
})
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function getNormalizedLocales(locales: NuxtI18nOptions['locales']): Local
}

export async function resolveLocales(path: string, locales: LocaleObject[]): Promise<LocaleInfo[]> {
const files = await resolveFiles(path, '**/*{json,json5,yaml,yml}')
const files = await resolveFiles(path, '**/*{json,json5,yaml,yml,js,ts}')
return files.map(file => {
const parsed = parse(file)
const locale = findLocales(locales, parsed.base)
Expand Down