jshmrtn / vue3-gettext

Translate Vue 3 applications with gettext.
https://jshmrtn.github.io/vue3-gettext/
MIT License
66 stars 23 forks source link

Allow passing a read-only props as context #18

Closed tcitworld closed 2 years ago

tcitworld commented 2 years ago
<template>
  <div>
    <p v-translate="{ indexName }" >
      <strong>%{indexName}</strong>  something something something
    </p>
  </div>
</template>

<script lang="ts">
  import { defineComponent } from 'vue'

  export default defineComponent({
    props: {
      indexName: {
        type: String,
        required: true,
      },
    },
  })
</script>

Gives

[Vue warn]: Attempting to mutate prop "indexName". Props are readonly. 

The trace points to https://github.com/jshmrtn/vue3-gettext/blob/65e55810133dec332d004a19aa8d7fd7fc4ea849/src/directive.ts#L33

lzurbriggen commented 2 years ago

@tcitworld I believe the issue is that indexName is already in the translation context (binding.instance), which means you could use the directive without manually passing it:

<p v-translate>
  <strong>%{indexName}</strong> something
</p>

or rename the parameter:

<p v-translate="{ name: indexName }" >
  <strong>%{name}</strong> something
</p>

So I don't really consider this a bug, but I see how it can be confusing. I'll try to update the documentation.

As a heads up: I'll probably deprecate (but not remove) the directive and components soon. I will document the reasons when it comes to that.

tcitworld commented 2 years ago

That's correct, thanks!