Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add locale composable #13336

Merged
merged 6 commits into from
Apr 27, 2021
Merged

feat: add locale composable #13336

merged 6 commits into from
Apr 27, 2021

Conversation

nekosaur
Copy link
Member

@nekosaur nekosaur commented Mar 27, 2021

Description

creates locale and rtl composables.

adapter helpers for vue-i18n and vue-intl are not included here since it would mean we'd need to depend on those packages. they should probably be separate npm packages that can be imported and used.

resolves #13539

Motivation and Context

v3

How Has This Been Tested?

playground. still needs tests

Markup:

<template>
  <v-app class="fill-height">
    <v-locale-provider :locale="scoped" :rtl="true">
      <Foo />
    </v-locale-provider>

    <Foo />

    <span>global: {{ t('$vuetify.close') }}</span>

    <button @click="current = current === 'ja' ? 'sv' : 'ja'">toggle</button>
    <button @click="scoped = scoped === 'ja' ? 'sv' : 'ja'">toggle</button>
    <pre>{{ current }}</pre>
    <pre>isRtl: {{ isRtl }}</pre>
    <input v-model="scoped">
  </v-app>
</template>

<script>
  import { h, ref } from 'vue'
  import { useLocale } from '../src/composables/locale'
  import { useRtl } from '../src/composables/rtl'

  const Foo = {
    props: {
      bar: {
        type: null,
      },
    },
    setup (props, ctx) {
      const locale = useLocale()
      const { isRtl } = useRtl()

      return () => h('div', [
        h('div', ['translated: ' + locale.t('$vuetify.close')]),
        h('div', [`isRtl: ${isRtl.value}`]),
        ctx.slots.default?.(),
      ])
    },
  }

  export default {
    name: 'Playground',
    components: { Foo },
    setup () {
      const locale = useLocale()
      const scoped = ref('sv')
      const { isRtl } = useRtl()

      return { ...locale, scoped, isRtl }
    },
  }
</script>

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Improvement/refactoring (non-breaking change that doesn't add any features but makes things better)

Checklist:

  • The PR title is no longer than 64 characters.
  • The PR is submitted to the correct branch (master for bug fixes and documentation updates, dev for new features and backwards compatible changes and next for non-backwards compatible changes).
  • My code follows the code style of this project.
  • I've added relevant changes to the documentation (applies to new features and breaking changes in core library)

@glen-84
Copy link

glen-84 commented Mar 28, 2021

I prefer vue-intl (Format.JS). vue-i18n is still optional, right?

@nekosaur
Copy link
Member Author

Yes, it's optional. And the API here is still very much up in the air. I'll have a look at vue-intl.

@nekosaur
Copy link
Member Author

@glen-84 I've reworked the adapter interface to kind of work with vue-intl as well. still very prototypey.

yarn.lock Show resolved Hide resolved
@nekosaur
Copy link
Member Author

This or some version of locale/rtl needs to be merged pretty soon

@johnleider johnleider added this to In progress in Vuetify 3 - Titan via automation Apr 14, 2021
@johnleider johnleider added this to the v3.0.0 milestone Apr 14, 2021
packages/vuetify/dev/index.js Outdated Show resolved Hide resolved
packages/vuetify/src/components/VLocaleProvider/index.ts Outdated Show resolved Hide resolved
packages/vuetify/src/framework.ts Outdated Show resolved Hide resolved
packages/vuetify/src/composables/rtl.ts Outdated Show resolved Hide resolved
Vuetify 3 - Titan automation moved this from In progress to Review in progress Apr 14, 2021
@nekosaur nekosaur marked this pull request as ready for review April 23, 2021 16:07
packages/vuetify/src/composables/locale.ts Show resolved Hide resolved
packages/vuetify/src/composables/locale.ts Outdated Show resolved Hide resolved
packages/vuetify/dev/index.js Outdated Show resolved Hide resolved
packages/vuetify/src/composables/rtl.ts Outdated Show resolved Hide resolved
packages/vuetify/src/composables/rtl.ts Outdated Show resolved Hide resolved
packages/vuetify/src/composables/rtl.ts Outdated Show resolved Hide resolved
packages/vuetify/src/composables/rtl.ts Outdated Show resolved Hide resolved
Vuetify 3 - Titan automation moved this from Review in progress to Reviewer approved Apr 27, 2021
@johnleider johnleider merged commit 66dc081 into next Apr 27, 2021
Vuetify 3 - Titan automation moved this from Reviewer approved to Done Apr 27, 2021
@johnleider johnleider deleted the feat/v3-locale branch April 27, 2021 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

4 participants