stoic multilingual

This commit is contained in:
elvira
2026-09-28 18:17:33 +03:00
parent 023c11019c
commit aa051525a1
20 changed files with 696 additions and 27 deletions
+17 -1
View File
@@ -2,16 +2,32 @@
namespace App\Models;
use App\Services\Stoic;
use Illuminate\Database\Eloquent\Model;
use JacobJoergensen\LaravelPaper\Attributes\ContentPath;
use JacobJoergensen\LaravelPaper\Attributes\Driver;
use JacobJoergensen\LaravelPaper\Attributes\Timestamps;
use JacobJoergensen\LaravelPaper\Paper;
// Points at the default locale (el), which Stoic writes every field to. Other
// locales hold only the translatable fields — use localized() to get a page
// with those layered on top for the current locale.
#[Driver("markdown")]
#[ContentPath("resources/stoic/content/pages")]
#[ContentPath("resources/stoic/content/el/pages")]
#[Timestamps]
class StoicPage extends Model
{
use Paper;
/**
* The page in the current locale: the default-locale entry, with the
* current locale's non-empty fields (and body) swapped in. Untranslated
* fields fall back to the default locale.
*/
public static function localized(string $slug): ?static
{
$page = static::firstWhere('slug', $slug);
return $page?->forceFill(Stoic::localeOverrides("pages/{$slug}.md"));
}
}