有没有办法让本地化的字符串进入iOS游乐场?我有一些从右到左的语言翻译,其中包括我必须使用十六进制编辑器编辑的格式代码(以确保代码的顺序正确),我希望手动检查格式化字符串的输出确保它有效。
顺便说一句,是否有任何Mac OS文本编辑器允许您以从左到右的模式显示阿拉伯语和希伯来语?
答案 0 :(得分:0)
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"
答案 1 :(得分:0)
我可以通过在游乐场的en.lproj
文件夹中创建一个Resources
来完成此工作(请注意,我的系统是英文的,您可能必须将其放入{{1} },以使其在您的系统上正常运行)。
要注意的一件事是,如果您使用的是复数lproj
,我总是会忘记必须指定键为本地化字符串。您不能只是做:
stringsDict
您必须这样做:
String.localizedStringWithFormat("next_step", beer)
以下是我所做的要点: https://gist.github.com/designatednerd/fdfb916cc4d4ad3f33c25e917a95a2be