Hello, in this article we will learn how to implement Countries List inside your project (website, android app, etc).
here’s an example of android app:
first, we will use CountriesList library from Github:
github.com/kimoandroid/CountriesList
Why this library
- Easy to use anywhere.
- You can add unlimited translation for the same file without editing the main function or use Hardcoded.
- You can use country_code key to use it in your sytem for calling codes.
- you can display country name with it’s flag easily.
You can easily use the ready api directly by using this link: https://api.encept.co/countries/index.php?lang=en
- api parameters: lang=ar OR lang=en
- api response: JSON Encode.
[{
"code":"US",
"calling_code":"+1",
"flag":"🇺🇸",
"name":"United States"
}]
You can use this api directly and call this link from your project and get the JSON response.
Or you can create your api from zero at your own server & use your own link.
First, Download The Library Files That I Mentioned Before From Github: github.com/kimoandroid/CountriesList
This Library is very flexable and easy to use & edit.
Inside Localization folder you will find the translation of the countries name you can add new translation file by creating file called country_[lang symbol].php such as spanish, you will create a file named country_sp.php.
and after that copy all content that inside default_strings.php file ‘this is the translation schema’
now if anyone called the api url and put this parameter: ‘lang=sp’ the api will return the countries list with spanish.
That’s all, Follow For More 🙂
Leave a Reply