Snapshot of main at 9f39a6e1e (2026-11-02)

This commit is contained in:
Ronald Huynen committed 2026-11-02 10:41:47 +01:00
commit 6ccf1792d7
2580 files changed
+1040202

No files matched your search

+35
View File
@@ -0,0 +1,35 @@
<?php
namespace App\Polls;
/**
* Picks a label from a per-locale array: {"en": "...", "nl": "..."}.
*/
class Localized
{
/**
* The label in the given (or current) locale, falling back to the app fallback
* locale and then to the first label that is filled in.
*/
public static function pick(?array $labels, ?string $locale = null): string
{
$labels = array_filter($labels ?? [], fn ($label) => is_string($label) && trim($label) !== '');
$locale = $locale ?? app()->getLocale();
return $labels[$locale]
?? $labels[config('app.fallback_locale')]
?? (string) reset($labels);
}
/**
* Validation rule: at least one locale has a label.
*/
public static function filledRule(): \Closure
{
return function (string $attribute, $value, \Closure $fail) {
if (!is_array($value) || self::pick($value) === '') {
$fail(__('Fill in at least one language.'));
}
};
}
}