Skip to content

Commit 9b0764f

Browse files
authored
Review and update README and LICENSE (#7)
1 parent 8388081 commit 9b0764f

File tree

2 files changed

+30
-43
lines changed

2 files changed

+30
-43
lines changed

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# The MIT License (MIT)
22

3-
Copyright (c) 2018 Ivan Vermeyen (<ivan@codezero.be>)
3+
Copyright (c) Ivan Vermeyen (ivan@codezero.be)
44

55
> Permission is hereby granted, free of charge, to any person obtaining a copy
66
> of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 29 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
11
# BrowserLocale
22

3-
## IMPORTANT: March 2022
4-
5-
[![Support Ukraine](https://raw.githubusercontent.com/hampusborgos/country-flags/main/png100px/ua.png)](https://github.com/hampusborgos/country-flags/blob/main/png100px/ua.png)
6-
7-
It's horrible to see what is happening now in Ukraine, as Russian army is
8-
[bombarding houses, hospitals and kindergartens](https://twitter.com/DavidCornDC/status/1501620037785997316).
9-
10-
Please [check out supportukrainenow.org](https://supportukrainenow.org/) for the ways how you can help people there.
11-
Spread the word.
12-
13-
And if you are from Russia and you are against this war, please express your protest in some way.
14-
I know you can get punished for this, but you are one of the hopes of those innocent people.
15-
16-
---
17-
183
[![GitHub release](https://img.shields.io/github/release/codezero-be/browser-locale.svg?style=flat-square)](https://github.com/codezero-be/browser-locale/releases)
194
[![License](https://img.shields.io/packagist/l/codezero/browser-locale.svg?style=flat-square)](LICENSE.md)
205
[![Build Status](https://img.shields.io/github/actions/workflow/status/codezero-be/browser-locale/run-tests.yml?style=flat-square&logo=github&logoColor=white&label=tests)](https://github.com/codezero-be/browser-locale/actions)
@@ -24,7 +9,7 @@ I know you can get punished for this, but you are one of the hopes of those inno
249

2510
[![ko-fi](https://www.ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/R6R3UQ8V)
2611

27-
#### Get the most preferred locales from your visitor's browser.
12+
Get the most preferred locales from your visitor's browser.
2813

2914
Every browser has a setting for preferred website locales.
3015

@@ -34,26 +19,25 @@ This can be read by PHP, usually with the `$_SERVER["HTTP_ACCEPT_LANGUAGE"]` var
3419
3520
**BrowserLocale** parses this string and lets you access the preferred locales quickly and easily.
3621

37-
3822
## Requirements
3923

4024
- PHP >= 7.0
4125

4226
## Install
4327

44-
```php
28+
```bash
4529
composer require codezero/browser-locale
4630
```
4731

4832
## Instantiate
4933

50-
#### For vanilla PHP:
34+
For vanilla PHP:
5135

52-
``` php
36+
```php
5337
$browser = new \CodeZero\BrowserLocale\BrowserLocale($_SERVER["HTTP_ACCEPT_LANGUAGE"]);
5438
```
5539

56-
#### For Laravel:
40+
For Laravel:
5741

5842
Laravel >= 5.5 will automatically register the ServiceProvider so you can get `BrowserLocale` from the IOC container.
5943

@@ -63,13 +47,13 @@ $browser = \App::make(\CodeZero\BrowserLocale\BrowserLocale::class);
6347

6448
## Get Primary Locale
6549

66-
``` php
50+
```php
6751
$locale = $browser->getLocale();
6852
```
6953

7054
This will return an instance of `\CodeZero\BrowserLocale\Locale` or `null` if no locale exists.
7155

72-
``` php
56+
```php
7357
if ($locale !== null) {
7458
$full = $locale->locale; // Example: "en-US"
7559
$language = $locale->language; // Example: "en"
@@ -84,11 +68,12 @@ if ($locale !== null) {
8468
$locales = $browser->getLocales();
8569
```
8670

87-
This will return an array of `\CodeZero\BrowserLocale\Locale` instances, sorted by weight in descending order. So the first array item is the most preferred locale.
71+
This will return an array of `\CodeZero\BrowserLocale\Locale` instances, sorted by weight in descending order.
72+
So the first array item is the most preferred locale.
8873

8974
If no locales exist, an empty array will be returned.
9075

91-
``` php
76+
```php
9277
foreach ($locales as $locale) {
9378
$full = $locale->locale; // Example: "en-US"
9479
$language = $locale->language; // Example: "en"
@@ -99,59 +84,61 @@ foreach ($locales as $locale) {
9984

10085
## Filter Locale Info
10186

102-
You can get a flattened array with only specific Locale information. These arrays will always be sorted by weight in descending order. There will be no duplicate values! (e.g. `en` and `en-US` are both the language `en`)
87+
You can get a flattened array with only specific Locale information.
88+
These arrays will always be sorted by weight in descending order.
89+
There will be no duplicate values! (e.g. `en` and `en-US` are both the language `en`)
10390

104-
#### LocaleFilter
91+
### LocaleFilter
10592

10693
Returns an array of every locale found in the input string.
10794

108-
``` php
95+
```php
10996
$browser = new \CodeZero\BrowserLocale\BrowserLocale('en-US,en;q=0.8,nl-NL;q=0.6');
110-
$filter = \CodeZero\BrowserLocale\Filters\LocaleFilter;
97+
$filter = new \CodeZero\BrowserLocale\Filters\LocaleFilter;
11198
$locales = $browser->filter($filter);
11299
//=> Result: ['en-US', 'en', 'nl-BE']
113100
```
114101

115-
#### CombinedFilter
102+
### CombinedFilter
116103

117104
Returns an array of every locale found in the input string, while making sure the 2-letter language version of the locale is always present.
118105

119-
``` php
106+
```php
120107
$browser = new \CodeZero\BrowserLocale\BrowserLocale('en-US,nl;q=0.8');
121-
$filter = \CodeZero\BrowserLocale\Filters\CombinedFilter;
108+
$filter = new \CodeZero\BrowserLocale\Filters\CombinedFilter;
122109
$locales = $browser->filter($filter);
123110
//=> Result: ['en-US', 'en', 'nl']
124111
```
125112

126-
#### LanguageFilter
113+
### LanguageFilter
127114

128115
Returns an array of only the 2-letter language codes found in the input string. Language codes are also extracted from full locales and added to the results array.
129116

130-
``` php
117+
```php
131118
$browser = new \CodeZero\BrowserLocale\BrowserLocale('en-US,en;q=0.8,nl-NL;q=0.6');
132-
$filter = \CodeZero\BrowserLocale\Filters\LanguageFilter;
119+
$filter = new \CodeZero\BrowserLocale\Filters\LanguageFilter;
133120
$languages = $browser->filter($filter);
134121
//=> Result: ['en', 'nl']
135122
```
136123

137-
#### CountryFilter
124+
### CountryFilter
138125

139126
Returns an array of only the 2-letter country codes found in the input string. Locales that only contain a 2-letter language code will be skipped.
140127

141-
``` php
128+
```php
142129
$browser = new \CodeZero\BrowserLocale\BrowserLocale('en-US,en;q=0.8,nl-NL;q=0.6,nl;q=0.4');
143-
$filter = \CodeZero\BrowserLocale\Filters\CountryFilter;
130+
$filter = new \CodeZero\BrowserLocale\Filters\CountryFilter;
144131
$countries = $browser->filter($filter);
145132
//=> Result: ['US', 'NL']
146133
```
147134

148-
#### WeightFilter
135+
### WeightFilter
149136

150137
Returns an array of all relative quality factors found in the input string. The default of `1.0` is also included.
151138

152-
``` php
139+
```php
153140
$browser = new \CodeZero\BrowserLocale\BrowserLocale('en-US,en;q=0.8,nl-NL;q=0.6,nl;q=0.4');
154-
$filter = \CodeZero\BrowserLocale\Filters\WeightFilter;
141+
$filter = new \CodeZero\BrowserLocale\Filters\WeightFilter;
155142
$weights = $browser->filter($filter);
156143
//=> Result: [1.0, 0.8, 0.6, 0.4]
157144
```
@@ -160,7 +147,7 @@ You can create your own filters by implementing the `\CodeZero\BrowserLocale\Fil
160147

161148
## Testing
162149

163-
```
150+
```bash
164151
composer test
165152
```
166153

0 commit comments

Comments
 (0)