Localization Testing on the iOS Playground

Is there a way to get localized strings on an iOS playground? I have a number of right-to-left language translations that include format codes that I had to edit with a hex editor (to make sure the codes were in the correct byte order), and I want to manually examine the output of the formatted string to make sure it worked.

Aside, are there any Mac OS text editors that allow you to display Arabic and Hebrew in left-to-right mode?

+5
source share
1 answer

Swift 3: an example of a playground for testing localization

//: 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
source

Source: https://habr.com/ru/post/1244916/


All Articles