Skip to content

Commit 3a17c8e

Browse files
authored
Adds support for og:locale (#28)
1 parent 169600d commit 3a17c8e

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ url(string $url)
5252
title(string $title)
5353
description(string $description)
5454
image(string $url)
55+
locale(string $locale)
5556

5657
twitterCreator(string $username)
5758
twitterSite(string $username)
@@ -158,6 +159,16 @@ If you wish to change the URL, call `seo()->url()`:
158159
seo()->url(route('products.show', $this->product));
159160
```
160161

162+
### Locale
163+
164+
To set the `og:locale` property:
165+
166+
```php
167+
seo()->locale('de_DE');
168+
```
169+
170+
Expected format is `language_TERRITORY`.
171+
161172
### Modifiers
162173

163174
You may want to modify certain values before they get inserted into the template. For example, you may want to suffix the meta `<title>` with `| ArchTech` when it has a non-default value.

assets/views/components/meta.blade.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
@if(seo('site')) <meta property="og:site_name" content="@seo('site')"> @endif
2222

23+
@if(seo('locale')) <meta property="og:locale" content="@seo('locale')" /> @endif
24+
2325
@if(seo('image')) <meta property="og:image" content="@seo('image')" /> @endif
2426

2527
@if(seo('url'))

src/SEOManager.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* @method $this site(string $site = null, ...$args) Set the site name.
1616
* @method $this image(string $url = null, ...$args) Set the cover image.
1717
* @method $this type(string $type = null, ...$args) Set the page type.
18+
* @method $this locale(string $locale = null, ...$args) Set the page locale.
1819
* @method $this twitter(enabled $bool = true, ...$args) Enable the Twitter extension.
1920
* @method $this twitterCreator(string $username = null, ...$args) Set the Twitter author.
2021
* @method $this twitterSite(string $username = null, ...$args) Set the Twitter author.
@@ -56,7 +57,7 @@ public function all(): array
5657
protected function getKeys(): array
5758
{
5859
return collect([
59-
'site', 'title', 'image', 'description', 'url', 'type',
60+
'site', 'title', 'image', 'description', 'url', 'type', 'locale',
6061
'twitter.creator', 'twitter.site', 'twitter.title', 'twitter.image', 'twitter.description',
6162
])
6263
->merge(array_keys($this->defaults))

tests/Pest/ManagerTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,14 @@
146146
->toContain('<meta property="og:type" content="foo" />') // overridden
147147
->not()->toContain('website');
148148
});
149+
150+
test('og:locale is not included by default', function () {
151+
expect(meta())
152+
->not()->toContain('og:locale');
153+
});
154+
155+
test('og:locale can be added to the template', function () {
156+
seo()->locale('de_DE');
157+
158+
expect(meta())->toContain('<meta property="og:locale" content="de_DE" />');
159+
});

0 commit comments

Comments
 (0)