Localization
Introduction
Headlines and nouns may use translation keys from your app's lang files. Storyfeed translates them when retrieving the feed, using the application's current locale. Set it for each request as described in Laravel's locale configuration; Storyfeed does not choose the reader's locale.
Translating Headlines
Define the template for each supported locale, starting with the default:
return [
// Without this line, English readers see "feed.order_placed".
'order_placed' => ':actor placed :object at :target',
];return [
'order_placed' => ':actor a passé :object chez :target',
];Pass the translation key to FeedHeadline::trans():
use App\Models\Order;
use Storyfeed\Facades\Story;
use Storyfeed\FeedHeadline;
Story::for(Order::class)
->verb('place')
->headline(FeedHeadline::trans('feed.order_placed'));With the locale set to French:
Translated templates keep linked tokens and optional segments. You may reorder tokens in each translation. Undefined keys are displayed as written.
anonymousHeadline() and missingHeadline() take a FeedHeadline too.
Translating Group Headlines
Add a template for the repeat group to each locale's feed.php file:
return [
'order_placements' => ':actor made :count order placements at :target',
];return [
'order_placements' => ':actor a passé commande :count fois chez :target',
];Pass the key to the group's headline:
use App\Models\Order;
use Storyfeed\Facades\Story;
use Storyfeed\FeedHeadline;
use Storyfeed\Grouping\GroupBuilder;
Story::for(Order::class)
->verb('place')
->grouped(
fn (GroupBuilder $group) => $group
->repeat(FeedHeadline::trans('feed.order_placements')),
);use App\Models\Order;
use Storyfeed\Facades\Story;
use Storyfeed\FeedHeadline;
use Storyfeed\Grouping\Group;
Story::for(Order::class)
->verb('place')
->grouped(
Group::repeat()->headline(FeedHeadline::trans('feed.order_placements')),
);With the locale set to French:
The translation is resolved when the feed is read, including when definitions are cached. Role tokens remain linked.
Translated group tokens are not checked at boot. Each locale must use only tokens supported by the group's axis.
| Group Headline | How It Is Rendered |
|---|---|
A string or FeedHeadline::trans() | a template whose role tokens and count are replaced |
| A closure | finished text; its result is not processed as a token template |
Translating Nouns
Pass a translation key to FeedNoun::trans() for a group's noun:
use App\Models\Order;
use Storyfeed\Facades\Story;
use Storyfeed\FeedNoun;
Story::for(Order::class)->fallback()->noun(FeedNoun::trans('nouns.order'));Separate singular and plural forms with a pipe:
return [
'order' => 'order|orders',
];return [
'order' => 'commande|commandes',
];See Aggregation for where nouns appear.