zoukankan      html  css  js  c++  java
  • IOS多国语言Localize方法

    使用一系列的NSLocalizedString函数就是localize的本质。

    NSLocalizedString(NSString *key, NSString *comment)

    这里的table取值为nil,所以就把默认的Localizable.strings文件当作table

    对于这里的comment是指当你使用genstrings tool来生成文件的时候,这一对key-value pair 前面的comment

    文件Localizable.strings

    用来存储需要local的string,如果没有,你可以建立一个叫这个名字的stringFile,默认就是使用这个文件的,以下就是这个文件中的内容格式,

    /*this is comment format, there is content below*/
    "meterFormat" = "%@ meters";

    NSLocalizedStringFromTable(NSString* key, NSString* tableName, NSString* comment)

    的本质就是Bundle中的一个函数

    localizedStringForKey:(NSString*)key value:(NSString*)value table:(NSString*)tablename

    其中的value是指,如果没有找到翻译的内容,或者key为空时,显示什么内容,tablename是指.strings文件的名字

    比如一个文件名字为Buttons.strings

    那么使用时,采用

    [myBundle localizedStringForKey:@"key" value:@"no translate" table:@"Buttons"]

    NSLocalizedStringFromTableInBundle

    这个函数可以选择不同的bundle

    软件的名字可以通过以下的方法国际化:

    对于InfoPlist.strings

    里面可以存储软件的名字

    CFBundleDisplayName = "";

    其他特殊用法:

    对于要使用的string中间包含有变量的情况,可以使用

    "windows at %d columns and %d rows."

    "File %@ not found"

    这样的格式来存储内容

    使用的时候,用stringWithFormat:来创建包含变量的NSString,使用即可,比如

     NSString* str=[NSString stringWithFormat:@"%d hullo %@", 23, @"local"];

    另外有时候不同语言翻译的时候,变量的顺序可能会发生改变,这个时候就需要在其中加上tag形如n$来指明位置关系,比如

    "%2$@ blah, %1$@ blah"就表明两个参数的顺序变化了。

    特殊字符

    比如回车\r   换行\n

    引号 \" 

  • 相关阅读:
    网页工具KOBAS进行KEGG富集分析
    Novel LncRNA的实时定量PCR引物设计教程
    Annotated LncRNA的实时定量PCR引物设计教程
    GO分析-GOseq的使用教程
    转录因子预测-oPOSSUM 3.0的使用教程
    miRNA结合位点预测软件RNAhybrid的使用教程
    关于win10用户名设置为中文导致Rstudio画图报错的解决方法
    edgeR之配对检验分析差异基因的使用教程
    51nod 1051最大子矩阵和
    51nod最大字段和(1049 1254)
  • 原文地址:https://www.cnblogs.com/cnyin/p/2615085.html
Copyright © 2011-2022 走看看