I want to format my datetime outside the component.
function transformDatetime(config, value) { if (value) { return $d(new Date(value), config); } return $t('-'); }
I'm trying to get $t from the application instance. But it only works in component context, just like useI18n.
import { getCurrentInstance } from 'vue' export default function useGlobal() { const instance = getCurrentInstance() if (!instance) return return instance.appContext.config.globalProperties }
I found the solution. Just import your
i18n
into a file outside your application anduse i18n.global.t