Skip to content

Commit

Permalink
Remove deprecated composables
Browse files Browse the repository at this point in the history
  • Loading branch information
brawaru committed Jun 11, 2023
1 parent 8ab6b16 commit 997402a
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 44 deletions.
27 changes: 27 additions & 0 deletions .changeset/new-turkeys-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
'@vintl/vintl': major
---

Remove deprecated composables

Composables, such as `useI18n`, `useTranslate` and `useFormatters` were previously deprecated with the warning that they will be removed in the next major version. They now get removed as scheduled.

Migration steps:

- Use `useVIntl` everywhere you used `useI18n`, the latter was just an alias for `useVIntl` in previous versions.

- To retrieve translate function previously returned by `useTranslate`, destructure `formatMessage` function from the controller:

```js
const { formatMessage } = useVIntl
```

It is bound to the controller and as such is safe to use on its own.

- To retrieve formatters previously returned by `useFormatters`, destructure `formats` property from the controller:

```js
const { formats } = useVIntl
```

It is reactively updated object and also safe to use on its own.
4 changes: 1 addition & 3 deletions src/runtime/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
export { useI18n, useVIntl } from './useI18n.js'
export { useFormatters } from './useFormatters.js'
export { useTranslate } from './useTranslate.js'
export { useVIntl } from './useVIntl.js'
15 changes: 0 additions & 15 deletions src/runtime/useFormatters.ts

This file was deleted.

14 changes: 0 additions & 14 deletions src/runtime/useTranslate.ts

This file was deleted.

10 changes: 0 additions & 10 deletions src/runtime/useI18n.ts → src/runtime/useVIntl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,3 @@ export function useVIntl<ControllerType = MessageValueType>() {

return controller as IntlController<ControllerType>
}

/**
* Alias for {@link useVIntl}.
*
* @deprecated This composable name is deprecated and will be removed in next
* major version. Please use {@link useVIntl} instead.
*/
export function useI18n<ControllerType = MessageValueType>() {
return useVIntl<ControllerType>()
}
4 changes: 2 additions & 2 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { describe, expect, test, vi } from 'vitest'
import { type App, createApp, defineComponent } from 'vue'
import {
type PreferredLocalesSource,
useI18n,
useVIntl,
type LocaleDescriptor,
} from '../dist'
import { type IntlController, createController } from '../dist/controller'
Expand Down Expand Up @@ -35,7 +35,7 @@ let controller: IntlController<string>
const appComponent = defineComponent({
name: 'App',
setup() {
const i18nResult = useI18n()
const i18nResult = useVIntl()
return { i18nResult }
},
})
Expand Down

0 comments on commit 997402a

Please sign in to comment.