Compare commits

...
Author SHA1 Message Date
github-actions[bot] f8f4494527 Version Packages 2023-10-10 21:46:16 +00:00
Sasha Sorokin fe75e7ca94 Explicitly pass build subcommand to nuxt-module-build 2023-10-10 23:41:44 +02:00
Sasha Sorokin a9fdc595f5 Update VIntl Unplugin to 1.5.0 2023-10-10 23:39:42 +02:00
github-actions[bot] eee372b21e Version Packages 2023-10-10 04:21:08 +00:00
renovate[bot]andGitHub 220a9cbf00 Update all non-major dependencies 2023-10-10 04:08:51 +00:00
Sasha Sorokin 81c23b0b8d Add support for parsing error handling 2023-10-10 06:02:11 +02:00
Sasha Sorokin 2b5a59b33d Unpin FormatJS dependencies 2023-10-09 02:29:16 +02:00
renovate[bot]andGitHub d8dabcf62e Update all non-major dependencies 2023-10-08 21:07:47 +00:00
renovate[bot]andGitHub 02281aa6c7 Update actions/checkout action to v4 2023-10-08 20:18:27 +00:00
renovate[bot]GitHubrenovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
ef16a887d2 Update devDependency prettier-plugin-jsdoc to v1 (#51)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-10-07 19:49:33 +02:00
github-actions[bot]GitHubgithub-actions[bot] <github-actions[bot]@users.noreply.github.com>
880cb1972d Version Packages (#60)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-09-11 20:05:29 +02:00
Sasha Sorokin 979f2bdedd Add more SEO options 2023-09-11 19:59:11 +02:00
Sasha Sorokin 7cb833df1e Switch to bundler module resolution 2023-09-11 19:35:14 +02:00
Sasha SorokinandGitHub 682133f893 Add Bing verification file (#53) 2023-08-21 05:00:27 +02:00
renovate[bot]GitHubrenovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
9bff4db4c1 Update typescript-eslint monorepo to v6 (#52)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-08-11 03:47:58 +02:00
22 changed files with 3318 additions and 1790 deletions
+1 -1
View File
@@ -22,7 +22,7 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v3
+1 -1
View File
@@ -10,7 +10,7 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v3
@@ -22,6 +22,7 @@ Represents the VIntl module options.
| `hostLanguageParam` | `'hl'` | **Deprecated.** An optional name of the query parameter used to override the user language (including automatically detected one). It is used to generate SEO meta tags. Using `null` will disable them. |
| `parserless` | `<...>` | An optional [`ParserlessOptions`] object or [`ParserlessMode`] which configures the parserless mode. |
| `seo` | `<...>` | An optional [`SEOOptions`] object which configures automatic head tags to improve discoverability of other languages by search engines. |
| `onParseError` | | An optional [`ParsingErrorHandlingOption`] value that defines how to handle errors that occur when transforming message files. If not defined, the errors are not handled and thrown during the building, preventing it from succeeding. |
[`BroadcastChannel`]: https://developer.mozilla.org/en-US/docs/Web/API/BroadcastChannel
[`ParserlessOptions`]: #parserlessoptions
@@ -154,8 +155,30 @@ Represents options for the automatic head tags.
By default VIntl will add `<link>` tags for every language to make search engines aware of other languages, you can disable this by setting `enabled` to `false`.
| Property | Default | Description |
| :----------------------- | :-----: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `enabled` | `true` | A boolean value representing whether VIntl should automatically add `<link>` tags to `<head>` of the site. These tags make search engines aware that your site is provided in different languages. |
| `hostLanguageParameter`: | `hl` | A string value representing the query parameter that VIntl would use to configure the language of the site. |
| `baseURL` | | **Recommended.** An optional string value representing the base URL of the site. If not set, VIntl will try to guess the URL based on inital request URL or the current `window.location`. |
| Property | Default | Description |
| :-------------------------- | :-----: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `enabled` | `true` | A boolean value representing whether VIntl should automatically add `<link>` tags to `<head>` of the site. These tags make search engines aware that your site is provided in different languages. |
| `hostLanguageParameter`: | `hl` | A string value representing the query parameter that VIntl would use to configure the language of the site. |
| `baseURL` | | **Recommended.** An optional string value representing the base URL of the site. If not set, VIntl will try to guess the URL based on inital request URL or the current `window.location`. |
| `defaultLocaleHasParameter` | `true` | A boolean value representing whether the default locale should have a host language parameter. Disabling this may make URLs of visitors cleaner, however it is not correct, because lack of host language instructs VIntl to use user's language (either the one they've used before or browser's one). |
| `xDefaultHreflang` | `true` | A boolean value representing whether the `x-default` hreflang is present. |
## `ParsingErrorHandlingOption`
[`ParsingErrorHandlingOption`]: #parsingerrorhandlingoption
Represents a value for the message pasing error handling option.
It can be one of the following:
- A string containing a name of the strategy for handling the errors. The following strategies are available:
| Name | Strategy |
| :----------------------- | :-------------------------------------------------------------------------------- |
| `use-message-as-literal` | Use the raw message contents as a literal. |
| `use-id-as-literal` | Use the message ID as a literal. |
| `use-empty-literal` | Use empty string as a literal. |
| `log-and-skip` | Log the error to console and don't include the message into the transformed file. |
| `skip` | Skip including the message into the transformed file. |
- An function that takes in a context for the error (that includes error itself) and optionally returns a fallback AST (not returning anything skips including the message into the transformed file).
+6 -6
View File
@@ -13,14 +13,14 @@
"start": "node .output/server/index.mjs"
},
"devDependencies": {
"@formatjs/cli": "^6.1.2",
"@nuxt-themes/docus": "^1.12.3",
"@nuxt/eslint-config": "^0.1.1",
"@formatjs/cli": "^6.2.0",
"@nuxt-themes/docus": "^1.15.0",
"@nuxt/eslint-config": "^0.2.0",
"@vintl-dev/eslint-config-peony": "workspace:^",
"@vintl/nuxt": "workspace:^",
"eslint": "^8.42.0",
"nuxi": "^3.5.3",
"nuxt": "^3.5.3",
"eslint": "^8.51.0",
"nuxi": "^3.9.0",
"nuxt": "^3.7.4",
"theme-colors": "^0.0.5",
"vue": "^3.3.4"
}
+4
View File
@@ -0,0 +1,4 @@
<?xml version="1.0"?>
<users>
<user>9491DAF6E17F64A987F923EC70F0BAEE</user>
</users>
+3
View File
@@ -1,4 +1,7 @@
{
"broken-message": {
"message": "This is {broken, }"
},
"example": {
"message": "Example"
},
+10
View File
@@ -16,6 +16,11 @@ export default defineNuxtConfig({
format: 'crowdin',
},
],
meta: {
static: {
iso: 'en',
},
},
},
{
tag: 'uk',
@@ -30,5 +35,10 @@ export default defineNuxtConfig({
storage: 'cookie',
broadcastLocaleChange: true,
parserless: 'always',
seo: {
xDefaultHreflang: false,
defaultLocaleHasParameter: false,
},
onParseError: 'log-and-skip',
},
})
+3 -3
View File
@@ -17,8 +17,8 @@
"@vintl-dev/eslint-config-peony": "workspace:^",
"@vintl-dev/pg-messages": "workspace:^",
"@vintl/nuxt": "workspace:^",
"eslint": "^8.42.0",
"nuxi": "^3.5.3",
"nuxt": "^3.5.3"
"eslint": "^8.51.0",
"nuxi": "^3.9.0",
"nuxt": "^3.7.4"
}
}
+4
View File
@@ -27,6 +27,10 @@ const messages = defineMessages({
id: 'index.use-automatic',
defaultMessage: 'Use automatic',
},
brokenMessage: {
id: 'broken-message',
defaultMessage: 'This is {broken, }'
},
} as const)
const vintl = useVIntl()
+3 -3
View File
@@ -7,8 +7,8 @@
"packages/*"
],
"devDependencies": {
"@changesets/cli": "^2.26.1",
"turbo": "^1.10.1"
"@changesets/cli": "^2.26.2",
"turbo": "^1.10.15"
},
"scripts": {
"pg:prepare": "turbo run --no-daemon @vintl-dev/pg#dev:prepare",
@@ -36,5 +36,5 @@
}
}
},
"packageManager": "pnpm@8.6.1"
"packageManager": "pnpm@8.8.0"
}
+7 -7
View File
@@ -26,14 +26,14 @@
"config.json"
],
"dependencies": {
"@rushstack/eslint-patch": "^1.3.0",
"@typescript-eslint/eslint-plugin": "^5.59.9",
"@typescript-eslint/parser": "^5.59.9",
"eslint-plugin-vue": "^9.14.1",
"typescript": "^5.1.3"
"@rushstack/eslint-patch": "^1.5.1",
"@typescript-eslint/eslint-plugin": "^6.7.4",
"@typescript-eslint/parser": "^6.7.4",
"eslint-plugin-vue": "^9.17.0",
"typescript": "^5.2.2"
},
"devDependencies": {
"@types/eslint": "^8.40.0",
"eslint": "^8.42.0"
"@types/eslint": "^8.44.3",
"eslint": "^8.51.0"
}
}
+40
View File
@@ -1,5 +1,45 @@
# @vintl/nuxt
## 1.7.0
### Minor Changes
- a9fdc59: Add support for parsing the messages in the error handlers
With [update to `@vintl/unplugin`](https://github.com/vintl-dev/unplugin/releases/tag/v1.5.0), it's now possible to use `parseMessage` from the error handler's context to parse custom messages or re-parse the current message with any modified options.
## 1.6.0
### Minor Changes
- 81c23b0: Support for parsing error handling
`@vintl/nuxt` can now handle errors when parsing message files containing broken messages in a configurable manner.
You can configure how errors are handled using `onParseError` module option, which can either be a name of the built-in strategy, or a function that takes in context and optionally provides fallback message AST.
Check out documentation for more information.
### Patch Changes
- 2b5a59b: Unpin FormatJS dependencies
We proveviously had `@formatjs/intl` pinned because of the broken ESM migration, however this has been fixed for quite some time already, so the pinned version has been to changed to a range, which ensures that `@formatjs/intl` can be updated with latest bug fixes and improvements until the next major version.
## 1.5.0
### Minor Changes
- 979f2bd: Add more SEO options
Two options have been added to the SEO configuration:
- `defaultLocaleHasParameter` allows to disable the host language parameter for the default locale.
This is not recommended and not correct, because lack of the host language parameter instructs VIntl to use user's language (either the one they've used before or browser's one). However, it may be useful in some cases.
- `xDefaultHreflang` allows to disable the `x-default` hreflang in case it's not useful to have (e.g. you disable the automatic language detection), although this is quite rare.
## 1.4.0
### Minor Changes
+16 -16
View File
@@ -1,6 +1,6 @@
{
"name": "@vintl/nuxt",
"version": "1.4.0",
"version": "1.7.0",
"description": "Nuxt Module for VIntl integration",
"keywords": [
"i18n",
@@ -34,36 +34,36 @@
"dist"
],
"scripts": {
"build": "nuxt-module-build",
"build": "nuxt-module-build build",
"lint": "eslint --cache .",
"prepack": "pnpm run -s lint && pnpm run -s build"
},
"devDependencies": {
"@nuxt/module-builder": "^0.4.0",
"@nuxt/schema": "^3.5.3",
"@nuxt/module-builder": "^0.5.2",
"@nuxt/schema": "^3.7.4",
"@types/hash-sum": "^1.0.0",
"@types/node": "^18.16.16",
"@unhead/vue": "^1.1.27",
"@types/node": "^18.18.4",
"@unhead/vue": "^1.7.4",
"@vintl-dev/eslint-config-peony": "workspace:^",
"hookable": "^5.5.3",
"prettier-plugin-jsdoc": "^0.4.2",
"typescript": "^5.1.3",
"vue-router": "^4.2.4"
"prettier-plugin-jsdoc": "^1.1.0",
"typescript": "^5.2.2",
"vue-router": "^4.2.5"
},
"dependencies": {
"@formatjs/intl": "2.7.2",
"@formatjs/intl-localematcher": "^0.4.0",
"@nuxt/kit": "^3.5.3",
"@vintl/unplugin": "^1.2.4",
"@vintl/vintl": "^4.2.1",
"@formatjs/intl": "^2.9.3",
"@formatjs/intl-localematcher": "^0.4.2",
"@nuxt/kit": "^3.7.4",
"@vintl/unplugin": "^1.5.0",
"@vintl/vintl": "^4.2.3",
"astring": "^1.8.6",
"consola": "^3.1.0",
"consola": "^3.2.3",
"hash-sum": "^2.0.0",
"import-meta-resolve": "^3.0.0",
"pathe": "^1.1.1",
"picocolors": "^1.0.0",
"slash": "^5.1.0",
"ufo": "^1.1.2",
"ufo": "^1.3.1",
"zod": "^3.21.4"
}
}
+21
View File
@@ -124,11 +124,31 @@ export default defineNuxtModule<ModuleOptions>({
const { icuMessages } = await import('@vintl/unplugin')
const onParseError = (() => {
let { onParseError } = options
if (onParseError === 'log-and-skip') {
onParseError = (ctx) => {
consola.warn(
`[vintl] Cannot parse the message "${
ctx.messageId
}" in "${relativizePath(
nuxt.options.srcDir,
ctx.moduleId,
)}". It will me skipped.`,
)
}
}
return onParseError
})()
extendWebpackConfig((cfg) => {
const plugins = (cfg.plugins ??= [])
plugins.push(
...pluginOptionsBank
.createOptions({
onParseError,
output: {
type: parserlessModeEnabled ? 'ast' : 'raw',
},
@@ -143,6 +163,7 @@ export default defineNuxtModule<ModuleOptions>({
...pluginOptionsBank
.createOptions({
pluginsWrapping: true,
onParseError,
output: {
type: parserlessModeEnabled ? 'ast' : 'raw',
},
+17 -13
View File
@@ -1,9 +1,10 @@
import { useHead } from '#imports'
import type { SEOOptions } from '@vintl/nuxt-runtime/options'
import type { IntlController } from '@vintl/vintl/controller'
import { computed } from 'vue'
import type { LocationQuery, useRouter as _useRouter$type } from 'vue-router'
import { useRouter as _useRouter, useRequestURL } from 'nuxt/app'
import { joinURL } from 'ufo'
import { computed } from 'vue'
import type { LocationQuery, useRouter as _useRouter$type } from 'vue-router'
const useRouter = _useRouter as typeof _useRouter$type
@@ -35,10 +36,7 @@ type LangHrefLink = {
href: string
}
interface HeadOptions {
hostLanguageParameter: string
baseURL?: string
}
type HeadOptions = Omit<SEOOptions, 'enabled'>
export function initHead(
controller: IntlController<any>,
@@ -72,27 +70,33 @@ export function initHead(
const query = String(getSeachParams(route.query))
const { path } = route
let defaultEntry: LangHrefLink
const hrefLangs: Map<string, LangHrefLink> = new Map()
{
if (options.xDefaultHreflang) {
const sp = new URLSearchParams(query)
sp.delete(options.hostLanguageParameter)
defaultEntry = {
hrefLangs.set('x-default', {
// key: `hreflang-default`,
rel: 'alternate',
hreflang: 'x-default',
href: normalizeURL(withQueryParams(path, sp.toString())),
}
})
}
const hrefLangs: Map<string, LangHrefLink> = new Map()
for (const locale of controller.availableLocales) {
const hrefLang = locale.meta?.static?.iso ?? locale.tag
if (hrefLangs.has(hrefLang)) continue
const sp = new URLSearchParams(query)
sp.set(options.hostLanguageParameter, locale.tag)
if (
controller.defaultLocale === locale.tag &&
!options.defaultLocaleHasParameter
) {
sp.delete(options.hostLanguageParameter)
} else {
sp.set(options.hostLanguageParameter, locale.tag)
}
hrefLangs.set(hrefLang, {
// key: `hreflang-${locale.tag}`,
@@ -102,7 +106,7 @@ export function initHead(
})
}
return [defaultEntry, ...hrefLangs.values()]
return Array.from(hrefLangs.values())
},
})
}
@@ -3,6 +3,27 @@ import { tSwitch } from '../utils/zod-utils.js'
import { languageTagSchema } from './language-tag.js'
import { localeDescriptorSchema } from './locales.js'
import { seoOptions } from './seo.js'
import type { ParseErrorHandler } from '@vintl/unplugin'
const parseErrorHandingStrategy = t.union([
t.literal('use-message-as-literal'),
t.literal('use-id-as-literal'),
t.literal('use-empty-literal'),
t.literal('log-and-skip'),
t.literal('skip'),
])
const parseErrorHandler = t.custom<ParseErrorHandler>(
(value) => typeof value === 'function',
)
export const parseErrorHandling = tSwitch((input) => {
if (typeof input === 'function') {
return parseErrorHandler
} else if (typeof input === 'string') {
return parseErrorHandingStrategy
}
})
const parselessModeEnumSchema = t.enum(['always', 'only-prod', 'never'])
@@ -200,6 +221,14 @@ export const moduleOptionsSchema = t
return parselessOptionsSchema
}
}).default('only-prod'),
/**
* Either a literal name of the strategy or a function that handles the
* errors that occur during the parsing of one of the imported files.
*
* @see https://github.com/vintl-dev/unplugin/blob/df9b3be9c77f78eaf5fe7f8d6fde1655f2bc79e1/README.md#onparseerror
*/
onParseError: parseErrorHandling.optional(),
})
.transform((from) => {
if (from.seo === undefined) {
+13
View File
@@ -29,4 +29,17 @@ export const seoOptions = t.object({
'Base URL at which the site will be available. This is required to generate absolute hreflang links. ',
)
.optional(),
/**
* Whether to use the host language parameter for the default locale.
*
* This options helps keep URLs for your default language clean, however it is
* not correct, and is not recommended, because lack of the host language
* parameter tells VIntl to use the user locale (whether it's the one they've
* choosen before or their browser's one).
*/
defaultLocaleHasParameter: t.boolean().default(true),
/** Whether to enable `x-default` hreflang. */
xDefaultHreflang: t.boolean().default(true),
})
+4 -2
View File
@@ -1,8 +1,10 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "nodenext",
"module": "esnext",
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"types": ["./types/nuxt"],
+1 -1
View File
@@ -3,7 +3,7 @@
"compilerOptions": {
"composite": true,
"module": "ESNext",
"module": "nodenext",
"moduleResolution": "nodenext",
"types": ["./types/nuxt"],
+9 -3
View File
@@ -82,11 +82,17 @@ declare module '@vintl/nuxt-runtime/options' {
hostLanguageParameter: string
/**
* Base URL at which the site will be available. This is required to generate
* absolute hreflang links. Without this, VIntl must try to guess the URL
* based on the server request URL / current `window.location`.
* Base URL at which the site will be available. This is required to
* generate absolute hreflang links. Without this, VIntl must try to guess
* the URL based on the server request URL / current `window.location`.
*/
baseURL?: string
/** Whether to use the host language parameter for the default locale. */
defaultLocaleHasParameter: boolean
/** Whether to enable `x-default` hreflang. */
xDefaultHreflang: boolean
}
/** SEO options. */
+3094 -1728
View File
File diff suppressed because it is too large Load Diff
+4 -1
View File
@@ -7,8 +7,11 @@
"@vintl/nuxt#lint": {
"outputs": [".eslintcache"]
},
"@vintl-dev/pg#intl:extract": {
"outputs": ["./locales/en-US.json"]
},
"@vintl-dev/pg#dev:prepare": {
"dependsOn": ["@vintl/nuxt#build"],
"dependsOn": ["@vintl/nuxt#build", "@vintl-dev/pg#intl:extract"],
"inputs": ["./package.json", "./nuxt.config.ts"],
"outputs": [".nuxt"]
},