Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing localizations in an iOS playground

Is there a way to get localized strings into 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 ensure the codes were in the correct byte order), and I wish to manually examine the output of the formatted string to make sure it worked.

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

like image 932
JustinHK Avatar asked Mar 11 '16 19:03

JustinHK


People also ask

What is the difference between playground and Xcode?

An Xcode project allows you to create real apps that you could eventually upload to the App Store (providing you became an Apple Developer). An Xcode Playground allows you to play with code and test it out. It isn't for mainstream developing.

What is the difference between Swift playground and Xcode?

Xcode and Swift are both software development products developed by Apple. Swift is a programming language used to create apps for iOS, macOS, tvOS, and watchOS. Xcode is an Integrated Development Environment (IDE) that comes with a set of tools that helps you build Apple-related apps.

Why is my Xcode playground not running?

Restarting Xcode and rebooting my macbook. Stopping the simulator via the Activity monitor and restarting it. Opening up new tabs in an attempt to refresh. Uninstalling and reinstalling Xcode via the app store.

How do I open swift playground on Mac?

In the Swift Playgrounds app on your Mac, click Run My Code (or use the Touch Bar). If there are instructions on the right side of the screen, they slide down when you click Run My Code, so you can watch your code run in the live view. When you click Stop, the instructions slide back up.


1 Answers

I was able to get this working by making an en.lproj in the Resources folder of a playground (note that my system is in English, you may have to put it in the lproj for your language to get this to work on your system).

One thing to note is that if you're using a plurals stringsDict, I always forget that you have to specify that the key is a localized string. You can't just do:

String.localizedStringWithFormat("next_step", beer)

You have to do:

String.localizedStringWithFormat(NSLocalizedString("next_step", comment: ""), beer)

Here's a gist of what I did: https://gist.github.com/designatednerd/fdfb916cc4d4ad3f33c25e917a95a2be

like image 72
DesignatedNerd Avatar answered Oct 21 '22 09:10

DesignatedNerd