use different Locale in kotlin


#1

l want to add language to my app use string , lang English and Arabic . my app is flight schedule for specific airport via data json. and my app working fine with out problem . l want change the language are come from data json to Arabic language

String res in en

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="schedule">schedule</string>
    <string name="arrival">arrival</string>
    <string name="departed">departed</string>
    <string name="cancelled">cancelled</string>
</resources>

String res in arabic

<?xml version="1.0" encoding="utf-8"?>
<resources>
   <string name="schedule">مجدولة</string>
    <string name="arrival">وصلت</string>
    <string name="departed">غادرت</string>
    <string name="cancelled">الغيت</string>

</resources>

l want use those resources in my list adapte because i used list view in my app

override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {

        val view : View = LayoutInflater.from(context).inflate(R.layout.row_layout,parent,false)

        val code = view.findViewById(R.id.code_id) as AppCompatTextView
        val status = view.findViewById(R.id.status_id) as AppCompatTextView
        val TimeFlight = view.findViewById(R.id.time_id) as AppCompatTextView
        val LogoAriline = view.findViewById(R.id.logo_image) as ImageView

        CallsingID.text = list[position].Callsign
        AirlineID.text = list[position].Airline
        code.text = list[position].code
        status.text= list[position].status
        TimeFlight.text = getDateTime(list[position].TimeFlight)
        Picasso.get().load(Uri.parse("https://www.xxxxxxx.com/static/images/data/operators/"+status.text.toString()+"_logo0.png"))
            .into(LogoAriline)



        return view as View
    }

l want add language inside of status.text= list[position].status


#2

I saw your question when you put it up on StackOverflow, I linked a project (https://github.com/andre-artus/ExtendArrayAdapter) that also demonstrates some localization.


#3

Here is a link to my SO answer:.


#4

And if you combine that with my answer here, then you should be sorted.