Skip to content

Commit c72abb8

Browse files
authored
Use underscores in config file (#15)
1 parent 7c03cc0 commit c72abb8

12 files changed

+42
-41
lines changed

README.md

+14-13
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ You will now find a `localizer.php` file in the `config` folder.
8080
Add any locales you wish to support to your published `config/localizer.php` file:
8181

8282
```php
83-
'supported-locales' => ['en', 'nl'];
83+
'supported_locales' => ['en', 'nl'];
8484
```
8585

8686
You can also use one or more custom slugs for a locale:
8787

8888
```php
89-
'supported-locales' => [
89+
'supported_locales' => [
9090
'en' => 'english-slug',
9191
'nl' => ['dutch-slug', 'nederlandse-slug'],
9292
];
@@ -95,7 +95,7 @@ You can also use one or more custom slugs for a locale:
9595
Or you can use one or more custom domains for a locale:
9696

9797
```php
98-
'supported-locales' => [
98+
'supported_locales' => [
9999
'en' => 'english-domain.test',
100100
'nl' => ['dutch-domain.test', 'nederlands-domain.test'],
101101
];
@@ -136,16 +136,17 @@ Update the `stores` array to choose which stores to use.
136136
137137
## 🛠️ More Configuration (optional)
138138

139-
### ☑️ `omitted-locale`
139+
### ☑️ `omitted_locale`
140+
141+
If you don't want your main locale to have a slug, you can set it as the `omitted_locale` (not the custom slug).
140142

141-
If you don't want your main locale to have a slug, you can set it as the `omitted-locale` (not the custom slug).
142143
If you do this, no additional detectors will run after the `UrlDetector` and `OmittedLocaleDetector`.
143144
This makes sense, because the locale will always be determined by those two in this scenario.
144145

145146
Example:
146147

147148
```php
148-
'omitted-locale' => 'en',
149+
'omitted_locale' => 'en',
149150
```
150151

151152
Result:
@@ -155,20 +156,20 @@ Result:
155156

156157
Default: `null`
157158

158-
### ☑️ `trusted-detectors`
159+
### ☑️ `trusted_detectors`
159160

160161
Add any detector class name to this array to make it trusted. (do not remove it from the `detectors` array)
161162
When a trusted detector returns a locale, it will be used as the app locale, regardless if it's a supported locale or not.
162163

163164
Default: `[]`
164165

165-
### ☑️ `url-segment`
166+
### ☑️ `url_segment`
166167

167168
The index of the URL segment that has the locale, when using the `UrlDetector`.
168169

169170
Default: `1`
170171

171-
### ☑️ `route-action`
172+
### ☑️ `route_action`
172173

173174
The custom route action that holds the locale, when using the `RouteActionDetector`.
174175

@@ -182,26 +183,26 @@ Route::group(['locale' => 'nl'], function () {
182183
});
183184
```
184185

185-
### ☑️ `user-attribute`
186+
### ☑️ `user_attribute`
186187

187188
The attribute on the user model that holds the locale, when using the `UserDetector`.
188189
If the user model does not have this attribute, this detector check will be skipped.
189190

190191
Default: `locale`
191192

192-
### ☑️ `session-key`
193+
### ☑️ `session_key`
193194

194195
The session key that holds the locale, when using the `SessionDetector` and `SessionStore`.
195196

196197
Default: `locale`
197198

198-
### ☑️ `cookie-name`
199+
### ☑️ `cookie_name`
199200

200201
The name of the cookie that holds the locale, when using the `CookieDetector` and `CookieStore`.
201202

202203
Default: `locale`
203204

204-
### ☑️ `cookie-minutes`
205+
### ☑️ `cookie_minutes`
205206

206207
The lifetime of the cookie that holds the locale, when using the `CookieStore`.
207208

config/localizer.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
/**
66
* The locales you wish to support.
77
*/
8-
'supported-locales' => [],
8+
'supported_locales' => [],
99

1010
/**
1111
* If your main locale is omitted from the URL, set it here.
1212
* It will always be used if no supported locale is found in the URL.
1313
* Note that no other detectors will run after the OmittedLocaleDetector!
1414
* Setting this option to `null` will disable this detector.
1515
*/
16-
'omitted-locale' => null,
16+
'omitted_locale' => null,
1717

1818
/**
1919
* The detectors to use to find a matching locale.
@@ -35,7 +35,7 @@
3535
* When a trusted detector returns a locale, it will be used
3636
* as the app locale, regardless if it's a supported locale or not.
3737
*/
38-
'trusted-detectors' => [
38+
'trusted_detectors' => [
3939
//
4040
],
4141

@@ -52,36 +52,36 @@
5252
* The index of the segment that has the locale,
5353
* when using the UrlDetector.
5454
*/
55-
'url-segment' => 1,
55+
'url_segment' => 1,
5656

5757
/**
5858
* The attribute or "action" on the route that holds the locale,
5959
* when using the RouteActionDetector.
6060
*/
61-
'route-action' => 'locale',
61+
'route_action' => 'locale',
6262

6363
/**
6464
* The attribute on the user model that holds the locale,
6565
* when using the UserDetector.
6666
*/
67-
'user-attribute' => 'locale',
67+
'user_attribute' => 'locale',
6868

6969
/**
7070
* The session key that holds the locale,
7171
* when using the SessionDetector and SessionStore.
7272
*/
73-
'session-key' => 'locale',
73+
'session_key' => 'locale',
7474

7575
/**
7676
* The name of the cookie that holds the locale,
7777
* when using the CookieDetector and CookieStore.
7878
*/
79-
'cookie-name' => 'locale',
79+
'cookie_name' => 'locale',
8080

8181
/**
8282
* The lifetime of the cookie that holds the locale,
8383
* when using the CookieStore.
8484
*/
85-
'cookie-minutes' => 60 * 24 * 365, // 1 year
85+
'cookie_minutes' => 60 * 24 * 365, // 1 year
8686

8787
];

src/Detectors/CookieDetector.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class CookieDetector implements Detector
1414
*/
1515
public function detect()
1616
{
17-
$key = Config::get('localizer.cookie-name');
17+
$key = Config::get('localizer.cookie_name');
1818

1919
return Cookie::get($key);
2020
}

src/Detectors/OmittedLocaleDetector.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ class OmittedLocaleDetector implements Detector
1313
*/
1414
public function detect()
1515
{
16-
return Config::get('localizer.omitted-locale') ?: null;
16+
return Config::get('localizer.omitted_locale') ?: null;
1717
}
1818
}

src/Detectors/RouteActionDetector.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class RouteActionDetector implements Detector
1414
*/
1515
public function detect()
1616
{
17-
$action = Config::get('localizer.route-action');
17+
$action = Config::get('localizer.route_action');
1818

1919
return Request::route()->getAction($action);
2020
}

src/Detectors/SessionDetector.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class SessionDetector implements Detector
1414
*/
1515
public function detect()
1616
{
17-
$key = Config::get('localizer.session-key');
17+
$key = Config::get('localizer.session_key');
1818

1919
return Session::get($key);
2020
}

src/Detectors/UrlDetector.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ class UrlDetector implements Detector
1414
*/
1515
public function detect()
1616
{
17-
$locales = Config::get('localizer.supported-locales');
18-
$position = Config::get('localizer.url-segment');
17+
$locales = Config::get('localizer.supported_locales');
18+
$position = Config::get('localizer.url_segment');
1919
$slug = Request::segment($position);
2020

2121
// If supported locales is a simple array like ['en', 'nl']

src/Detectors/UserDetector.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function detect()
2020
return null;
2121
}
2222

23-
$attribute = Config::get('localizer.user-attribute');
23+
$attribute = Config::get('localizer.user_attribute');
2424

2525
return $user->getAttributeValue($attribute);
2626
}

src/LocalizerServiceProvider.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ protected function mergeConfig()
6767
protected function registerLocalizer()
6868
{
6969
$this->app->bind(Localizer::class, function ($app) {
70-
$locales = $app['config']->get("{$this->name}.supported-locales");
70+
$locales = $app['config']->get("{$this->name}.supported_locales");
7171
$detectors = $app['config']->get("{$this->name}.detectors");
7272
$stores = $app['config']->get("{$this->name}.stores");
73-
$trustedDetectors = $app['config']->get("{$this->name}.trusted-detectors");
73+
$trustedDetectors = $app['config']->get("{$this->name}.trusted_detectors");
7474

7575
return new Localizer($locales, $detectors, $stores, $trustedDetectors);
7676
});

src/Stores/CookieStore.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ class CookieStore implements Store
1616
*/
1717
public function store($locale)
1818
{
19-
$name = Config::get('localizer.cookie-name');
20-
$minutes = Config::get('localizer.cookie-minutes');
19+
$name = Config::get('localizer.cookie_name');
20+
$minutes = Config::get('localizer.cookie_minutes');
2121

2222
Cookie::queue($name, $locale, $minutes);
2323
}

src/Stores/SessionStore.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class SessionStore implements Store
1616
*/
1717
public function store($locale)
1818
{
19-
$key = Config::get('localizer.session-key');
19+
$key = Config::get('localizer.session_key');
2020

2121
Session::put($key, $locale);
2222
}

tests/Feature/SetLocaleTest.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ protected function setUp(): void
3030
// Remove any default browser locales
3131
$this->setBrowserLocales(null);
3232

33-
$this->sessionKey = Config::get('localizer.session-key');
34-
$this->cookieName = Config::get('localizer.cookie-name');
33+
$this->sessionKey = Config::get('localizer.session_key');
34+
$this->cookieName = Config::get('localizer.cookie_name');
3535
}
3636

3737
/** @test */
@@ -78,7 +78,7 @@ public function you_can_configure_which_segment_to_use_as_locale()
7878
$this->setSupportedLocales(['en', 'nl']);
7979
$this->setAppLocale('en');
8080

81-
Config::set('localizer.url-segment', 2);
81+
Config::set('localizer.url_segment', 2);
8282

8383
Route::get('some/nl/route', function () {
8484
return App::getLocale();
@@ -222,7 +222,7 @@ public function it_looks_for_a_locale_on_the_authenticated_user()
222222
$this->setSupportedLocales(['en', 'nl']);
223223
$this->setAppLocale('en');
224224

225-
$attribute = Config::get('localizer.user-attribute');
225+
$attribute = Config::get('localizer.user_attribute');
226226
$user = new User();
227227
$user->$attribute = 'nl';
228228

@@ -363,7 +363,7 @@ public function trusted_detectors_ignore_supported_locales_and_may_set_any_local
363363

364364
$routeAction = ['locale' => 'nl'];
365365

366-
Config::set('localizer.trusted-detectors', [
366+
Config::set('localizer.trusted_detectors', [
367367
\CodeZero\Localizer\Detectors\RouteActionDetector::class,
368368
]);
369369

@@ -403,7 +403,7 @@ protected function setAppLocale($locale)
403403
*/
404404
protected function setSupportedLocales(array $locales)
405405
{
406-
Config::set('localizer.supported-locales', $locales);
406+
Config::set('localizer.supported_locales', $locales);
407407

408408
return $this;
409409
}
@@ -417,7 +417,7 @@ protected function setSupportedLocales(array $locales)
417417
*/
418418
protected function setOmittedLocale($locale)
419419
{
420-
Config::set('localizer.omitted-locale', $locale);
420+
Config::set('localizer.omitted_locale', $locale);
421421

422422
return $this;
423423
}

0 commit comments

Comments
 (0)