国际化和本地化中的使用
来源:互联网 发布:ibeer啤酒软件下载 编辑:程序博客网 时间:2024/05/16 13:47
有关区域的概念:处理语言和计量单位(eg:货币、日期格式、时间格式、数字分隔)而定义的一组转换。
oc 中用NSLocale作为对象来定义,它包含了区域设置的标签、集群了一系列的转换。最常用的区域舍hi标签符是en,代表English区域,标示符的子集也可以使用,像en_US(为English语言中的美国区域设置) eg:(其实本地化就相当于一种约束配置,在这里可以实现有关的内容格式)
[numberFormatter setLocale:[[NSLocalealloc]initWithLocaleIdentifier:@"en"]];//设置本地的区域为English区域
日期:NSDate用来处理时间,一般结合NSLocale来使用,一般用到的方法为:dateFromString:和stringFromDate:来实现字符串和日期的转换。
一般是通过NSDate转化为string之后,在用NSLocale来设置区域,显示期望输出的格式。使用于NSDateFormatter时间格式化类。
日历的概念:NSCalendar
//Create a default Calendar
NSCalendar *defaultCalendar = [[NSCalendaralloc]initWithCalendarIdentifier:NSGregorianCalendar];//获取日历,这里获取的是公历
NSDate *date = [NSDatedateWithTimeIntervalSinceNow:0];//使用的时间是从现在开始获取为0距离,也就是现在的时间
//create a NSDateFormatter
NSDateFormatter *formatter = [[NSDateFormatteralloc]init];//创建一个时间的格式,当时这个格式只是一个范的概念,需要设置具体,可以设置为本地的区域格式
//set the defaultCalendar to the formatter
[formatter setCalendar:defaultCalendar]; //设置为上面设置好的公历
//set the current locale
[formatter setLocale:currentLocale];//设置本地化的格式(即为将时间的格式设置为本地区域的格式)
[formatter setDateStyle:NSDateFormatterMediumStyle];//设置date的方式 ,更加小范围的设置
[formatter setTimeStyle:NSDateFormatterMediumStyle];//设施time的方式,更加f范围的级别设置
dateLabel.text=[NSStringstringWithFormat:@"Date for locale: %@",[formatterstringFromDate:date]]; //字符串的格式显示
通用方式的存储:就是如果应用需要存储日期,用字符串来表达容易混淆,并且一旦存储,所有的情况就不再可能转换为预期的日期,这是因为用户可能改变设备的设置。而使用通用的unixDateTimeStamp。
原理:简单的调用NSDate对象调用名为timeIntervalSince1970的方法。计算与1970.1.1的时间间隔,返回一个双精度的数值。
可以抽象为一个类来调用:
DateHelper.h文件
#import <Foundation/Foundation.h>
@interface DateHelper : NSObject
+(int)getGenericDateForDate:(NSDate *)date;
+(NSDate *)getDateforGenericDate:(int)genericDate;
@end
DateHelper.m文件
#import "DateHelper.h"
@implementation DateHelper
//用UNIX的方式来存储相应的时间
+(int)getGenericDateForDate:(NSDate *)date
{
return (int)[datetimeIntervalSince1970];
}
+(NSDate *)getDateforGenericDate:(int)genericDate
{
return [NSDatedateWithTimeIntervalSinceReferenceDate:genericDate];
}
@end
数字的使用格式:区域设置对日期的表达产生影响,同时也对数字产生影响。
数字格式:使用Numeric对象并且想要为这个对象的值实现文本表达时,可以使用NSNumberFormatter类就数值转换为文本表达式。
显示的格式:
(1)
[numberFormatter setLocale:[[NSLocalealloc]initWithLocaleIdentifier:@"fr"]];//法国的本地化
[numberFormatter setNumberStyle:NSNumberFormatterPercentStyle]; //数字的一种格式
cell.textLabel.text = [NSStringstringWithFormat:@"PercentStyle: %@",[numberFormatterstringFromNumber:@1234.4444444]];//显示
(2)
[numberFormatter setLocale:[[NSLocalealloc]initWithLocaleIdentifier:@"fr"]];
[numberFormatter setPositiveFormat:@"######0.####"];//即为显示的格式,小数点的位置以及相应的数字的个数
上面是数值的两种不同的格式进行显示。NUMERIC格式
NUMERIC数据类型设置
NUMERIC 数据类型使用标准、可变长度的内部格式来存储数字。
- 国际化和本地化中的使用
- poedit使用(本地化和国际化)
- 国际化和本地化
- 国际化和本地化
- android 本地化和国际化
- shell国际化和本地化
- 国际化和本地化
- iOS 国际化和本地化
- android本地化和国际化
- Android 本地化和国际化
- 本地化和国际化
- Django 国际化和本地化
- Django国际化和本地化
- Django国际化和本地化
- 漫谈国际化和本地化测试
- 漫谈国际化和本地化测试
- 漫谈国际化和本地化测试
- android的国际化和本地化
- windows与linux系统互相拷贝文件
- 【日常学习】【棋盘DP】【多线程DP】codevs1169 传纸条题解
- iOS手势之 响应上下左右滑动手势
- try catch finally巩固
- 直接插入排序
- 国际化和本地化中的使用
- MSP430F149嵌入式系统中FLASH K9F1G08U0M的应用
- 身份证号正则校验(js校验+JAVA校验)
- 2012年5月SAT香港真题解析
- java连接mysql数据库
- Jetty提交数据时报java.lang.IllegalStateException: Form too large270468>200000问题解决
- Oracle数据泵导入导出 Oracle impdp/expdp
- virtualbox中安装ubuntu
- Unity5 如何做资源管理和增量更新