xiCO2k / laravel-vue-i18n

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

Language files are not Reading Recursive #84

Closed GekkeGlennDev closed 1 year ago

GekkeGlennDev commented 1 year ago

I used this plugin but i'm running into a issue.

My lang folder structure is as follow:

Lang
| en
  | pages
  | - admin
  | - - dashboard.php
  | pagination.php
  | validation.php
| nl
  | pages
  | - admin
  | - - dashboard.php
  | pagination.php
  | validation.php
| php_en.json
| php_nl.json

But if i read the json files, i only see the translations from the files of the root dir of a languages and not the sub folder translations.

Or is there any fix for it?

App.js:

import './bootstrap';
import '../css/app.css';

import { createApp, h } from 'vue';
import { createInertiaApp } from '@inertiajs/inertia-vue3';
import { InertiaProgress } from '@inertiajs/progress';
import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers';
import { ZiggyVue } from '../../vendor/tightenco/ziggy/dist/vue.m';
import { i18nVue } from 'laravel-vue-i18n';

const appName = window.document.getElementsByTagName('title')[0]?.innerText || 'Laravel';

createInertiaApp({
    title: (title) => `${title} - ${appName}`,
    resolve: (name) => resolvePageComponent(`./Pages/${name}.vue`, import.meta.glob('./Pages/**/*.vue')),
    setup({ el, app, props, plugin }) {
        return createApp({ render: () => h(app, props) })
            .use(plugin)
            .use(ZiggyVue, Ziggy)
            .use(i18nVue, {
                resolve: async lang => {
                    const langs = import.meta.glob('../../lang/php_*.json');
                    return await langs[`../../lang/php_${lang}.json`]();
                }
            })
            .mount(el);
    },
});

InertiaProgress.init({ color: '#4B5563' });

Vite Config:

import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import vue from '@vitejs/plugin-vue';
import i18n from 'laravel-vue-i18n/vite';

export default defineConfig({
    plugins: [
        laravel({
            input: 'resources/js/app.js',
            refresh: true,
        }),
        vue({
            template: {
                transformAssetUrls: {
                    base: null,
                    includeAbsolute: false,
                },
            },
        }),

        // https://github.com/xiCO2k/laravel-vue-i18n
        i18n(),
    ],
});

Versions: Laravel 9.38 PHP: 8.1.0 Yarn: 1.22.19 Vite: 3.0.0 Vue: 3.2.41

GekkeGlennDev commented 1 year ago

Extra info: In a vue file i'm doing this to load a translation:

<script setup>
import { trans } from 'laravel-vue-i18n';
</script>

<template>
{{ trans('pages.dashboard.head.title') }}
</template>

image

xiCO2k commented 1 year ago

Interesting case, will take a look on that shortly.

Thanks.

sebastiaanluca commented 1 year ago

We have a similar case and it's also not reading the php files recursively. It only works for php translation files in the root locale directory.

Translations from auth.php work, but translations from store-admin/store-employee-questions/overview.php are not parsed and placed in the php_de_DE.json file.

Screenshot 2022-12-04 at 21 14 04

As this is a blocking issue for us, how can we help to implement this? JS package dev isn't my strength 😄

xiCO2k commented 1 year ago

Sorry guys, I will need to have a bit more free time to tackle this one.

If anyone want to do a PR for that, it would be lovely ❤️