amiranagram/localizator

lang folder moved in laravel 9.x

fjeansson opened this issue · 6 comments

the lang folder is no longer under resources, so the following line in helpers.php is incorrect for laravel 9.x installs.

return resource_path('lang'.($path !== '' ? DIRECTORY_SEPARATOR.$path : ''));

zamon commented

same with me, error creating directory when using laravel 9.x

If you noticed, there's a condition: ! function_exists('lang_path') so the function won't be registered in Laravel 9. Not sure how you have this problem, since I'm using this package on L9 and older versions.

FYI, found this in Laravel's codebase:

$this->useLangPath(value(function () {
    if (is_dir($directory = $this->resourcePath('lang'))) {
        return $directory;
    }

    return $this->basePath('lang');
}));

So, make sure lang folder doesn't exist in resources otherwise that directory will be registered as the default lang path.

If you noticed, there's a condition: ! function_exists('lang_path') so the function won't be registered in Laravel 9. Not sure how you have this problem, since I'm using this package on L9 and older versions.

This is still a problem in Laravel 9. It is a problem because the lang_path-function that you declare in helpers.php actually overrides Laravels own lang_path-function. Your packages helpers.php is run before Laravels Illuminate/Foundation/helpers.php so your version of the function is used. There is a test for function_exists('lang_path') also in Laravels helpers.php.

If you want to be backwards compatible and support Laravel before lang_path then you might have to detect this at runtime.

Fixed in 0.11.1

This piece of code from the application.php shows that lang_path() function first looks for the old path( resource/lang), if for any reason it is this directory, it returns the same one, if not, it returns the new path (correct path).

$this->useLangPath(value(function () {
            return is_dir($directory = $this->resourcePath('lang'))
                        ? $directory
                        : $this->basePath('lang');

So for the lang_path() to work properly. Delete or move the old directory created for any reason