You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[](https://gitter.im/mcamara/laravel-localization?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[](https://houndci.com)
8
+
## About Fork
9
+
This package is a fork of [mcamara/laravel-localization](https://github.com/mcamara/laravel-localization) with a support for localization switch by domain names like to
10
+
11
+
- exmaple.com - english version
12
+
- example.es - versión en español
13
+
- example.ru - русская версия
14
+
15
+
or
16
+
17
+
- en.exmaple.com - english version
18
+
- es.example.com - versión en español
19
+
- ru.example.com - русская версия
20
+
21
+
Read a more information about new feature [Localization Switch By Domain Names](#localization-switch-by-domain-names)
22
+
23
+
## Introduction
8
24
9
25
Easy i18n localization for Laravel, an useful tool to combine with Laravel localization classes.
10
26
@@ -17,11 +33,14 @@ The package offers the following:
17
33
- Supports caching & testing
18
34
- Option to hide default locale in url
19
35
- Many snippets and helpers (like language selector)
36
+
-**Smart redirects between domain names**
20
37
21
38
## Table of Contents
22
39
23
40
- <ahref="#installation">Installation</a>
24
-
- <ahref="#usage">Usage</a>
41
+
- <ahref="#one-domain-usage">One Domain Usage</a>
42
+
- <ahref="#localization-switch-by-domain-names">Localization Switch By Domain Names</a>
Once this route group is added to the routes file, a user can access all locales added into `supportedLocales` (`en`and `es` by default).
148
+
Once this route group is added to the routes file, a user can access all locales added into `supportedLocales` (`en`, `es`and `ru` by default).
128
149
For example, the above route file creates the following addresses:
129
150
130
151
```
@@ -154,6 +175,72 @@ Route::group(
154
175
});
155
176
```
156
177
178
+
### Localization Switch By Domain Names
179
+
A first step, you should set up domains. For example, your project suppored tree locales:
180
+
181
+
-`en` is [example.com](https://example.com/)
182
+
-`es` is [example.es](https://example.es/)
183
+
-`ru` is [example.ru](https://example.ru/)
184
+
185
+
In your `.env` configuration files you should call about domains as:
186
+
187
+
```php
188
+
LOCALIZATION_DOMAIN_NAME_EN=example.com
189
+
LOCALIZATION_DOMAIN_NAME_ES=example.es
190
+
LOCALIZATION_DOMAIN_NAME_RU=example.ru
191
+
```
192
+
193
+
Don't forget uncommented your locales in the `config/laravellocalization.php` config file in `supportedLocales`.
194
+
195
+
Add the following to your routes file:
196
+
197
+
```php
198
+
// routes/web.php
199
+
200
+
Route::group([
201
+
'middleware' => [ 'localizationDomainRedirect' ]
202
+
], function()
203
+
{
204
+
/** ADD ALL LOCALIZED ROUTES INSIDE THIS GROUP **/
205
+
Route::get('/', function()
206
+
{
207
+
return View::make('hello');
208
+
});
209
+
210
+
Route::get('test',function(){
211
+
return View::make('test');
212
+
});
213
+
});
214
+
215
+
/** OTHER PAGES THAT SHOULD NOT BE LOCALIZED **/
216
+
217
+
```
218
+
219
+
For example, the above route file creates the following addresses:
220
+
221
+
```
222
+
// Set application language to English
223
+
https://example.com/
224
+
https://example.com/test
225
+
226
+
// Set application language to Spanish
227
+
https://example.es/
228
+
https://example.es/test
229
+
230
+
// Set application language to Russian
231
+
https://example.ru/
232
+
https://example.ru/test
233
+
234
+
```
235
+
236
+
#### Domains .env properties
237
+
To declare a domain name for a special location, you must declare the variable as `LOCALIZATION_DOMAIN_NAME_` and the location in uppercase. If the location uses a dash, it must be replaced with an underscore.
238
+
239
+
- Locale `en` is declared as `LOCALIZATION_DOMAIN_NAME_EN`
240
+
- Locale `uz-Arab` is declared as `LOCALIZATION_DOMAIN_NAME_UZ_ARAB`
241
+
- Locale `ca-valencia` is declared as `LOCALIZATION_DOMAIN_NAME_CA_VALENCIA`
242
+
- etc...
243
+
157
244
### Recommendations
158
245
159
246
***1.***: It is **strongly** recommended to use a [redirecting middleware](#redirect-middleware).
0 commit comments