Pre-1.0. Not intended for public use yet. The API is subject to undocumented change, and these pages may already be wrong about it.

Skip to content

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:

lang/en/feed.php
php
return [
    // Without this line, English readers see "feed.order_placed".
    'order_placed' => ':actor placed :object with :target',
];
lang/fr/feed.php
php
return [
    'order_placed' => ':actor a passé :object auprès de :target',
];

Pass the translation key to FeedHeadline::trans():

routes/feed.php
php
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:

ES
Erica Sinclair a passé Order #1035 auprès de Scoops Ahoy

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 Nouns ​

Pass a translation key to FeedNoun::trans() for a group's noun:

routes/feed.php
php
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:

lang/en/nouns.php
php
return [
    'order' => 'order|orders',
];
lang/fr/nouns.php
php
return [
    'order' => 'commande|commandes',
];

See Aggregation for where nouns appear.

Released under the MIT License.