俄语通话记录时间显示问题

在俄语下,查看通话记录,显示的时间会有问题,比如,正常情况下应该显示21分钟之前,或21小时之前,而在俄语下查看,就会发现显示不正常,会显示为1分钟之前,或是1小时之前,在其他语言下就会正常显示。通过查看源码发现 应该就是下面这句话导致此问题的发生。

resId = com.android.internal.R.plurals.abbrev_in_num_hours;
format = r.getQuantityString(resId, (int) count);

只要之歌count值为21,就会返回1。

以下为官网解释:

When the language requires special treatment of numbers like one (as with the number 1 in English and most other languages; in Russian, any number ending in 1 but not ending in 11 is in this class).

按照android官网上的解释,会看数字的最后2位,如果是11的话就是好多就显示好多,如果是X1的话,就显示为1.

 比如:11就会显示为11111就会显示会111

                     21则会显示为1121也会显示为1,31也会显示1


修改思路可以使用xliff来客制化one字符串


定位文件:\frameworks\base\core\java\android\text\format\DateUtils.java

public static CharSequence getRelativeTimeSpanString(long time, long now, long minResolution,
            int flags) {
        Resources r = Resources.getSystem();
        boolean abbrevRelative = (flags & (FORMAT_ABBREV_RELATIVE | FORMAT_ABBREV_ALL)) != 0;

        boolean past = (now >= time);
        long duration = Math.abs(now - time);

        int resId;
        long count;
        if (duration < MINUTE_IN_MILLIS && minResolution < MINUTE_IN_MILLIS) {
            count = duration / SECOND_IN_MILLIS;
            if (past) {
                if (abbrevRelative) {
                    resId = com.android.internal.R.plurals.abbrev_num_seconds_ago;
                } else {
                    resId = com.android.internal.R.plurals.num_seconds_ago;
                }
            } else {
                if (abbrevRelative) {
                    resId = com.android.internal.R.plurals.abbrev_in_num_seconds;
                } else {
                    resId = com.android.internal.R.plurals.in_num_seconds;
                }
            }
        } else if (duration < HOUR_IN_MILLIS && minResolution < HOUR_IN_MILLIS) {
            count = duration / MINUTE_IN_MILLIS;
            if (past) {
                if (abbrevRelative) {
                    resId = com.android.internal.R.plurals.abbrev_num_minutes_ago;
                } else {
                    resId = com.android.internal.R.plurals.num_minutes_ago;
                }
            } else {
                if (abbrevRelative) {
                    resId = com.android.internal.R.plurals.abbrev_in_num_minutes;
                } else {
                    resId = com.android.internal.R.plurals.in_num_minutes;
                }
            }
        } else if (duration < DAY_IN_MILLIS && minResolution < DAY_IN_MILLIS) {
            count = duration / HOUR_IN_MILLIS;
            if (past) {
                if (abbrevRelative) {
                    resId = com.android.internal.R.plurals.abbrev_num_hours_ago;
                } else {
                    resId = com.android.internal.R.plurals.num_hours_ago;
                }
            } else {
                if (abbrevRelative) {
                    resId = com.android.internal.R.plurals.abbrev_in_num_hours;
                } else {
                    resId = com.android.internal.R.plurals.in_num_hours;
                }
            }
        } else if (duration < WEEK_IN_MILLIS && minResolution < WEEK_IN_MILLIS) {
            return getRelativeDayString(r, time, now);
        } else {
            // We know that we won't be showing the time, so it is safe to pass
            // in a null context.
            return formatDateRange(null, time, time, flags);
        }

	/*  modify for  begin*/
	String format = "";
	if((int)count == 21 && isRuLanguage()){ //判断为21并且 俄语下,使用xliff来客制化one字符串 ,其他后缀为1的类似,看需求
		if(duration < HOUR_IN_MILLIS){
			format = r.getString(com.android.internal.R.string.num_minutes_ago,(int)count);//在xml中增加定义
		}else if(duration < DAY_IN_MILLIS){
			format = r.getString(com.android.internal.R.string.num_hours_ago,(int)count);
		}else{
			format = r.getQuantityString(resId, (int) count);
		}
	}else{
 		format = r.getQuantityString(resId, (int) count);
	}
        return String.format(format, count);
    }
	/*判断语言 */
private static boolean isRuLanguage(){
	    Locale locale = Resources.getSystem().getConfiguration().locale;
            String language = locale.getLanguage();
            if (language.endsWith("ru"))
                return true;
            else
                return false;
	}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值