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

feat: support server-side i18n integration #2558

Merged
merged 50 commits into from
Dec 7, 2023
Merged
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
b186708
feat: support server-side i18n integration
kazupon Nov 16, 2023
96eb3a3
fix: locale detector loading on server-side
kazupon Nov 16, 2023
de37cd0
refactor
kazupon Nov 16, 2023
4c760a0
merge from main branch
kazupon Nov 16, 2023
2e3f2e0
fix: more deps
kazupon Nov 16, 2023
8a29b9a
fix: cannot bundle intlify/core
kazupon Nov 22, 2023
69866ca
fix: initial options loading
kazupon Nov 23, 2023
01b8c44
refactor: function name
kazupon Nov 23, 2023
33fea31
Merge branch 'main' into feat/intlify-h3-integration2
kazupon Nov 23, 2023
dd33773
refactor: remove context
kazupon Nov 23, 2023
809b837
fix: type errors
kazupon Nov 23, 2023
6f252cf
refactor: argument ordering
kazupon Nov 23, 2023
3fc1bd7
fix: pass user cache messages
kazupon Nov 23, 2023
3b5c833
fix: wrong judgement enabling
kazupon Nov 24, 2023
a0f5b64
fix: not work useRuntimeConfig
kazupon Nov 24, 2023
153ee61
Merge branch 'main' into feat/intlify-h3-integration3
kazupon Nov 25, 2023
0a7399c
feat: `useRuntimeConfig` support (#2572)
BobbieGoede Nov 25, 2023
181e1c4
fix: spec tests
kazupon Nov 25, 2023
0ec9b0a
chore: bump nitropack
kazupon Nov 25, 2023
75eb4a9
fix: salvage basic_usage.spec.ts
kazupon Nov 25, 2023
01bb141
fix: Avoid order broken of `vueI18nConfigPaths`
kazupon Nov 25, 2023
6c162d3
fix: type error
kazupon Nov 25, 2023
1ae6f0f
refactor: move to messages
kazupon Nov 25, 2023
1df540b
fix: lazy load implementation
kazupon Nov 28, 2023
a2a9992
fix: i18n resources always lazy loading for nitro side
kazupon Nov 28, 2023
d5cae4a
fix: reduce resource size for nitropack bundling
kazupon Nov 28, 2023
cb5f834
fix: drop import assetion
kazupon Nov 28, 2023
834b1ab
refactor
kazupon Nov 28, 2023
2f93b94
fix: h3 integration layer support (#2589)
BobbieGoede Dec 4, 2023
fbfab0b
Merge branch 'main' into feat/intlify-h3-integration
kazupon Dec 5, 2023
d02ab1c
chore: update deps
kazupon Dec 5, 2023
9a37015
chore: upgrade vitest
kazupon Dec 5, 2023
f8543cc
fix: cannot resolve type for intlify/h3 utilites
kazupon Dec 5, 2023
1ea7efb
fix: bump intlify/h3 and utilts
kazupon Dec 6, 2023
502b088
fix: tweak locale detector for playground
kazupon Dec 6, 2023
f1c1d55
refactor
kazupon Dec 6, 2023
cecac24
add `defineI18nLocaleDetector` composable
kazupon Dec 6, 2023
27ed64e
docs: add `useTranslation`
kazupon Dec 6, 2023
fd8c141
fix: remove console log
kazupon Dec 6, 2023
bf5fab0
docs: update server-side translations
kazupon Dec 6, 2023
5ef3b4c
Update docs/content/2.guide/16.server-side-translations.md
kazupon Dec 6, 2023
955e0fd
Update docs/content/2.guide/16.server-side-translations.md
kazupon Dec 6, 2023
14b9d5b
Update docs/content/2.guide/16.server-side-translations.md
kazupon Dec 6, 2023
990a52e
Update docs/content/2.guide/16.server-side-translations.md
kazupon Dec 6, 2023
1ae12b0
Update docs/content/4.API/1.composables.md
kazupon Dec 6, 2023
551ecea
Update docs/content/4.API/1.composables.md
kazupon Dec 6, 2023
d1454f9
Update docs/content/4.API/1.composables.md
kazupon Dec 6, 2023
f92b9a6
Update docs/content/4.API/1.composables.md
kazupon Dec 6, 2023
88f1a98
Update docs/content/4.API/1.composables.md
kazupon Dec 6, 2023
1520ad2
Update docs/content/2.guide/16.server-side-translations.md
kazupon Dec 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: spec tests
  • Loading branch information
kazupon committed Nov 25, 2023
commit 181e1c4936730470634148774dd299efc253d89e
126 changes: 14 additions & 112 deletions specs/basic_usage.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
import { test, expect } from 'vitest'
import { fileURLToPath } from 'node:url'
import { setup } from './utils'
import { assetLocaleHead, getData, getText, gotoPath, renderPage, waitForURL } from './helper'
import { getData, getText, gotoPath, renderPage, waitForURL } from './helper'

await setup({
rootDir: fileURLToPath(new URL(`./fixtures/basic_usage`, import.meta.url)),
browser: true,
// prerender: true,
// overrides
nuxtConfig: {}
nuxtConfig: {
extends: [
fileURLToPath(new URL(`./fixtures/layers/layer-lazy`, import.meta.url)),
fileURLToPath(new URL(`./fixtures/layers/layer-vueI18n-options/layer-simple`, import.meta.url)),
fileURLToPath(new URL(`./fixtures/layers/layer-vueI18n-options/layer-simple-secondary`, import.meta.url))
],
i18n: {
locales: ['en', 'fr'],
defaultLocale: 'en'
}
}
})

test('basic usage', async () => {
Expand Down Expand Up @@ -97,8 +107,8 @@ test('layer vueI18n options properties are merge and override by priority', asyn

await page.click(`#switch-locale-path-usages .switch-to-fr a`)
await waitForURL(page, '/fr')
expect(await getText(page, '#snake-case')).toEqual('Γ€-propos-de-ce-site')
expect(await getText(page, '#pascal-case')).toEqual('Γ€ProposDeCeSite')
expect(await getText(page, '#snake-case')).toEqual('Should-be-overridden')
expect(await getText(page, '#pascal-case')).toEqual('ShouldBeOverridden')
BobbieGoede marked this conversation as resolved.
Show resolved Hide resolved
expect(await getText(page, '#fallback-message')).toEqual('Unique translation')
})

Expand Down Expand Up @@ -188,111 +198,3 @@ test('(#2476) Parametrized messages can be overwritten', async () => {
expect(await getText(page, '#module-layer-base-key')).toEqual('Layer base key overwritten!')
expect(await getText(page, '#module-layer-base-key-named')).toEqual('Layer base key overwritten, greetings bar!')
})

test('(#2338) should be extended API', async () => {
const { page } = await renderPage('/')

const globalData = await getData(page, '#global-scope-properties')
expect(globalData.code).toEqual('en')
const localeData = await getData(page, '#local-scope-properties')
expect(localeData.code).toEqual('en')
})

test('<NuxtLink> triggers runtime hooks', async () => {
const { page, consoleLogs } = await renderPage('/kr')

// click `fr` lang switch with `<NuxtLink>`
await page.locator('#nuxt-locale-link-fr').click()
await waitForURL(page, '/fr')

// click `kr` lang switch with `<NuxtLink>`
await page.locator('#nuxt-locale-link-kr').click()
await waitForURL(page, '/kr')

expect(consoleLogs.find(log => log.text.includes('onBeforeLanguageSwitch kr fr true'))).toBeTruthy()
expect(consoleLogs.find(log => log.text.includes('onBeforeLanguageSwitch fr kr false'))).toBeTruthy()
expect(consoleLogs.find(log => log.text.includes('onLanguageSwitched kr fr'))).toBeTruthy()

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

// navigate to about page
await page.locator('#link-about').click()
await waitForURL(page, '/fr/about')

// navigate to home page
await page.locator('#link-home').click()
await waitForURL(page, '/fr')
})

test('setLocale triggers runtime hooks', async () => {
const { page, consoleLogs } = await renderPage('/kr')

// click `fr` lang switch link
await page.locator('#set-locale-link-fr').click()

// click `kr` lang switch link
// Hook prevents locale change to `kr`, stays `fr`
await page.locator('#set-locale-link-kr').click()
expect(consoleLogs.find(log => log.text.includes('onBeforeLanguageSwitch kr fr true'))).toBeTruthy()
expect(consoleLogs.find(log => log.text.includes('onLanguageSwitched kr fr'))).toBeTruthy()
expect(consoleLogs.find(log => log.text.includes('onBeforeLanguageSwitch fr kr false'))).toBeTruthy()

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

test('render with meta components', async () => {
const { page } = await renderPage('/')

/**
* default locale
*/

// title tag
expect(await getText(page, 'title')).toMatch('Page - Homepage')
await waitForURL(page, '/')

// html tag `lang` attribute
expect(await page.getAttribute('html', 'lang')).toMatch('en')

// html tag `dir` attribute
expect(await page.getAttribute('html', 'dir')).toMatch('ltr')

// rendering link tag and meta tag in head tag
await assetLocaleHead(page, '#layout-use-locale-head')

/**
* change locale
*/

// click `fr` lang switch link
await page.locator('#nuxt-locale-link-fr').click()
await waitForURL(page, '/fr')

// title tag
expect(await getText(page, 'title')).toMatch('Page - Accueil')

// html tag `lang` attribute
expect(await page.getAttribute('html', 'lang')).toMatch('fr')

// rendering link tag and meta tag in head tag
await assetLocaleHead(page, '#layout-use-locale-head')

/**
* access to other page
*/

// click about page
await page.locator('#link-about').click()
await waitForURL(page, '/fr/about')

// title tag
expect(await getText(page, 'title')).toMatch('Page - Γ€ propos')

// html tag `lang` attribute
expect(await page.getAttribute('html', 'lang')).toMatch('fr')

// rendering link tag and meta tag in head tag
await assetLocaleHead(page, '#layout-use-locale-head')
})