laravel-google-translate icon indicating copy to clipboard operation
laravel-google-translate copied to clipboard

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

Open momente-organisieren opened this issue 3 years ago • 7 comments

  1. currently views in resources/views/vendor/$package are being ingored
  2. lang.json is only written to resources/lang/lang.json

proposed outcome

  • Finder scans resoures/views/vendor/$package
  • collects strings
  • strings get translated
  • JsonArrayFileTranslator writes to resoureces/lang/vendor/$package/lang.json

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 avatar Apr 27 '21 14:04 momente-organisieren

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 avatar Apr 27 '21 15:04 momente-organisieren

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

momente-organisieren avatar Apr 27 '21 15:04 momente-organisieren

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 avatar Aug 08 '22 03:08 itsrexb