Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ahmedde's avatar

Global Vue function inside of <script setup>?

I have this helper function that is used to grab translations:

export function __(key, replacements = {}) {
    let translation = window._translations[key] || key;
    Object.keys(replacements).forEach((replacement) => {
        translation = translation.replace(`:${replacement}`, replacements[replacement]);
    });
    return translation;
}

I'm importing it in my app.js using global properties: VueApp.config.globalProperties.__ = __; and the function is accessible everywhere inside of . However, it isn't accessible inside of script setup which is where I also need it.

The only way to use it is by importing the composable into each component, but I have many components that need to use this function. Are there better ways to do this than importing the composable repeteadly?

0 likes
0 replies

Please or to participate in this conversation.