martinlindhe / laravel-vue-i18n-generator

Generates a vue-i18n compatible include file from your Laravel translations
MIT License
306 stars 207 forks source link

'Excludes' doesn't work for directories. #87

Open aezur opened 5 years ago

aezur commented 5 years ago

Assuming a directory structure of:

- lang
    - en
        - file_name_1.php
        - directory_name
            - file_name_2.php

And in the config file:

'excludes' => [
        'file_name_1',    /* Works */
        "directory_name",    /* Doesn't work */
    ],

When art vue-i18n:generate is run, then everything inside directory_name will be included in the output file.

Placing directory_name/file_name_2' into theexcludes` array is a workaround, but it doesn't suit my use case.

martinlindhe commented 5 years ago

See #81

aezur commented 5 years ago

Thanks for the reply, but it doesn't address my issue. I have defined my root folder. The comment of the excludes array states you can add directories to the array to exclude them. You cannot. This feature does not work. EDIT: The desired behaviour is that when the path to a directory is added to the excludes array, that directory and the files it contains are excluded from the output of art vue-i18n:generate.

martinlindhe commented 5 years ago

Alright, thanks for letting me know

octfx commented 5 years ago

Looking at the source code (https://github.com/martinlindhe/laravel-vue-i18n-generator/blob/master/src/Generator.php#L56) the generator will only compare filenames ignoring the folder path.
So if you wanted to exclude file_name_2.php you could just add file_name_2 to your excludes array as a workaround.

martinlindhe commented 5 years ago

I'm not working on this code atm, but you are very welcome to submit a PR to fix this.

karolispx commented 5 years ago

Hi @martinlindhe , do you have any guidelines for PRs?

martinlindhe commented 5 years ago

@karolispx nothing special, just open a PR and we take it from there!

karolispx commented 5 years ago

I took a quick look at this and the code at https://github.com/martinlindhe/laravel-vue-i18n-generator/blob/master/src/Generator.php#L56 is used to exclude directories inside 'resources/lang/' directory, i.e. if you had a few languages: en, ko, ru - you could exclude the whole language directory by adding the folder name to 'excludes' at https://github.com/martinlindhe/laravel-vue-i18n-generator/blob/master/src/config/vue-i18n-generator.php#L41, i.e.'excludes' => ['ko'],

The actual problem is not being able to exclude directory from a language folder, i.e. excluding directory '/resources/lang/en/custom' does not work.

This function https://github.com/martinlindhe/laravel-vue-i18n-generator/blob/master/src/Generator.php#L259 handles file exclusion so I think appropriatefunction needs to be written for excluding directories and called here https://github.com/martinlindhe/laravel-vue-i18n-generator/blob/master/src/Generator.php#L215

Will take a closer look when I have some time.