{"id":23050822,"url":"https://github.com/geta/epi.geolocationtools","last_synced_at":"2025-04-03T03:42:32.306Z","repository":{"id":25674215,"uuid":"99909072","full_name":"Geta/EPi.GeolocationTools","owner":"Geta","description":null,"archived":false,"fork":false,"pushed_at":"2023-07-16T03:28:36.000Z","size":1792,"stargazers_count":1,"open_issues_count":9,"forks_count":0,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-02-08T17:44:39.690Z","etag":null,"topics":["cms","commerce"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Geta.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-08-10T10:01:29.000Z","updated_at":"2022-01-21T14:10:35.000Z","dependencies_parsed_at":"2025-02-09T23:00:13.801Z","dependency_job_id":null,"html_url":"https://github.com/Geta/EPi.GeolocationTools","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Geta%2FEPi.GeolocationTools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Geta%2FEPi.GeolocationTools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Geta%2FEPi.GeolocationTools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Geta%2FEPi.GeolocationTools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Geta","download_url":"https://codeload.github.com/Geta/EPi.GeolocationTools/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246933355,"owners_count":20857052,"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":["cms","commerce"],"created_at":"2024-12-15T23:38:09.863Z","updated_at":"2025-04-03T03:42:32.280Z","avatar_url":"https://github.com/Geta.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Geta Episerver geolocation tools\n\n![](http://tc.geta.no/app/rest/builds/buildType:(id:GetaPackages_EPiGeolocationTools_00ci),branch:master/statusIcon)\n\n## Description\n\nFor ASP.NET 5+ and Episerver/Optimizely 12+ see: https://github.com/Geta/geta-optimizely-geolocationtools\n\nThis library can be used to retrieve the languagebranch which matches the given request best. It provides methods to retrieve a preferred languagebranch by a users' geolocation, [browser language preference](https://www.w3.org/International/questions/qa-lang-priorities)  or both.\nThe commerce library can be used to find the right market and corresponding language based on the same parameters.\nUseful to prompt the user that a different language might suit him/her better.\nUseful for setting the right market for a user or for suggesting a specific market and language.\nBuilds on top of Episervers' built in support for [geolocation](https://world.episerver.com/documentation/developer-guides/CMS/personalization/Configuring-personalization/)\n\n## Features\n* Get languagebranch by geolocation, preferred browser languages or both\n* [Commerce] Get market by geolocation and preferred browser languages\n* Override ip address for local development testing (by setting a cookie)\n\n## How to get started?\n* ``install-package Geta.EPi.GeolocationTools``\n* ``install-package Geta.EPi.GeolocationTools.Commerce``\n\n## Details\n\n### Local development\nFor local development add a cookie to override the ip adress to an ip you want to test.\nEither in code:\n```csharp\n// This will be gone next request\nRequest.Cookies.Add(new HttpCookie(Geta.EPi.GeolocationTools.Constants.IPAddressOverride)\n{\n\tValue = \"59.107.128.65\", // Chinese ip address\n\tExpires = DateTime.Now.AddYears(1)\n});\nvar result = _commerceGeolocationService.GetMarket(Request);\n\n// This will be there upon the next request\nHttpContext.Response.SetCookie(new HttpCookie(Geta.EPi.GeolocationTools.Constants.IPAddressOverride)\n{\n    Value = \"59.107.128.65\",\n    Expires = DateTime.Now.AddYears(1)\n});\n// Chinese market (if available)\nvar result = _commerceGeolocationService.GetMarket(Request);\n```\nOr add a cookie \"geolocation_ip_override\" in your browser dev tools.\n![Dev tools cookie](/docs/images/cookie-dev-tools.png)\n\n#### Test IPs\n\n| Country code |        IP       |\n|:------------:|:---------------:|\n|      DE      |   85.88.2.224   |\n|      CH      |  178.255.153.2  |\n|      AT      |  185.180.12.65  |\n|      SE      |   82.99.17.96   |\n|      US      |  64.17.254.216  |\n|      FI      | 146.161.232.141 |\n|      NO      |   169.51.80.85  |\n\n### Code example for Geta.EPi.GeolocationTools\n```csharp\npublic class LanguageBranchExample : Controller\n{\n    private readonly IGeolocationService _geolocationService;\n\n    public LanguageBranchExample(\n        IGeolocationService geolocationService)\n    {\n        _geolocationService = geolocationService;\n    }\n\n    public void Index()\n    {\n        // Gets the language based on the users' location and their browser preferences, depending on what is available.\n        // 1. Language branch for both the users' country and their browser preferences\n        // 2. Language branch for users' browser preferences\n        // 3. Fallback language\n        var languageBranch = _geolocationService.GetLanguage(Request);\n    }\n}\n```\n### Code example for Geta.EPi.GeolocationTools.Commerce\nRegister ICurrentMarket implementation\n```csharp\n public class StructureMapRegistry : Registry\n{\n    public StructureMapRegistry()\n    {\n        For\u003cICurrentMarket\u003e().Use\u003cCurrentMarketFromGeolocation\u003e()}\n    }\n}\n```\nGet market based on geolocation and browser preferences\n```csharp\npublic class MarketExample : Controller\n{\n    private readonly ICurrentMarket _currentMarket;\n    private readonly ICommerceGeolocationService _commerceGeolocationService;\n\n    public MarketExample(\n        ICurrentMarket currentMarket, \n        ICommerceGeolocationService commerceGeolocationService)\n    {\n        _currentMarket = currentMarket;\n        _commerceGeolocationService = commerceGeolocationService;\n    }\n\n    public void Index()\n    {\n        // Get current market based on geolocation and browser preferences, market, language, location can be null\n        var result = _commerceGeolocationService.GetMarket(Request);\n        \n        // This one will be cached by storing the result in a cookie\n        // Will fall back to first enabled market or the default market\n        var sameMarket = _currentMarket.GetCurrentMarket();\n    }\n}\n```\n\n## Package maintainer\nhttps://github.com/brianweet\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeta%2Fepi.geolocationtools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgeta%2Fepi.geolocationtools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeta%2Fepi.geolocationtools/lists"}