2016-03-11 12 views
5

C'è un modo per ottenere stringhe localizzate in un parco giochi iOS? Ho un numero di traduzioni della lingua da destra a sinistra che includono i codici di formato che ho dovuto modificare con un editor esadecimale (per garantire che i codici fossero nell'ordine dei byte corretto) e desidero esaminare manualmente l'output della stringa formattata per assicurarsi che funzionasse.Test delle localizzazioni in un parco giochi iOS

Per inciso, esistono degli editor di testo per Mac OS che consentono di visualizzare l'arabo e l'ebraico nella modalità da sinistra a destra?

risposta

0

Swift 3: parco giochi di esempio per le localizzazioni di test

//: 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" 
+0

Grazie per la risposta - mi è stato effettivamente alla ricerca di un modo per utilizzare i file di stringa della mia applicazione, però, di non stampare una singola stringa in più locale . – JustinHK

Problemi correlati