-
-
Notifications
You must be signed in to change notification settings - Fork 156
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
orderByTranslation scope seems to ignore fallback locale #71
Comments
I'm sorry to re-open this issue, but it now returns fallback translation indeed, but not sorted, despite method's name. |
I would love to take a look into this and proper fix it this time. Could you please provide an example of what you have on your database, your expected output and the final result? It would be easier to put into context 👍 |
Sure ! This is my database:
Then:
I expected both lists to be sorted the same. Hope this helps ! |
Thank you for such a detailed report! I'll check it out tomorrow and see if I can fix it 👍 |
The problem is that it joins and orders the current app translation The scope should use a similar approach like BUT I want to note that this will possibly get dropped during #41 because I see no way to order in DB by PHP written fallback detection logic. For me the fallback customization and refactoring has higher priority than scopes. I'm open for a discussion and also for ideas how to still fix it? An idea would be to switch to Laravel 6 only and use lazy collections to increase PHP sort performance? 🤔 |
I think this can be solved using a CASE when ordering like the one I deleted on previous commits, but inside the join in this case. So if you order in the join you would get the Saying all of this from memory on the phone. I could be totally wrong on this 😅 |
I would say no because you have to order by different rows. folder: To order folder#12 with the right value into the right place you have to use the After the strategy classes the only way I see would be to order in PHP to use the strategies and 100% order by the same values that are displayed. For smaller collections this is no problem. But the moment you have a lot locales and/or entities it will reduce performance a lot. 😔 |
We faced this same scenario at work and I think we solved it with that order inside the join. I’ll take a look at it tomorrow and see if it works. I wouldn’t consider it an option to do it in php though. |
Not yet but I don't want to reject #41 because of an order scope. So I'm fine with every fix, but it could be that v12 will drop this scope. |
My use case is two locales and few records to sort, so I'm ok with Laravel's collection sorting for now. Maybe I just can make a suggestion: always load translation for requested locale AND fallback locale unless requested locale is the same. It wouldn't be too hard on the DB. Unless it's already planned for next release ? |
The next major version won't have any some fallback locale. Atm we already have - I believe 2 or 3 fallback algorithms implemented.
So everything done in DB could match but doesn't have to the PHP result. It's also a pain to maintain. 😔 That's why I want to split this into separate classes which could get combined or not, the user can write custom fallback algorithms, like looping the request accept-language header or whatever the user wants to do. |
I understand how hard it can be. Translations have always been a PITA. I can't wait to see what the future release will have to offer on that matter, and will try to contribute to the extend of my possibilities. |
I will reopen it if David wants to fix it? #41 will need some time, I would say not even or very end of this year. It still needs some more planning and also some code work. |
I tried to find a solution for this for a time now but I can't accomplish a thing. This is the result I came up with for the join statement:
The issue is that the I'm sorry, but I'll put my efforts on the Test refactoring features for now. I recommend to write the query by yourself, @RichardDern, since this looks like a very specific scenario. Sorry for the inconvenience. |
Okay, i would keep it open. If someone else finds a solution. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This issue has been automatically closed because it has not had recent activity. Thank you for your contributions. |
Describe the bug
orderByTranslation scope seems to ignore fallback locale.
To Reproduce
orderByTranslation
: list is OKapp()->setLocale('en')
orderByTranslation
: list is empty (assuming no model was ever translated to en)I'm supposed to write mostly in French, but some articles in English. As such, my main
locale
as well as myfallback_locale
both are 'fr' in Laravel's config. In config/translatable.php, I setlocale
tonull
,use_fallback
totrue
,use_property_fallback
totrue
, andfallback_locale
tonull
.Expected behavior
In the absence of translation in English, I would expect
orderByTranslation
to return the expected list with the French translations available, instead of nothing at all (still assuming I have only French Translations in my database at the moment).Versions (please complete the following information)
The text was updated successfully, but these errors were encountered: