Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在iOS操场中测试本地化_Ios_Xcode_Xcode6_Swift Playground_Nslocalizedstring - Fatal编程技术网

在iOS操场中测试本地化

在iOS操场中测试本地化,ios,xcode,xcode6,swift-playground,nslocalizedstring,Ios,Xcode,Xcode6,Swift Playground,Nslocalizedstring,有没有办法让本地化字符串进入iOS操场?我有许多从右到左的语言翻译,其中包括我必须用十六进制编辑器编辑的格式代码(以确保代码的字节顺序正确),我希望手动检查格式化字符串的输出,以确保它正常工作 另外,是否有任何Mac OS文本编辑器允许您以从左到右的模式显示阿拉伯语和希伯来语?Swift 3:用于测试本地化的示例 //: Playground - noun: a place where people can play import UIKit //current locale identif

有没有办法让本地化字符串进入iOS操场?我有许多从右到左的语言翻译,其中包括我必须用十六进制编辑器编辑的格式代码(以确保代码的字节顺序正确),我希望手动检查格式化字符串的输出,以确保它正常工作


另外,是否有任何Mac OS文本编辑器允许您以从左到右的模式显示阿拉伯语和希伯来语?

Swift 3:用于测试本地化的示例

//: Playground - noun: a place where people can play

import UIKit

//current locale identifier
NSLocale.current.identifier //"en_US"

//available identifiers
NSLocale.availableLocaleIdentifiers //["eu", "hr_BA", "en_CM", "en_BI" ...]

// particular locales    
let unitedStatesLocale = NSLocale(localeIdentifier: "en_US") 
let chinaLocale = NSLocale(localeIdentifier: "zh_Hans") 
let germanyLocale = NSLocale(localeIdentifier: "de_DE") 
let indiaLocale = NSLocale(localeIdentifier: "en_IN") 
let arabicLocale = NSLocale(localeIdentifier: "ar") 
let hebrewLocale = NSLocale(localeIdentifier: "he") 

//called in English
unitedStatesLocale.displayName(forKey: NSLocale.Key.identifier, value: unitedStatesLocale.localeIdentifier)! //"English (United States)"
unitedStatesLocale.displayName(forKey: NSLocale.Key.identifier, value: chinaLocale.localeIdentifier)! //"Chinese (Simplified)"
unitedStatesLocale.displayName(forKey: NSLocale.Key.identifier, value: germanyLocale.localeIdentifier)! //"German (Germany)"
unitedStatesLocale.displayName(forKey: NSLocale.Key.identifier, value: indiaLocale.localeIdentifier)! //"English (India)"
unitedStatesLocale.displayName(forKey: NSLocale.Key.identifier, value: arabicLocale.localeIdentifier)! //"Arabic"
unitedStatesLocale.displayName(forKey: NSLocale.Key.identifier, value: hebrewLocale.localeIdentifier)! //"Hebrew"

//particular locale called in german
germanyLocale.displayName(forKey: NSLocale.Key.identifier, value: unitedStatesLocale.localeIdentifier)! //"Englisch (Vereinigte Staaten)"

//particular locale called in arabic
arabicLocale.displayName(forKey: NSLocale.Key.identifier, value: unitedStatesLocale.localeIdentifier)! //"الإنجليزية (الولايات المتحدة)"

//particular locale called in hebrew
hebrewLocale.displayName(forKey: NSLocale.Key.identifier, value: unitedStatesLocale.localeIdentifier)! //"אנגלית (ארצות הברית)"

//representing Numbers
let pi:NSNumber = 3.14159265358979
var numberFormatter = NumberFormatter()
numberFormatter.numberStyle = NumberFormatter.Style.decimal

//differences in formatting in various locales   
numberFormatter.locale = unitedStatesLocale as Locale!
numberFormatter.string(from: pi ) //"3.142"

numberFormatter.locale = chinaLocale as Locale!
numberFormatter.string(from: pi ) //"3.142"

numberFormatter.locale = germanyLocale as Locale!
numberFormatter.string(from: pi ) //"3,142"

numberFormatter.locale = indiaLocale as Locale!
numberFormatter.string(from: pi ) //"3.142"

numberFormatter.locale = arabicLocale as Locale!
numberFormatter.string(from: pi ) //"٣٫١٤٢"

numberFormatter.locale = hebrewLocale as Locale!
numberFormatter.string(from: pi ) //"3.142"

我可以通过在游乐场的
Resources
文件夹中制作
en.lproj
来实现这一点(请注意,我的系统是英文的,您可能需要将其放入
lproj
中,以便您的语言在您的系统上实现这一点)

需要注意的一点是,如果使用复数
stringsDict
,我总是忘记必须指定键是本地化字符串。你不能只做:

String.localizedStringWithFormat(“下一步”,啤酒)
你必须做到:

String.localizedStringWithFormat(NSLocalizedString(“下一步”,注释:“”),beer)
以下是我所做工作的要点:

感谢您的回复-我实际上是在寻找一种方法来使用我的应用程序的字符串文件,而不是在多个地区打印单个字符串。