binshops / laravel-blog

Laravel Blog Package/ Laravel CMS. Easiest way to add a blogging system to your Laravel website. Laravel Blog.

Home Page:https://www.binshops.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Default package language

SvetoslavStefanov opened this issue · comments

Hey,
The website I'm building is not by default translated to English (although it has an English translation). So initially I went to ...\config\binshopsblog.php and changed default_language to the language I wanted. When I went to localhost/blog_setup and finished the process. But the default language was still en.

I added another language from Blog admin -> Add new Language. Then I added a post with that language and the post was inaccessible when I went to http://localhost/blog. The reason was that by default my language was not set to English.

If you're having this issue, the reason for this are:

  1. The default language is stored in the DB, not in the config file. Go to your DB -> binshops_configurations -> search for DEFAULT_LANGUAGE_LOCALE
  2. In vendor\binshops\laravel-blog\src\Middleware\DetectLanguage.php it's trying to get the default language wrong. It's trying to access $request->route('locale'), but it should be app()->getLocale()
  3. When a locale is not found, it's trying to access the default one from the DB, not from the config file

It's pretty much enough to change the default language in the DB.

My proposal to the package's owner is:

  1. When executing POST->http://localhost/blog_setup - either ask for default language OR get the one from config\binshopsblog.php
  2. Store the default language either in the config file or in the DB - not at both places at once
  3. In vendor\binshops\laravel-blog\src\Middleware\DetectLanguage.php instead of $request->route('locale'), make it app()->getLocale() - everywhere else in Laravel people are using the second approach.
  4. In vendor\binshops\laravel-blog\src\Middleware\DetectLanguage.php instead of accessing the default language from the DB, access it from the config file.

I got a middleware before Middleware\DetectLanguage.php that sets the app's default language to my default if there is none in the URL, but the package cannot access it, because it's trying to get it via $request->route('locale'). I tried setting this attribute in the $request object, but unsuccesfuly. Most people are using app()->setLocale() nowadays.

Hey,
thanks for your comment,

I agree, duplicate presence of locale config is wrong, and it must be changed.

I will also take a look at the \DetectLanguage.php to see if it needs improvement.

Thanks for your time.