Search code examples
iosswiftxcodelocationdefault

How to set language based on user's location?


For any mobile app, Users set their preferred language.But What I wanna do is App should be set with the language based on user's location.For Example,If user is in tamilnadu language should be automatically set with "Tamil".But User should be able to change the language what they want.Is there any library for this.


Solution

  • Use this tutorial to track the user visited locations using CoreLocation :- https://www.raywenderlich.com/5247-core-location-tutorial-for-ios-tracking-visited-locations

    Under Location Description section, in geoCoder.reverseGeocodeLocation method, you can take the placemarks?.administrativeArea variable to get the state code.

    You need to compare each state and set the corresponding languages by code. There is no default iOS library which undertakes the functionality you are asking for. If you are intended to take this app globally, its better your backend team implements this. You will pass the state/stateCode in the api request and the backend will return the corresponding language.