Closed underdpt closed 2 years ago
Thank you for the good work! PR looks fine. Needs to be tested. Could you add a unit test for this case?
Yeah, i can add it to testTranslatePhpFilesCommand()
or make a new testTranslateVendorPhpFilesCommand()
that would be almost a 1-1 copy. What would you prefer?
you can add it to existing one. testTranslatePhpFilesCommand
Just added it.
Also I found that the target folder might not exists when running the tests, so added a check for that.
I will test locally and merge it this weekend. Good job. Thank you for your contribution!
Tests are not passing. Please check
There was 1 failure:
1) Tanmuhittin\LaravelGoogleTranslateTests\Unit\TranslateFilesCommandTest::testTranslatePhpFilesCommand
Failed asserting that file "/Users/karabas/Desktop/laravel-google-translate/tests/Unit/../test-resources/resources/lang/tr/tests.php" exists.
/Users/karabas/Desktop/laravel-google-translate/tests/Unit/TranslateFilesCommandTest.php:22
`
``
I've just checked. My developmen OS is Windows, and it seems the regex to filter the paths chokes on unix or mixed folder separator. I've upgraded the function to search the lang files to always use unix paths and corrected the regex.
so i need this
thanks
This PR enable the translation of php language files under
resource/lang/vendor
.It modifies some core functions from
PhpArrayFileTranslator.php
:get_translation_files
now uses a recursive iterator that gets all files where the path includes a folder named with the base locale (ex:/en/
). This might be an issue if we have something like this:/lang/es/weird/en/file.php
but I can't remember to have seen anything like this.get_language_file_address
simply replaces the first occurence of the base locale to the target locale on the file, that allows it to work withlang/en/...
and also withlang/vendor/package/en/...
get_language_file_address
now returns the full path of the target file, not only the dirname./vendor/
folder and then we use the file path to get the namespaced translation key, and we add the namespace to Laravel's translation app to prevent missing translations from packages that have not been booted or that doesn't register the namespace on it's service providerI also made some cosmetic changes for better readability.
NOTE: this is only for php lang files. I don't know any package that ships with a json translation file under
/vendor/
so this is missing translating vendor json files. If you know such package, please tell me so I can add a PR for that so the package is consistent.