jetstreamlabs / zora

Add your Laravel language translations to your asset pipeline for use in Javascript packages like Vue or React.
MIT License
10 stars 3 forks source link

How to use in vue composition api? #119

Closed sibber11 closed 1 week ago

sibber11 commented 8 months ago

it's working in the template. but getting error when trying to use in script setup

secondmanveran commented 7 months ago

@sibber11

Sorry I never got a notification for this.

If you're compiling your language files in javascript (which you should be), you should have a zora.js file.

Create a composable, I call mine useTrans, and place it in the Composable directory.

import { trans } from 'zora';
import { Zora } from '../zora.js';

export default function useTrans(key, replace) {
  return trans(key, replace, Zora);
}

Then you can import the composable and use it as needed.

import { useTrans } from '@/Composable/useTrans.js';

const message = useTrans('auth.failed');
// {{ message }} = 'These credentials do not match our records.'

Hope that helps.