{"id":26085261,"url":"https://github.com/codezero-be/browser-locale","last_synced_at":"2025-06-16T01:38:39.019Z","repository":{"id":56530441,"uuid":"47924496","full_name":"codezero-be/browser-locale","owner":"codezero-be","description":"⭐️ Get the most preferred locales from your visitor's browser.","archived":false,"fork":false,"pushed_at":"2024-03-02T12:52:24.000Z","size":82,"stargazers_count":13,"open_issues_count":1,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-16T15:18:45.626Z","etag":null,"topics":["browser","detection","language","laravel","locale","localization","php","preferred-locales"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codezero-be.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"ko_fi":"ivanvermeyen","custom":"https://paypal.me/ivanvermeyen"}},"created_at":"2015-12-13T15:23:35.000Z","updated_at":"2024-09-28T14:21:33.000Z","dependencies_parsed_at":"2024-06-18T21:16:54.117Z","dependency_job_id":"a5e74586-3579-4953-8fa3-74674c03dd14","html_url":"https://github.com/codezero-be/browser-locale","commit_stats":{"total_commits":58,"total_committers":3,"mean_commits":"19.333333333333332","dds":0.03448275862068961,"last_synced_commit":"dd6c50e5557b06b57960df6db7f52e85ef683e5e"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/codezero-be/browser-locale","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codezero-be%2Fbrowser-locale","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codezero-be%2Fbrowser-locale/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codezero-be%2Fbrowser-locale/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codezero-be%2Fbrowser-locale/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codezero-be","download_url":"https://codeload.github.com/codezero-be/browser-locale/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codezero-be%2Fbrowser-locale/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260082482,"owners_count":22956291,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["browser","detection","language","laravel","locale","localization","php","preferred-locales"],"created_at":"2025-03-09T05:58:01.539Z","updated_at":"2025-06-16T01:38:38.972Z","avatar_url":"https://github.com/codezero-be.png","language":"PHP","funding_links":["https://ko-fi.com/ivanvermeyen","https://paypal.me/ivanvermeyen","https://ko-fi.com/R6R3UQ8V"],"categories":[],"sub_categories":[],"readme":"# BrowserLocale\n\n[![GitHub release](https://img.shields.io/github/release/codezero-be/browser-locale.svg?style=flat-square)](https://github.com/codezero-be/browser-locale/releases)\n[![License](https://img.shields.io/packagist/l/codezero/browser-locale.svg?style=flat-square)](LICENSE.md)\n[![Build Status](https://img.shields.io/github/actions/workflow/status/codezero-be/browser-locale/run-tests.yml?style=flat-square\u0026logo=github\u0026logoColor=white\u0026label=tests)](https://github.com/codezero-be/browser-locale/actions)\n[![Code Coverage](https://img.shields.io/codacy/coverage/7948f1eaee514e47b4a07f268afc630f/master?style=flat-square)](https://app.codacy.com/gh/codezero-be/browser-locale)\n[![Code Quality](https://img.shields.io/codacy/grade/7948f1eaee514e47b4a07f268afc630f/master?style=flat-square)](https://app.codacy.com/gh/codezero-be/browser-locale)\n[![Total Downloads](https://img.shields.io/packagist/dt/codezero/browser-locale.svg?style=flat-square)](https://packagist.org/packages/codezero/browser-locale)\n\n[![ko-fi](https://www.ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/R6R3UQ8V)\n\nGet the most preferred locales from your visitor's browser.\n\nEvery browser has a setting for preferred website locales.\n\nThis can be read by PHP, usually with the `$_SERVER[\"HTTP_ACCEPT_LANGUAGE\"]` variable.\n\n\u003e `$_SERVER[\"HTTP_ACCEPT_LANGUAGE\"]` will return a comma separated list of language codes. Each language code MAY have a \"relative quality factor\" attached (\"nl;q=0.8\") which determines the order of preference. For example: `nl-NL,nl;q=0.8,en-US;q=0.6,en;q=0.4`. If no relative quality factor is present, the value is by default `1.0`.\n\n**BrowserLocale** parses this string and lets you access the preferred locales quickly and easily.\n\n##  Requirements\n\n- PHP \u003e= 7.0\n\n## Install\n\n```bash\ncomposer require codezero/browser-locale\n```\n\n## Instantiate\n\nFor vanilla PHP:\n\n```php\n$browser = new \\CodeZero\\BrowserLocale\\BrowserLocale($_SERVER[\"HTTP_ACCEPT_LANGUAGE\"]);\n```\n\nFor Laravel:\n\nLaravel \u003e= 5.5 will automatically register the ServiceProvider so you can get `BrowserLocale` from the IOC container.\n\n```php\n$browser = \\App::make(\\CodeZero\\BrowserLocale\\BrowserLocale::class);\n```\n\n## Get Primary Locale\n\n```php\n$locale = $browser-\u003egetLocale();\n```\n\nThis will return an instance of `\\CodeZero\\BrowserLocale\\Locale` or `null` if no locale exists.\n\n```php\nif ($locale !== null) {\n    $full     = $locale-\u003elocale;   // Example: \"en-US\"\n    $language = $locale-\u003elanguage; // Example: \"en\"\n    $country  = $locale-\u003ecountry;  // Example: \"US\"\n    $weight   = $locale-\u003eweight;   // Example: 1.0\n}\n```\n\n## Get All Locales\n\n```php\n$locales = $browser-\u003egetLocales();\n```\n\nThis will return an array of `\\CodeZero\\BrowserLocale\\Locale` instances, sorted by weight in descending order.\nSo the first array item is the most preferred locale.\n\nIf no locales exist, an empty array will be returned.\n\n```php\nforeach ($locales as $locale) {\n    $full     = $locale-\u003elocale;   // Example: \"en-US\"\n    $language = $locale-\u003elanguage; // Example: \"en\"\n    $country  = $locale-\u003ecountry;  // Example: \"US\"\n    $weight   = $locale-\u003eweight;   // Example: 1.0  \n}\n```\n\n## Filter Locale Info\n\nYou can get a flattened array with only specific Locale information.\nThese arrays will always be sorted by weight in descending order.\nThere will be no duplicate values! (e.g. `en` and `en-US` are both the language `en`)\n\n### LocaleFilter\n\nReturns an array of every locale found in the input string.\n\n```php\n$browser = new \\CodeZero\\BrowserLocale\\BrowserLocale('en-US,en;q=0.8,nl-NL;q=0.6');\n$filter = new \\CodeZero\\BrowserLocale\\Filters\\LocaleFilter;\n$locales = $browser-\u003efilter($filter);\n//=\u003e Result: ['en-US', 'en', 'nl-BE']\n```\n\n### CombinedFilter\n\nReturns an array of every locale found in the input string, while making sure the 2-letter language version of the locale is always present.\n\n```php\n$browser = new \\CodeZero\\BrowserLocale\\BrowserLocale('en-US,nl;q=0.8');\n$filter = new \\CodeZero\\BrowserLocale\\Filters\\CombinedFilter;\n$locales = $browser-\u003efilter($filter);\n//=\u003e Result: ['en-US', 'en', 'nl']\n```\n\n### LanguageFilter\n\nReturns 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.\n\n```php\n$browser = new \\CodeZero\\BrowserLocale\\BrowserLocale('en-US,en;q=0.8,nl-NL;q=0.6');\n$filter = new \\CodeZero\\BrowserLocale\\Filters\\LanguageFilter;\n$languages = $browser-\u003efilter($filter);\n//=\u003e Result: ['en', 'nl']\n```\n\n### CountryFilter\n\nReturns 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.\n\n```php\n$browser = new \\CodeZero\\BrowserLocale\\BrowserLocale('en-US,en;q=0.8,nl-NL;q=0.6,nl;q=0.4');\n$filter = new \\CodeZero\\BrowserLocale\\Filters\\CountryFilter;\n$countries = $browser-\u003efilter($filter);\n//=\u003e Result: ['US', 'NL']\n```\n\n### WeightFilter\n\nReturns an array of all relative quality factors found in the input string. The default of `1.0` is also included.\n\n```php\n$browser = new \\CodeZero\\BrowserLocale\\BrowserLocale('en-US,en;q=0.8,nl-NL;q=0.6,nl;q=0.4');\n$filter = new \\CodeZero\\BrowserLocale\\Filters\\WeightFilter;\n$weights = $browser-\u003efilter($filter);\n//=\u003e Result: [1.0, 0.8, 0.6, 0.4]\n```\n\nYou can create your own filters by implementing the `\\CodeZero\\BrowserLocale\\Filters\\Filter` interface.\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Security\n\nIf you discover any security related issues, please [e-mail me](mailto:ivan@codezero.be) instead of using the issue tracker.\n\n## Changelog\n\nA complete list of all notable changes to this package can be found on the\n[releases page](https://github.com/codezero-be/browser-locale/releases).\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodezero-be%2Fbrowser-locale","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodezero-be%2Fbrowser-locale","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodezero-be%2Fbrowser-locale/lists"}