nuxt-modules / i18n

I18n module for Nuxt
https://i18n.nuxtjs.org
MIT License
1.67k stars 469 forks source link

Implement composition API #987

Open rchl opened 3 years ago

rchl commented 3 years ago

Is your feature request related to a problem? Please describe.

Add a native composition API for use with Vue 3.

Some more info at https://dev.to/alvarosaburido/how-to-migrate-your-library-from-vue2-to-vue3-1h81

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

philipdanielhayton commented 3 years ago

Hola guys, any news on this? Or any work around for the short term?

What's the best way to access methods such as localePath inside the setup method currently?

rchl commented 3 years ago

See https://github.com/nuxt-community/composition-api/issues/425#issuecomment-813102698

DamianGlowala commented 2 years ago

@rchl any ideas on how to get a translated string inside setup() (when using an <i18n> custom block)? Everything comes back as a raw translation path... totally lost on this. Anything I am doing incorrectly in the below example? I am using Nuxt 2 with Composition API.

<i18n>
{
  "en": {
    "exampleString": "Test"
  }
}
</i18n>

...

setup() {
  const { i18n } = useContext();

  console.log(i18n.t("exampleString"));
}

Is this related to https://github.com/nuxt-community/i18n-module/pull/1333? May I ask why this PR is still a draft?

UPDATE I made a Nuxt composable by copying the useI18n() function from the https://github.com/nuxt-community/i18n-module/pull/1333. Works perfectly as a workaround ;)

thisismydesign commented 1 year ago

On nuxt 2 bridge:

<script setup lang="ts">

const { $i18n } = useNuxtApp()
$i18n.t('key')

</script>
MatthD commented 1 year ago

@thisismydesign is this suppose to work ?