<commit_before><?php

// use-case: if you use language image-tags, and want to show the images of the user's current language 
// first, and everything else later
// https://processwire.com/talk/topic/21246-images-gallery-sorting-order-based-on-language/?tab=comments#comment-183814
// https://processwire.com/blog/posts/processwire-updates-and-new-field-types/

// assuming you use delayed output strategy...
$content .= "<div class='gallery'>";

$userlang = $user->language->name;

$content .=  "$userlang <hr>"; // just for debugging

$g = $page->gallery->sort('tags'); // just for debugging: show all, sorted by tag
$content .=  "all: <br>";
foreach($g as $pic) {
    $content .=  "{$pic->tags} {$pic->url}<br>";
}
$content .=  "<hr>";

$g = $page->gallery->find("tags=$userlang"); // only user's current language images
$content .=  "userlang: <br>";
foreach($g as $pic) {
    $content .=  "{$pic->tags}  {$pic->url}<br>";
}

$g = $page->gallery->find("tags!=$userlang"); // ... and then, everything else
$content .=  "NOT userlang: <br>";
foreach($g as $pic) {
    $content .=  "{$pic->tags}  {$pic->url}<br>";
}

$content .= "</div>";<commit_msg>removed unnecessary debug code<commit_after><?php

// use-case: if you use language image-tags, and want to show the images of the user's current language 
// first, and everything else later
// https://processwire.com/talk/topic/21246-images-gallery-sorting-order-based-on-language/?tab=comments#comment-183814
// https://processwire.com/blog/posts/processwire-updates-and-new-field-types/

$userlang = $user->language->name;

$g = $page->gallery->find("tags=$userlang"); // only user's current language images
foreach($g as $pic) {
    $content .=  "<img src='{$pic->url}'>";
}

$g = $page->gallery->find("tags!=$userlang"); // ... and then, everything else
foreach($g as $pic) {
    $content .=  "<img src='{$pic->url}'>";
}
{'fraction_non_alphanumeric': 0.21117021276595746, 'fraction_numerical': 0.011702127659574468, 'mean_word_length': 4.016, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 37, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5865058', 'n_tokens_mistral': 643, 'n_tokens_neox': 618, 'n_words': 151}