Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default package language #98

Open
SvetoslavStefanov opened this issue Apr 27, 2023 · 1 comment
Open

Default package language #98

SvetoslavStefanov opened this issue Apr 27, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@SvetoslavStefanov
Copy link

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.

@samberrry samberrry added the enhancement New feature or request label Apr 27, 2023
@samberrry
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants