Skip to content

Commit

Permalink
fix!: remove deprecated locale iso property (#3146)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobbieGoede authored Sep 30, 2024
1 parent 35b45a9 commit 039f282
Show file tree
Hide file tree
Showing 44 changed files with 118 additions and 135 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ npx nuxi@latest module add i18n
],
i18n: {
locales: [
{ code: 'en', iso: 'en-US' },
{ code: 'fr', iso: 'fr-FR' }
{ code: 'en', language: 'en-US' },
{ code: 'fr', language: 'fr-FR' }
]
defaultLocale: 'en',
}
Expand Down
2 changes: 1 addition & 1 deletion docs/content/docs/2.guide/5.browser-language-detection.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default defineNuxtConfig({
For better SEO, it's recommended to set `redirectOn` to `root` (which is the default value). When set, the language detection is only attempted when the user visits the root path (`/`) of the site. This allows crawlers to access the requested page rather than being redirected away based on detected locale. It also allows linking to pages in specific locales.
::

Browser language is detected either from `navigator` when running on client-side, or from the `accept-language` HTTP header. Configured `locales` (or locales `iso` and/or `code` when locales are specified in object form) are matched against locales reported by the browser (for example `en-US,en;q=0.9,no;q=0.8`). If there is no exact match for the full locale, the language code (letters before `-`) are matched against configured locales.
Browser language is detected either from `navigator` when running on client-side, or from the `accept-language` HTTP header. Configured `locales` (or locales `language` and/or `code` when locales are specified in object form) are matched against locales reported by the browser (for example `en-US,en;q=0.9,no;q=0.8`). If there is no exact match for the full locale, the language code (letters before `-`) are matched against configured locales.

To prevent redirecting users every time they visit the app, **Nuxt i18n module** sets a cookie using the detected locale. You can change the cookie's name by setting `detectBrowserLanguage.cookieKey` option to whatever you'd like, the default is _i18n_redirected_.

Expand Down
26 changes: 13 additions & 13 deletions docs/content/docs/2.guide/6.seo.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@ Here are the specific optimizations and features that it enables:

## Requirements

To leverage the SEO benefits, you must configure the `locales` option as an array of objects, where each object has an `iso` option set to the locale language tags:
To leverage the SEO benefits, you must configure the `locales` option as an array of objects, where each object has an `language` option set to the locale language tags:

```ts [nuxt.config.ts]
export default defineNuxtConfig({
i18n: {
locales: [
{
code: 'en',
iso: 'en-US'
language: 'en-US'
},
{
code: 'es',
iso: 'es-ES'
language: 'es-ES'
},
{
code: 'fr',
iso: 'fr-FR'
language: 'fr-FR'
}
]
}
Expand Down Expand Up @@ -165,11 +165,11 @@ useHead({

- `lang` attribute for the `<html>` tag

Sets the correct `lang` attribute, equivalent to the current locale's `iso` value, in the `<html>` tag.
Sets the correct `lang` attribute, equivalent to the current locale's `language` value, in the `<html>` tag.

- `hreflang` alternate link

Generates `<link rel="alternate" hreflang="x">` tags for every configured locale. The locales' `iso` value are used as `hreflang` values.
Generates `<link rel="alternate" hreflang="x">` tags for every configured locale. The locales' `language` value are used as `hreflang` values.

A "catchall" locale hreflang link is provided for each locale group (e.g. `en-*`). By default, it is the first locale provided, but another locale can be selected by setting `isCatchallLocale` to `true` on that specific locale object in your **Nuxt i18n module** configuration. [More on hreflang](https://support.google.com/webmasters/answer/189077)

Expand All @@ -181,11 +181,11 @@ useHead({
locales: [
{
code: 'en',
iso: 'en-US' // Will be used as "catchall" locale by default
language: 'en-US' // Will be used as "catchall" locale by default
},
{
code: 'gb',
iso: 'en-GB'
language: 'en-GB'
}
]
}
Expand All @@ -200,31 +200,31 @@ useHead({
locales: [
{
code: 'en',
iso: 'en-US'
language: 'en-US'
},
{
code: 'gb',
iso: 'en-GB',
language: 'en-GB',
isCatchallLocale: true // This one will be used as catchall locale
}
]
}
})
```

In case you already have an `en` locale `iso` set, it'll be used as the "catchall" without doing anything
In case you already have an `en` locale `language` set, it'll be used as the "catchall" without doing anything

```ts [nuxt.config.ts]
export default defineNuxtConfig({
i18n: {
locales: [
{
code: 'gb',
iso: 'en-GB'
language: 'en-GB'
},
{
code: 'en',
iso: 'en' // will be used as "catchall" locale
language: 'en' // will be used as "catchall" locale
}
]
}
Expand Down
8 changes: 4 additions & 4 deletions docs/content/docs/3.options/2.routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ List of locales supported by your app. Can either be an array of codes (`['en',

```json
[
{ "code": "en", "iso": "en-US", "file": "en.js", "dir": "ltr" },
{ "code": "ar", "iso": "ar-EG", "file": "ar.js", "dir": "rtl" },
{ "code": "fr", "iso": "fr-FR", "file": "fr.js" }
{ "code": "en", "language": "en-US", "file": "en.js", "dir": "ltr" },
{ "code": "ar", "language": "ar-EG", "file": "ar.js", "dir": "rtl" },
{ "code": "fr", "language": "fr-FR", "file": "fr.js" }
]
```

When using an object form, the properties can be:

- `code` (**required**) - unique identifier of the locale
- `iso` (required when using SEO features) - A language-range used for SEO features and for matching browser locales when using [`detectBrowserLanguage`](/docs/options/browser#detectbrowserlanguage) functionality. Should use the [language tag syntax](https://www.w3.org/International/articles/language-tags/) as defined by the IETF's [BCP47](https://www.rfc-editor.org/info/bcp47), for example:
- `language` (required when using SEO features) - A language-range used for SEO features and for matching browser locales when using [`detectBrowserLanguage`](/docs/options/browser#detectbrowserlanguage) functionality. Should use the [language tag syntax](https://www.w3.org/International/articles/language-tags/) as defined by the IETF's [BCP47](https://www.rfc-editor.org/info/bcp47), for example:
- `'en'` (`language` subtag for English)
- `'fr-CA'` (`language+region` subtags for French as used in Canada)
- `'zh-Hans'` (`language+script` subtags for Chinese written with Simplified script)
Expand Down
6 changes: 3 additions & 3 deletions playground/layer-module/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ export default defineNuxtModule({
locales: [
{
code: 'en',
iso: 'en-US',
language: 'en-US',
file: 'en.json',
name: 'English'
},
{
code: 'fr',
iso: 'fr-FR',
language: 'fr-FR',
file: 'fr.json',
name: 'Francais'
},
{
code: 'nl',
iso: 'nl-NL',
language: 'nl-NL',
file: 'nl.json',
name: 'Nederlands'
}
Expand Down
6 changes: 3 additions & 3 deletions playground/layer-module/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ export default defineNuxtConfig({
locales: [
{
code: 'en',
iso: 'en-US',
language: 'en-US',
file: 'en.json',
// domain: 'localhost',
name: 'English'
},
{
code: 'fr',
iso: 'fr-FR',
language: 'fr-FR',
file: 'fr.json',
// domain: 'localhost',
name: 'Francais'
},
{
code: 'nl',
iso: 'nl-NL',
language: 'nl-NL',
file: 'nl.json',
// domain: 'localhost',
name: 'Nederlands'
Expand Down
12 changes: 6 additions & 6 deletions playground/layers/i18n-layer/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,41 @@ export default defineNuxtConfig({
locales: [
{
code: 'en',
iso: 'en-US',
language: 'en-US',
file: 'en.json',
// domain: 'localhost',
name: 'English'
},
{
code: 'fr',
iso: 'fr-FR',
language: 'fr-FR',
file: 'fr.json',
domain: 'layer-fr.example.com',
name: 'Francais'
},
{
code: 'nl',
iso: 'nl-NL',
language: 'nl-NL',
file: 'nl.json',
// domain: 'localhost',
name: 'Nederlands'
}
// {
// code: 'en-GB',
// iso: 'en-GB',
// language: 'en-GB',
// files: ['en.json', 'en-GB.json'],
// name: 'English (UK)'
// },
// {
// code: 'ja',
// iso: 'ja-JP',
// language: 'ja-JP',
// file: 'ja.json',
// domain: 'mydomain.com',
// name: 'Japanses'
// },
// {
// code: 'fr',
// iso: 'fr-FR',
// language: 'fr-FR',
// file: 'fr.json',
// domain: 'mydomain.fr',
// name: 'Français'
Expand Down
4 changes: 2 additions & 2 deletions playground/module-experimental/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ export default defineNuxtModule<ModuleOptions>({
locales: [
{
code: 'de',
iso: 'de-DE',
language: 'de-DE',
file: 'de.ts'
},
{
code: 'en',
iso: 'en-US',
language: 'en-US',
file: 'en.ts'
}
]
Expand Down
16 changes: 8 additions & 8 deletions playground/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,27 @@ export default defineNuxtConfig({
locales: [
{
code: 'en',
iso: 'en-US',
language: 'en-US',
file: 'en.json',
// domain: 'localhost',
name: 'English'
},
{
code: 'en-GB',
iso: 'en-GB',
language: 'en-GB',
files: ['en.json', 'en-GB.js', 'en-KK.js'],
name: 'English (UK)'
},
{
code: 'ja',
iso: 'ja-JP',
language: 'ja-JP',
file: 'ja.ts',
domain: 'mydomain.com',
name: 'Japanses'
},
{
code: 'fr',
iso: 'fr-FR',
language: 'fr-FR',
file: 'fr.json',
domain: 'mydomain.fr',
name: 'Français'
Expand Down Expand Up @@ -138,27 +138,27 @@ export default defineNuxtConfig({
locales: [
{
code: 'en',
iso: 'en-US',
language: 'en-US',
file: 'en.json',
// domain: 'localhost',
name: 'English'
},
{
code: 'en-GB',
iso: 'en-GB',
language: 'en-GB',
files: ['en.json', 'en-GB.js', 'en-KK.js', 'en-US.yaml', 'en-CA.json5'],
name: 'English (UK)'
},
{
code: 'ja',
iso: 'ja-JP',
language: 'ja-JP',
file: 'ja.ts',
domain: 'mydomain.com',
name: 'Japanses'
},
{
code: 'fr',
iso: 'fr-FR',
language: 'fr-FR',
file: 'fr.json',
domain: 'project-fr.example.com',
name: 'Français'
Expand Down
6 changes: 3 additions & 3 deletions specs/different_domains/different_domains.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ await setup({
locales: [
{
code: 'en',
iso: 'en',
language: 'en',
name: 'English',
domain: 'en.nuxt-app.localhost'
},
{
code: 'fr',
iso: 'fr-FR',
language: 'fr-FR',
name: 'Français',
domain: 'fr.nuxt-app.localhost'
},
{
code: 'kr',
iso: 'ko-KR',
language: 'ko-KR',
name: '한국어',
domain: 'kr.nuxt-app.localhost'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ await setup({
locales: [
{
code: 'en',
iso: 'en',
language: 'en',
name: 'English',
domain: 'nuxt-app.localhost',
domainDefault: true
},
{
code: 'no',
iso: 'no-NO',
language: 'no-NO',
name: 'Norwegian',
domain: 'nuxt-app.localhost'
},
{
code: 'fr',
iso: 'fr-FR',
language: 'fr-FR',
name: 'Français',
domain: 'fr.nuxt-app.localhost'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,27 @@ await setup({
locales: [
{
code: 'en',
iso: 'en',
language: 'en',
name: 'English',
domain: 'nuxt-app.localhost',
domainDefault: true
},
{
code: 'no',
iso: 'no-NO',
language: 'no-NO',
name: 'Norwegian',
domain: 'nuxt-app.localhost'
},
{
code: 'fr',
iso: 'fr-FR',
language: 'fr-FR',
name: 'Français',
domain: 'fr.nuxt-app.localhost',
domainDefault: true
},
{
code: 'ja',
iso: 'jp-JA',
language: 'jp-JA',
name: 'Japan',
domain: 'ja.nuxt-app.localhost',
domainDefault: true
Expand Down
Loading

0 comments on commit 039f282

Please sign in to comment.