Skip to content

Commit

Permalink
feat: remove jsTsFormatResource experimental (nuxt-modules#2531)
Browse files Browse the repository at this point in the history
* feat: support disableWarning option for experimental

* fix: remove jsTsFormatResource from experimental
  • Loading branch information
GaborTorma authored Nov 3, 2023
1 parent 1a3cc5c commit 727dba2
Show file tree
Hide file tree
Showing 12 changed files with 7 additions and 70 deletions.
4 changes: 0 additions & 4 deletions docs/content/2.guide/8.lazy-load-translations.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ If your function returns an object of locale messages, **you must define it in t
About `defineI18nLocale` details, see the [here](/api/composables#defineI18nLocale).
::

::alert{type="warn"}
Support for JS/TS format resources is an experimental feature and is disabled by default, to enable this set the `experimental.jsTsFormatResource` module option to `true`.
::

::alert{type="info"}
If the function returns an Object available in nuxt i18n module, you can configure the dynamic locale messages, like the API (including external API) or back-end, via fetch:

Expand Down
14 changes: 2 additions & 12 deletions docs/content/3.options/10.misc.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,9 @@ Miscellaneous options.
## `experimental`

- type: `object`
- default: `{ jsTsFormatResource: false }`

Configure the flag for experimental features of the nuxt i18n module.

::alert{type="info"}
This property can also be set using [`runtimeConfig`](./runtime-config).
::

Supported properties:

- `jsTsFormatResource` (default: `false`) - Allow the format `js` and `ts` for locale messages in lazy load translation.

- default: `{}`

Currently no experimental options are available.
## `customBlocks`

- type: `object`
Expand Down
12 changes: 0 additions & 12 deletions docs/content/3.options/9.runtime-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,11 @@ export default defineNuxtConfig({
i18n: {
// Leave options unset that you want to set using `runtimeConfig`
// baseUrl: 'https://example.com',
// experimental: {
// jsTsFormatResource: true,
// },
},
runtimeConfig: {
public: {
i18n: {
baseUrl: 'https://example.com',
experimental: {
jsTsFormatResource: true,
},
locales: {},
// other options ...
}
Expand Down Expand Up @@ -62,12 +56,6 @@ This runtime config option is the same as the [`baseUrl`](./routing#baseUrl) mod
Note that the `baseUrl` module option allows you to set the function, but the runtime config does not due to limitations.
::

### `experimental`
* property: `experimental.jsTsFormatResource`
* key: `NUXT_PUBLIC_I18N_EXPERIMENTAL_JS_TS_FORMAT_RESOURCE`

This runtime config option is the same as the [`experimental`](./misc#experimental) module option.

### `locales`
* property: `locales[code].domain`
* key: `NUXT_PUBLIC_I18N_LOCALES_{code}_DOMAIN`
Expand Down
6 changes: 0 additions & 6 deletions playground/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ export default defineNuxtConfig({
[
'@nuxtjs/i18n',
{
experimental: {
jsTsFormatResource: true
},
compilation: {
strictMessage: false,
escapeHtml: true
Expand Down Expand Up @@ -110,9 +107,6 @@ export default defineNuxtConfig({
// },
// debug: true,
i18n: {
experimental: {
jsTsFormatResource: true
},
compilation: {
// jit: false,
strictMessage: false,
Expand Down
3 changes: 0 additions & 3 deletions specs/fixtures/inline_options/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ export default defineNuxtConfig({
lazy: false,
langDir: 'lang',
defaultLocale: 'en',
experimental: {
jsTsFormatResource: true
},
detectBrowserLanguage: false,
locales: [
{
Expand Down
3 changes: 0 additions & 3 deletions specs/fixtures/issues/2000/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ export default defineNuxtConfig({
},

i18n: {
experimental: {
jsTsFormatResource: true
},
defaultLocale: 'en',
langDir: 'locales',
lazy: true,
Expand Down
3 changes: 0 additions & 3 deletions specs/fixtures/issues/2151/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ export default defineNuxtConfig({
],
strategy: 'prefix',
defaultLocale: 'en',
experimental: {
jsTsFormatResource: true
},
// debug: true,
detectBrowserLanguage: {
useCookie: true,
Expand Down
3 changes: 0 additions & 3 deletions specs/fixtures/lazy/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ export default defineNuxtConfig({
// langDir: 'lang',
// defaultLocale: 'fr',
detectBrowserLanguage: false,
experimental: {
jsTsFormatResource: true
},
compilation: {
strictMessage: false
},
Expand Down
4 changes: 1 addition & 3 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ export const REDIRECT_ON_OPTIONS = {
export const COMPONENT_OPTIONS_KEY = 'nuxtI18n'

export const DEFAULT_OPTIONS = {
experimental: {
jsTsFormatResource: false
},
experimental: {},
bundle: {
compositionOnly: true,
runtimeOnly: false,
Expand Down
7 changes: 1 addition & 6 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ export default defineNuxtModule<NuxtI18nOptions>({
applyOptionOverrides(options, nuxt)
debug('options', options)

if (options.experimental.jsTsFormatResource) {
logger.warn('JS / TS extension format is an experimental feature')
}

if (!options.compilation.jit) {
logger.warn(
'Opt-out JIT compilation. ' +
Expand Down Expand Up @@ -136,7 +132,6 @@ export default defineNuxtModule<NuxtI18nOptions>({

// for public
nuxt.options.runtimeConfig.public.i18n = defu(nuxt.options.runtimeConfig.public.i18n, {
experimental: options.experimental,
baseUrl: options.baseUrl,
locales: options.locales.reduce(
(obj, locale) => {
Expand Down Expand Up @@ -337,7 +332,7 @@ export default defineNuxtModule<NuxtI18nOptions>({
type MaybePromise<T> = T | Promise<T>
type LocaleSwitch<T extends string = string> = { oldLocale: T; newLocale: T }

type ModulePublicRuntimeConfig<Context = unknown> = Pick<NuxtI18nOptions<Context>, 'baseUrl' | 'experimental'>
type ModulePublicRuntimeConfig<Context = unknown> = Pick<NuxtI18nOptions<Context>, 'baseUrl'>

declare module '@nuxt/schema' {
interface NuxtConfig {
Expand Down
14 changes: 2 additions & 12 deletions src/runtime/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,23 +119,13 @@ type LocaleLoader = { key: string; load: () => Promise<any>; cache: boolean }
const loadedMessages = new Map<string, LocaleMessages<DefineLocaleMessage>>()

async function loadMessage(context: NuxtApp, { key, load }: LocaleLoader, locale: Locale) {
const i18nConfig = context.$config.public?.i18n as { experimental?: { jsTsFormatResource?: boolean } }

let message: LocaleMessages<DefineLocaleMessage> | null = null
try {
__DEBUG__ && console.log('loadMessage: (locale) -', locale)
const getter = await load().then(r => r.default || r)
if (isFunction(getter)) {
if (i18nConfig.experimental?.jsTsFormatResource) {
message = await getter(locale)
__DEBUG__ && console.log('loadMessage: dynamic load', message)
} else {
console.warn(
formatMessage(
'JS / TS extension format is not supported by default. This can be enabled by setting `i18n.experimental.jsTsFormatResource: true` (experimental)'
)
)
}
message = await getter(locale)
__DEBUG__ && console.log('loadMessage: dynamic load', message)
} else {
message = getter
if (message != null) {
Expand Down
4 changes: 1 addition & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ export type CustomRoutePages = {
}
}

export interface ExperimentalFeatures {
jsTsFormatResource?: boolean
}
export interface ExperimentalFeatures {}

export interface BundleOptions
extends Pick<
Expand Down

0 comments on commit 727dba2

Please sign in to comment.