How to change DateUtils.getRelativeTimeSpanString strings?

233 Views Asked by At

I'm trying to convert a date to relative date.

For example

12-03-2017 --> 2 years ago.

I'm using an android class which is "DateUtils.getRelativeTimeSpanString"

This class works just fine. But I have a little problem.

My app will serve in Turkish language. But method returns some very old sentence.

When relative time is equal to "2 days ago" class must return "2 gün önce" which is literal translation of "2 days ago". But instead it returns "Evvelsi gün" Which has same meaning but old sentence and I don't want to use that

How to change this string for Turkish language.

I did this:

if(DateUtils.getRelativeTimeSpanString(list.get(position).getCreatedAt().getTime(), System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS).toString().toLowerCase().equals("evvelsi gün")){
    //if class retuned unwanted word then dont use it but use preferred word.
    holder.postdate.setText("2 gün önce"); 
}
else{
    //if class returned preferred word use it
    holder.postdate.setText(DateUtils.getRelativeTimeSpanString(list.get(position).getCreatedAt().getTime(), System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS));
}

But as you can see I'm setting textView's text with hardcoded strings. Is this a good solution? Is there any more professional ways?

0

There are 0 best solutions below