xiCO2k / laravel-vue-i18n

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

How to use nested Json? #134

Closed chris-hud closed 1 year ago

chris-hud commented 1 year ago

Hi, I am unable to retrieve nested json. It seems similar to this closed issue here but I don't understand the resolution https://github.com/xiCO2k/laravel-vue-i18n/issues/130

Using laravel, with vue, inertia, vite

en.json

{
        "dashboard": "Your Name",
        "sidebar": {
            "one": "this should print"
        }
}

app.js

return createApp({ render: () => h(App, props) })
       .use(i18nVue, {
                resolve: async lang => {
                    const langs = import.meta.glob('../../lang/*.json');
                    return await langs[`../../lang/${lang}.json`]();
                }
            })
       ...

The imported file (from network tab) looks like this

export const dashboard = "Your Name";
export const sidebar = {
    one: "this should print"
};
export default {
    dashboard: dashboard,
    sidebar: sidebar
};

Plugin working successfully for non-nested data.

{{$t("dashboard")}}
 prints Your Name
{{$t("sidebar.one")}}
 prints sidebar.one
xiCO2k commented 1 year ago

That is not supposed to work. I don't think Laravel does that with the .json translations.