Comments (7)
Awesome this is the solution, thank you!
For displaying english in all versions, you have to remove where("lang_id" , '=' , $request->get("lang_id")) or change it to the english id in BinshopsReaderController.
from laravel-blog.
You can use sessions to store active language. And English could be the default language. Then you use select input or anything like that for a user to change locale.
That feature needs to use middleware to always check active language.
from laravel-blog.
I think you misunderstand my question. What you describe is already in place.
But the problem is if the user selects german, then the blog only shows posts that have been written with the selected language german. I want all languages to show posts that have been written for the language english though. And not the posts of the selected language.
from laravel-blog.
Hi guys @dappstatus @jmatike ,
thanks for reporting.
I've created a branch named "no-locale-route-support" to add this functionality. Unfortunately Laravel does not support optional prefix in route grouping, and this made it a little complex.
Anyway you @dappstatus can use the changes in this branch:
https://github.com/binshops/laravel-blog/tree/no-locale-route-support
now you can access your blog at: Default: www.domainname (calls the english version)
but as you see, the urls for posts and categories include the {locale}. So, I've changed the DetectLanguage logic to flag requests when the locale is not required with this attribute: noLocaleRoute
With the help of this attribute you can generate routes dynamically so that they do not include locale. That was the explanation of what is the logic, probably you are interested into contribute to add this functionality.
Thanks, have a great day ;)
from laravel-blog.
To contribute to this feature try to make PR from this branch:
https://github.com/binshops/laravel-blog/tree/no-locale-route-support
from laravel-blog.
So far this is working very well. I'm looking for 1 more improvement though, that I can't find the solution for.
I use 3 languages in my project, with the default being en
In LaravelLocalization you can set 'hideDefaultLocaleInURL' => true.
This will result in an auto redirect of /en/ to / by using 'prefix' => LaravelLocalization::setLocale() in web routes.
Now I tried to do the same thing for the laravel-blog routes. I tried to change:
Route::group(['prefix' => "/{locale}/".config('binshopsblog.blog_prefix', 'blog')], function () {
to
Route::group(['prefix' => (App::getLocale() !== 'en' ? "/{locale}/" : "/").config('binshopsblog.blog_prefix', 'blog')], function () {
Although the redirect itself works this way, it results in the following error:
Route [binshopsblog.single] not defined
which has to do with this line of code:
<a href='{{$noLocaleRoute == 1 ? $post->url('') : $post->url($locale)}}'><span>{{$post->title}}</span></a>
Any idea what the issue with this line of code is after that change in the routes?
After some more testing it seems like ->url('')
doesn't work after the change in route, it has no result when debugging.
from laravel-blog.
New feature added:
https://github.com/binshops/laravel-blog/releases/tag/v9.3.0
from laravel-blog.
Related Issues (20)
- Error viewing blog post: Call to a member function diffForHumans() on string HOT 1
- How can I add Pagination in blogs
- Undefined variable. HOT 2
- How can I remove uploaded media If I want ?
- 401 error when commenting as a normal user
- Fulltext Search - search throughout all blog posts HOT 1
- Need more instructions how to use.
- Error when searching blog
- SSL Issue HOT 1
- fulltext error HOT 1
- Undefined variable $noLocaleRoute HOT 4
- Attempt to read property "locale" on null HOT 4
- Unauthorized on binshops/laravel-blog urls HOT 1
- Laravel 9.X migrate gives issues
- Maybe it is a bug on relation language in model BinshopsCategoryTranslation?
- Not showing cats and posts in Russian HOT 4
- Support for Laravel 10x HOT 2
- Feature Request: automatically add blog posts to sitemap.xml HOT 3
- Default package language HOT 1
- binshopsblog : blog_admin is returning 401 Unauthorized HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-blog.