-
-
Notifications
You must be signed in to change notification settings - Fork 510
Add New Language Support
To add new language support is really easy.
Let’s see. For example, here we want to add support for the Turkish language.
- Open cloned project in Android Studio
- Find “src/main/res/raw/a_new_lang_tamplate.xml”. It is a template with list of countries where correct translated names must be placed.
- Make a copy of that file in the same folder and name it as “turkish.xml”. This must be the name of language.
- Now in this turkish.xml, add correct translations where “todo”s are specified.
-
ccp_dialog_title
is the title shown on selection list which should be a translation of “Select a country”. -
ccp_dialog_search_hint_message
is the search editText hint and should be a translation of “Search…”. -
ccp_dialog_no_result_ack_message
is the message shown when no country found for the query. It should be the translation of “Results not found”. - For all countries, replace “todo” with a translated country name.
-
Go to src/main/java/com/hbb20/CountryCodePicker.java
-
Find for “public enum Language “. This is the list of supported language in alphabetical order. Based on order, figure out the position for new language. For Turkish, it will go between Spanish and Ukrainian. So
ARABIC("ar"), BENGALI("bn"), CHINESE_SIMPLIFIED("zh"), CHINESE_TRADITIONAL("zh"), ENGLISH("en"), FRENCH("fr"), GERMAN("de"), GUJARATI("gu"), HEBREW("iw"), HINDI("hi"), INDONESIA("in"), JAPANESE("ja"), KOREAN("ko"), PORTUGUESE("pt"), RUSSIAN("ru"), SPANISH("es"), UKRAINIAN("uk");
will be
ARABIC("ar"), BENGALI("bn"), CHINESE_SIMPLIFIED("zh"), CHINESE_TRADITIONAL("zh"), ENGLISH("en"), FRENCH("fr"), GERMAN("de"), GUJARATI("gu"), HEBREW("iw"), HINDI("hi"), INDONESIA("in"), JAPANESE("ja"), KOREAN("ko"), PORTUGUESE("pt"), RUSSIAN("ru"), SPANISH("es"), TURKISH("tr"), UKRAINIAN("uk");
-
Here the name must be UpperCase version of the file name (apart from .xml) given in step 2.B. In this case its “TURKISH” for turkish.xml.
-
2 letter language code can be found at https://www.w3schools.com/tags/ref_language_codes.asp. For turkish language it is “tr”.
-
Go to src/main/res/values/attrs.xml
-
Find <attr name="ccp_defaultLanguage" format=“enum">
-
Make language entry in alphabetical order.
-
Update enum values for all the language below the new language. So that entire list has correct value order as well. This is very important, as it is used as mapping with the list we updated earlier in CountryCodePIcker.java.
-
For example, earlier it was
... ... <enum name=“SPANISH” value=“15”> <enum name=“UKRAINIAN” value=“16”> ```
-
After inserting Turkish between them it, it should look like
... ... <enum name=“SPANISH” value=“15”> <enum name=“TURKISH” value=“16”> <enum name=“UKRAINIAN” value=“17”>
- Finally we want to make sure that everything we have done so far is all good.
- Now do “Menu > Build > Make project”
- Open CountryCodePickerProject/app/src/main/res/layout/fragment_introduction.xml
- There is one CountryCodePicker view. Set our default language as new language.
- For this case, add app:ccp_defaultLanguage=“TURKISH" to the view.
- Run the app on device
- Open introduction page and tap on ccp view.
- If it is tested OK, please create a pull request. We will be happy to merge it.
- How to Integrate into your project
- Full Number Support
- Use as a Country Selector
- Auto detect country
- Auto detect language
- Remember last selection
- Country Preference
- Custom Mater List
- Exclude Countries
- Example phonenumber as hint
- Multi Language Support
- Default Country
- Country Selection Listener
- Dialog events listener
- CCP Theme Customization
- CCP Dialog Theme Customization
- Custom TypeFace
- Read Selected Country
- XML Properties
- Update Guide to v2
- Guide to Add New Language Support
- Guide to add New Country
- Change contry names for local project
- Handle CCP ClickListener Manually
- Custom Dialog Title/Hint/Empty Result ACK
- Flag Emoji Support (BETA)
- Change Log