结合两种语言文本RTL& LTR [英] Combine Two Language Text RTL & LTR

查看:209
本文介绍了结合两种语言文本RTL& LTR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个文本,一个用希伯来语,一个用英语。

I have two text, one in Hebrew language and one in English.

在第一篇文章中,我的日期是希伯来语。

In first text I have date that is in Hebrew.

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    NSLocale *hebrew = [[NSLocale alloc] initWithLocaleIdentifier:@"he_IL"]; // Hebrew

    [dateFormatter setDateFormat:@"yyyy-MM-dd'T'hh:mm:ss.SSSZ"];

    NSDate *date = [dateFormatter dateFromString:model.startDate];

    NSLog(@"%@", date);

    [dateFormatter setDateFormat:@"EEEE,dd.MM.yyyy"];
    dateFormatter.locale = hebrew;
    NSString *strDate = [dateFormatter stringFromDate:date];

并且开始日期是:יוםשישי,19.08.2016 in NString object strDate

and start Date is : יום שישי,19.08.2016 in NString object strDate

另一方面,我在NSString对象中有文字 07:00-16:00 timeForRequest

On other hand I have text 07: 00-16: 00 in NSString object timeForRequest

我需要的格式是יוםשני,15.01.2016 | 16:00 - 07:00

当我尝试使用以下代码时

and when I try to do same with following code

[NSString stringWithFormat:@"%@ | %@",strDate,timeForRequest]

它告诉我这样:יוםשישי,19.08.2016 | 07:00-16:00

观察时间不正确,请帮我从这种有线情况出来。

Observe the time is not correct, please help me to come out from this wired situation.

提前致谢。

推荐答案

我很确定这里的问题是strDate中的希伯来日期带有unicode字符,使其显示正确-向左。当与timeForResponse中的'普通'从左到右的字符串组合时,这会引起混乱。日期格式化程序从希伯来语语言环境中选择它。

I'm pretty sure that the problem here is that the hebrew date in strDate is carrying unicode characters that make it display right-to-left. That's causing chaos when combined with the 'ordinary' left-to-right string in timeForResponse. The date formatter is picking that up from the hebrew locale.

试试这个:


  1. 将日期格式字符串更改为

[dateFormatter setDateFormat:@dd.MM.yyyy,EEEE ];


  1. 将格式更改为

NSString * result = [NSString stringWithFormat:@\ u200E%@ |%@,timeForRequest,strDate];

0x200E unicode字符是不可见的,但会将渲染恢复为从左到右的模式。

The 0x200E unicode character is invisible but puts the rendering back into left-to-right mode.

在上面之后,这是我得到的输出:

After the above, this is the output that I'm getting:

07:00-16:00 | 17.08.2016,יוםרביעי

这篇关于结合两种语言文本RTL& LTR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆