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

TypeScript support #123

Open
7nohe opened this issue May 7, 2023 · 7 comments
Open

TypeScript support #123

7nohe opened this issue May 7, 2023 · 7 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@7nohe
Copy link

7nohe commented May 7, 2023

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
Copy link
Owner

xiCO2k commented May 8, 2023

I would love to review a PR with that capabilities.

@xiCO2k xiCO2k added enhancement New feature or request good first issue Good for newcomers labels May 14, 2023
@xiCO2k
Copy link
Owner

xiCO2k commented Jun 11, 2023

@daniser do you think this is solved?

Thanks

@daniser
Copy link
Contributor

daniser commented Jun 12, 2023

@daniser do you think this is solved?

Thanks

No unfortunately(

@xiCO2k
Copy link
Owner

xiCO2k commented Jun 13, 2023

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

@mathiasselleslach
Copy link

@xiCO2k ,

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

Many thanks.

@xiCO2k
Copy link
Owner

xiCO2k commented Aug 6, 2024

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

@mathiasselleslach
Copy link

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants