xiCO2k / laravel-vue-i18n

Allows to connect your `Laravel` Framework translation files with `Vue`.
MIT License
594 stars 49 forks source link

TypeScript support #123

Open 7nohe opened 1 year ago

7nohe commented 1 year ago

I am interested in having type-safe resources support like Vue I18n. Is it possible to achieve this?

import { createI18n } from 'vue-i18n'
import enUS from './locales/en-US.json'

// Type-define 'en-US' as the master schema for the resource
type MessageSchema = typeof enUS

const i18n = createI18n<[MessageSchema], 'en-US' | 'ja-JP'>({
  locale: 'en-US',
  messages: {
    'en-US': enUS
  }
})

https://vue-i18n.intlify.dev/guide/advanced/typescript.html

xiCO2k commented 1 year ago

I would love to review a PR with that capabilities.

xiCO2k commented 1 year ago

@daniser do you think this is solved?

Thanks

daniser commented 1 year ago

@daniser do you think this is solved?

Thanks

No unfortunately(

xiCO2k commented 1 year ago

I will leave this here if someone wants to contribute. Thanks @daniser 💪

mathiasselleslach commented 4 weeks ago

@xiCO2k ,

Am I correct to understand that this plugin does not support TS for the moment?

Many thanks.

xiCO2k commented 4 weeks ago

@mathiasselleslach, it should support, but probably missing some typing.

mathiasselleslach commented 4 weeks ago

Thanks @xiCO2k .

Using a Laravel/Vue(3)/Inertia setup myself and cant' get it to work. I am in a Typescript setup.

App.ts (as per documentation)

            .use(i18nVue, {
                resolve: async (lang: string) => {
                    const langs: any = import.meta.glob("../../lang/*.json");
                    return await langs[`../../lang/${lang}.json`]();
                }
            })

vite.config.js


export default defineConfig({
    plugins: [
        laravel({
            input: 'resources/js/app.ts',
            refresh: true,
        }),
        vue({
            template: {
                transformAssetUrls: {
                    base: null,
                    includeAbsolute: false,
                },
            },
        }),
        i18n(),
    ],
});

Am i missing something here?

When rendering

$t('test')

It just defaults to the key in the en.json file (yes, locale is set to en ;-) that i have checked)