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

[5.x]: SORT_LOCALE_STRING not working out of the box #14509

Closed
wsydney76 opened this issue Mar 1, 2024 · 1 comment
Closed

[5.x]: SORT_LOCALE_STRING not working out of the box #14509

wsydney76 opened this issue Mar 1, 2024 · 1 comment
Assignees
Labels

Comments

@wsydney76
Copy link

What happened?

Description

Maybe a bug, maybe not, just wondering how to handle this.

Now that nested entries owners are eager-loadable, I tried this in order to avoid more complex/additional db queries:

{% set roles = craft.entries
    .type('roles')
    .relatedTo(person)
    .with(['owner'])
    .collect
%}

{% set rolesSortedByFilmTitle = roles.sortBy('owner.title', SORT_LOCALE_STRING) %}

{% for role in rolesSortedByFilmTitle %}
    {{ role.owner.title }}: {{ role.roleName }}
{% endfor %}

With craft.app.locale.id set to de-DE, I expected entries to be sorted with locale specific rules (the ÄÖÜäöüß thing), but that isn't the case.

Looks like that you have to call setlocale(LC_COLLATE, str_replace('-', '_', Craft::$app->locale->id)); in PHP yourself first (note the underscore).

Could write a Twig extension/Collection makro for now, but don't like to introduce new syntax.

Also hesitating to set this globally in a module's init method, might have side effects??

Craft CMS version

Craft 5.0.0-beta.4

PHP version

8.2.13

Operating system and version

Linux 5.15.133.1-microsoft-standard-WSL2

Database type and version

MySQL 8.0.33

Image driver and version

No response

Installed plugins and versions

@brandonkelly
Copy link
Member

This has been resolved for 4.9 (WIP) and 5.0.0-beta.6 (out now).

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

No branches or pull requests

3 participants