Skip to content

Commit 8126927

Browse files
committed
First commit
0 parents  commit 8126927

28 files changed

+4804
-0
lines changed

.editorconfig

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
; This file is for unifying the coding style for different editors and IDEs.
2+
; More information at http://editorconfig.org
3+
4+
root = true
5+
6+
[*]
7+
charset = utf-8
8+
indent_size = 4
9+
indent_style = space
10+
end_of_line = lf
11+
insert_final_newline = true
12+
trim_trailing_whitespace = true
13+
14+
[{package.json,*.scss,*.css}]
15+
indent_size = 2
16+
17+
[*.md]
18+
trim_trailing_whitespace = false

.gitattributes

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Path-based git attributes
2+
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html
3+
4+
# Ignore all test and documentation with "export-ignore".
5+
/.editorconfig export-ignore
6+
/.gitattributes export-ignore
7+
/.gitignore export-ignore
8+
/.travis.yml export-ignore
9+
/.scrutinizer.yml export-ignore
10+
/phpunit.xml.dist export-ignore
11+
/tests export-ignore

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/vendor
2+
/phpunit.xml

.scrutinizer.yml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
filter:
2+
excluded_paths:
3+
- "config/"
4+
- "tests/"
5+
checks:
6+
php:
7+
code_rating: true
8+
remove_extra_empty_lines: true
9+
remove_php_closing_tag: true
10+
remove_trailing_whitespace: true
11+
fix_use_statements:
12+
remove_unused: true
13+
preserve_multiple: false
14+
preserve_blanklines: true
15+
order_alphabetically: true
16+
fix_php_opening_tag: true
17+
fix_linefeed: true
18+
fix_line_ending: true
19+
fix_identation_4spaces: true
20+
fix_doc_comments: true
21+
build:
22+
tests:
23+
override:
24+
-
25+
command: 'vendor/bin/phpunit --coverage-clover=coverage.clover'
26+
coverage:
27+
file: 'coverage.clover'
28+
format: 'clover'

.travis.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
language: php
2+
3+
php:
4+
- 7.1
5+
- 7.2
6+
7+
sudo: false
8+
9+
cache:
10+
directories:
11+
- $HOME/.composer/cache
12+
13+
before_script:
14+
- travis_retry composer self-update
15+
- travis_retry composer update --no-interaction
16+
17+
script:
18+
- vendor/bin/phpunit

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Changelog
2+
3+
All Notable changes to **Laravel Localizer** will be documented in this file.
4+
5+
## 1.0.0 (2018-04-01)
6+
7+
- Define your supported locales and match your visitor's preference
8+
- Uses the most common locale detectors by default
9+
- Uses the most common locale stores by default
10+
- Easily create and add your own detectors and stores

LICENSE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# The MIT License (MIT)
2+
3+
Copyright (c) 2018 Ivan Vermeyen (<[email protected]>)
4+
5+
> Permission is hereby granted, free of charge, to any person obtaining a copy
6+
> of this software and associated documentation files (the "Software"), to deal
7+
> in the Software without restriction, including without limitation the rights
8+
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
> copies of the Software, and to permit persons to whom the Software is
10+
> furnished to do so, subject to the following conditions:
11+
>
12+
> The above copyright notice and this permission notice shall be included in
13+
> all copies or substantial portions of the Software.
14+
>
15+
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
> THE SOFTWARE.

README.md

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Laravel Localizer
2+
3+
[![GitHub release](https://img.shields.io/github/release/codezero-be/laravel-localizer.svg)]()
4+
[![License](https://img.shields.io/packagist/l/codezero/laravel-localizer.svg)]()
5+
[![Build Status](https://scrutinizer-ci.com/g/codezero-be/laravel-localizer/badges/build.png?b=master)](https://scrutinizer-ci.com/g/codezero-be/laravel-localizer/build-status/master)
6+
[![Code Coverage](https://scrutinizer-ci.com/g/codezero-be/laravel-localizer/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/codezero-be/laravel-localizer/?branch=master)
7+
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/codezero-be/laravel-localizer/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/codezero-be/laravel-localizer/?branch=master)
8+
[![Total Downloads](https://img.shields.io/packagist/dt/codezero/laravel-localizer.svg)](https://packagist.org/packages/codezero/laravel-localizer)
9+
10+
#### Automatically detect and set an app locale that matches your visitor's preference.
11+
12+
- Define your supported locales and match your visitor's preference
13+
- Uses the most common locale [detectors](#detectors) by default
14+
- Uses the most common locale [stores](#stores) by default
15+
- Easily create and add your own detectors and stores
16+
17+
## Requirements
18+
19+
- PHP >= 7.1
20+
- Laravel >= 5.6
21+
22+
## Install
23+
24+
```php
25+
composer require codezero/laravel-localizer
26+
```
27+
28+
Laravel will automatically register the ServiceProvider.
29+
30+
#### Add Middleware
31+
32+
Add the middleware to the `web` middleware group in `app/Http/Kernel.php` after `StartSession`:
33+
34+
```php
35+
protected $middlewareGroups = [
36+
'web' => [
37+
//...
38+
\Illuminate\Session\Middleware\StartSession::class,
39+
//...
40+
\CodeZero\Localizer\Middleware\SetLocale::class,
41+
],
42+
];
43+
```
44+
45+
#### Publish Configuration File
46+
47+
```php
48+
php artisan vendor:publish --provider="CodeZero\Localizer\LocalizerServiceProvider" --tag="config"
49+
```
50+
51+
You will now find a `localizer.php` file in the `config` folder.
52+
53+
#### Configure Supported Locales
54+
55+
Add any locales you wish to support to your published `config/localizer.php` file:
56+
57+
```php
58+
'supported-locales' => ['en', 'nl', 'fr'];
59+
```
60+
61+
## Drivers
62+
63+
#### Detectors
64+
65+
By default the middleware will use the following detectors for a supported locale:
66+
67+
1. The URL
68+
2. The session
69+
3. A cookie
70+
4. The browser
71+
5. The app's default locale
72+
73+
If you publish the configuration file, you can choose which detectors to run and in what order.
74+
75+
You can also create your own detector by implementing the `\CodeZero\Localizer\Detectors\Detector` interface and add a reference to it in the config file. The detectors are resolved from Laravel's IOC container, so you can add any dependencies to your constructor.
76+
77+
#### Stores
78+
79+
The first supported locale that is returned by a detector will then be stored in:
80+
81+
- The session
82+
- A cookie
83+
- The app locale
84+
85+
If you publish the configuration file, you can choose which stores to use.
86+
87+
You can also create your own store by implementing the `\CodeZero\Localizer\Stores\Store` interface and add a reference to it in the config file. The stores are resolved from Laravel's IOC container, so you can add any dependencies to your constructor.
88+
89+
## Testing
90+
91+
```
92+
composer test
93+
```
94+
95+
## Security
96+
97+
If you discover any security related issues, please [e-mail me](mailto:[email protected]) instead of using the issue tracker.
98+
99+
## Changelog
100+
101+
See a list of important changes in the [changelog](CHANGELOG.md).
102+
103+
## License
104+
105+
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

composer.json

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"name": "codezero/laravel-localizer",
3+
"description": "Automatically detect and set an app locale that matches your visitor's preference.",
4+
"keywords": [
5+
"php",
6+
"laravel",
7+
"browser",
8+
"cookie",
9+
"session",
10+
"locale",
11+
"language",
12+
"country",
13+
"localization",
14+
"detect"
15+
],
16+
"license": "MIT",
17+
"authors": [
18+
{
19+
"name": "Ivan Vermeyen",
20+
"email": "[email protected]"
21+
}
22+
],
23+
"require": {
24+
"php": "^7.1",
25+
"codezero/browser-locale": "^3.0",
26+
"illuminate/support": "^5.6"
27+
},
28+
"require-dev": {
29+
"mockery/mockery": "^1.0",
30+
"orchestra/testbench": "3.6.*",
31+
"phpunit/phpunit": "^7.0"
32+
},
33+
"scripts": {
34+
"test": "phpunit"
35+
},
36+
"autoload": {
37+
"psr-4": {
38+
"CodeZero\\Localizer\\": "src"
39+
}
40+
},
41+
"autoload-dev": {
42+
"psr-4": {
43+
"CodeZero\\Localizer\\Tests\\": "tests"
44+
}
45+
},
46+
"extra": {
47+
"laravel": {
48+
"providers": [
49+
"CodeZero\\Localizer\\LocalizerServiceProvider"
50+
]
51+
}
52+
},
53+
"config": {
54+
"preferred-install": "dist",
55+
"sort-packages": true,
56+
"optimize-autoloader": true
57+
},
58+
"minimum-stability": "stable",
59+
"prefer-stable": true
60+
}

0 commit comments

Comments
 (0)