jshmrtn / vue3-gettext

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

scripts aren't working with $.gettext, only with the useGettext hook #26

Closed nanoander closed 2 years ago

nanoander commented 2 years ago

Issue: after running vue-gettext-extract, the expected pot and po files are created, but they have not the translation strings when using $.gettext in templates. It works when using the useGettext hook tho.

This works:

<script setup lang="ts">
import { useGettext } from 'vue3-gettext';
...
const { $gettext } = useGettext();
...
</script>
<template>
  <span>{{ $gettext('Some text...') }}</span>
</template>

but this doesn't:

<template>
  <span>{{ $.gettext('Some text...') }}</span>
</template>

Details:

"vue": "3.2.33", "vue3-gettext": "2.2.3"

App setup

import { createGettext } from 'vue3-gettext';
import translations from './i18n/translations.json';

const gettext = createGettext({
  availableLanguages: {
    en: 'English',
    es: 'Spanish',
  },
  defaultLanguage: 'en',
  translations: translations,
});

const app = createApp(App);
app.use(gettext);
app.mount('#app');
lzurbriggen commented 2 years ago

@nanoander I'm a bit confused, but here are some pointers:

At some point I may make the extract script customizable so you can define your own function names/tokens, but I can't promise anything atm.