Giter Site home page Giter Site logo

Comments (7)

dappstatus avatar dappstatus commented on May 8, 2024 1

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.

jmatike avatar jmatike commented on May 8, 2024

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.

dappstatus avatar dappstatus commented on May 8, 2024

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.

samberrry avatar samberrry commented on May 8, 2024

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.

samberrry avatar samberrry commented on May 8, 2024

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.

dappstatus avatar dappstatus commented on May 8, 2024

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.

samberrry avatar samberrry commented on May 8, 2024

New feature added:
https://github.com/binshops/laravel-blog/releases/tag/v9.3.0

from laravel-blog.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.