tanmuhittin / laravel-google-translate

Translate translation files to other languages using google translate or another translation api
MIT License
424 stars 71 forks source link

Should handle resources/views/vendor/$package/ and resources/lang/vendor/$package/lang.json #44

Open momente-organisieren opened 3 years ago

momente-organisieren commented 3 years ago
  1. currently views in resources/views/vendor/$package are being ingored
  2. lang.json is only written to resources/lang/lang.json

proposed outcome

additional notes

laravel doc suggests to publish vendor packages to resources/lang/vendor/$vendor/lang.json

translations genarated by laravel-google-translate that have been read from `resources/vendor/$package/lang.json should also be written to this target.

now only lang/lang.json is supported and used

JsonArrayFileTranslator.php#L46

$file = fopen(resource_path('lang/' . $target_locale . '.json'), "w+");
momente-organisieren commented 3 years ago

The workaround that worked at least to have the views, but is kinda fiddly has been:

  1. mv resources/views/vendor/$the-package-name resources/views/$the-package-name
  2. alter JsonArrayFileTranslator to write to a seperate directory (e.g. lang/test/lang.json)
  3. run php artisan translate:files
  4. mv resources/views/$the-package-name resources/views/vendor/$the-package-name
  5. copy lang/test/lang.json to lang/vendor/$the-package-name/lang.json

done

momente-organisieren commented 3 years ago

on that journey another fine option would be to specify only a source lang.json and to skip the whole file reader work that parses views and controllers .. maybe as a Console Command flag

itsrexb commented 2 years ago

The problem here is that it ignores any(?) directory named "vendor" In /src/TranslationFileTranslators/JsonArrayFileTranslator.php line 103 replace the line below and it will work $finder->in(base_path())->exclude('storage')->exclude('vendor')->in(base_path().DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'views'.DIRECTORY_SEPARATOR.'vendor')->name('*.php')->name('*.twig')->name('*.vue')->files();

itsrexb commented 7 months ago

There's a security issue here that needs to be applied immediately 0777 permission is too open https://github.com/tanmuhittin/laravel-google-translate/pull/58/files#diff-227ca57210f13336f78c103af73ea7fd5f5cf04337a0425a827acce83cbe51b5L62

Umar-Farooq-Shafi commented 5 months ago

Is there any workaround using php files?

itsrexb commented 5 months ago

Is there any workaround using php files?

you can use my PR here https://github.com/tanmuhittin/laravel-google-translate/issues/44#issuecomment-2057909266

Umar-Farooq-Shafi commented 5 months ago

@itsrexb Does it work with the .php extension inside the lang/vendor/filament-actions/en directory?