diff --git a/README.md b/README.md index f0b09bf..2816341 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,7 @@ url(string $url) title(string $title) description(string $description) image(string $url) +locale(string $locale) twitterCreator(string $username) twitterSite(string $username) @@ -158,6 +159,16 @@ If you wish to change the URL, call `seo()->url()`: seo()->url(route('products.show', $this->product)); ``` +### Locale + +To set the `og:locale` property: + +```php +seo()->locale('de_DE'); +``` + +Expected format is `language_TERRITORY`. + ### Modifiers You may want to modify certain values before they get inserted into the template. For example, you may want to suffix the meta `` with `| ArchTech` when it has a non-default value. diff --git a/assets/views/components/meta.blade.php b/assets/views/components/meta.blade.php index a09a228..1b7f3fe 100644 --- a/assets/views/components/meta.blade.php +++ b/assets/views/components/meta.blade.php @@ -20,6 +20,8 @@ @if(seo('site')) <meta property="og:site_name" content="@seo('site')"> @endif +@if(seo('locale')) <meta property="og:locale" content="@seo('locale')" /> @endif + @if(seo('image')) <meta property="og:image" content="@seo('image')" /> @endif @if(seo('url')) diff --git a/src/SEOManager.php b/src/SEOManager.php index 3a7e1d0..0e99e8f 100644 --- a/src/SEOManager.php +++ b/src/SEOManager.php @@ -15,6 +15,7 @@ * @method $this site(string $site = null, ...$args) Set the site name. * @method $this image(string $url = null, ...$args) Set the cover image. * @method $this type(string $type = null, ...$args) Set the page type. + * @method $this locale(string $locale = null, ...$args) Set the page locale. * @method $this twitter(enabled $bool = true, ...$args) Enable the Twitter extension. * @method $this twitterCreator(string $username = null, ...$args) Set the Twitter author. * @method $this twitterSite(string $username = null, ...$args) Set the Twitter author. @@ -56,7 +57,7 @@ public function all(): array protected function getKeys(): array { return collect([ - 'site', 'title', 'image', 'description', 'url', 'type', + 'site', 'title', 'image', 'description', 'url', 'type', 'locale', 'twitter.creator', 'twitter.site', 'twitter.title', 'twitter.image', 'twitter.description', ]) ->merge(array_keys($this->defaults)) diff --git a/tests/Pest/ManagerTest.php b/tests/Pest/ManagerTest.php index f99bf91..aa9f25b 100644 --- a/tests/Pest/ManagerTest.php +++ b/tests/Pest/ManagerTest.php @@ -146,3 +146,14 @@ ->toContain('<meta property="og:type" content="foo" />') // overridden ->not()->toContain('website'); }); + +test('og:locale is not included by default', function () { + expect(meta()) + ->not()->toContain('og:locale'); +}); + +test('og:locale can be added to the template', function () { + seo()->locale('de_DE'); + + expect(meta())->toContain('<meta property="og:locale" content="de_DE" />'); +});