8

I need to lauch iOS Simulator that uses specific language using command line. So I found that I can use

instruments -w <device>

and it is working great, I can set specific device. But how can I run simulator with specific language? I've tried adding

-AppleLanguages -AppleLocale

but there are some warnings:

Instruments Usage Error : Specified target process is invalid: -AppleLanguage

thanks!

MichalMoskala
  • 887
  • 1
  • 12
  • 25

4 Answers4

6

To run your app must be installed and located (if not, will open default language)

Use this command to run your app with some language

xcrun simctl launch <deviceid> <appid> -AppleLanguages "(pt-BR)"

Sample:

xcodebuild -sdk iphonesimulator8.4 -arch i386 install DSTROOT=SomeFolder
xcrun instruments -w "iPhone 6 (8.4 Simulator)"
xcrun simctl install booted SomeFolder/Applications/YourApp.app
xcrun simctl launch booted com.yourdomain.yourapp -AppleLanguages "(pt-BR)"
Haroldo Gondim
  • 7,725
  • 9
  • 43
  • 62
  • If you need to know localize your app this [tutorial](http://www.raywenderlich.com/64401/internationalization-tutorial-for-ios-2014) is a good way to start. – Haroldo Gondim Jul 15 '15 at 22:42
6

The only way to launch iOS Simulator with specific language is to change contents of its .GlobalPreferences.plist file. Using xcrun tool will not work because it passess arguments to launched app and not changing language of simulator itself. Manipulation on .GlobalPreferences.plist is quite difficult because it is a binary plist file, so you cannot modify it as 'normal' xml. The easiest way to change its contents is to write simple Xcode Command Line Tool application, Foundation SDK has all tools needed to modify binary plists.

Haroldo Gondim
  • 7,725
  • 9
  • 43
  • 62
MichalMoskala
  • 887
  • 1
  • 12
  • 25
  • Just in addition to make someone's pain less hurt, the plist is located at `~/Library/Developer/CoreSimulator/Devices/${YOURID}/data/Library/Preferences` since Xcode 8 I believe... (Changed path from previous Xcode versions) Correct me if I am wrong, but I think you can edit the plist file right now and leave the language key for your desired and delete the others and it will work. Also I believe you can just edit it for once with classic plist editor and you are okay... – Dominik Bucher Jun 25 '18 at 08:25
  • 1
    This is a script I use to change locale in simulator before launching: https://gist.github.com/rumax/2470ec2fcc3ef84420542f049589407e See related article: https://itnext.io/you-dont-need-gui-or-how-to-control-ios-simulator-from-command-line-bf5cfa60aed2 – mmccabe Jul 15 '19 at 01:36
  • @mmccabe any hint on why Simulator version 12.4 always changes the default keyboard settings even after setting it in `GlobalPreferences.plist`? – Bruno Bieri Mar 09 '21 at 08:46
  • I ended up with a doing two things to end up with only one keyboard layout in the iOS Simulator. First as described in this answer I updated the GlobalPreferences.plist for that particular Simulator. Then I started the Simulator and before my actual UI Test I automated the Settings app of iOS to remove the keyboard which is automatically added by iOS Simulator once I start it. This way I ended up with only the keyboard layout I want to have. To get the simulator ID: https://itnext.io/you-dont-need-gui-or-how-to-control-ios-simulator-from-command-line-bf5cfa60aed2 – Bruno Bieri Mar 24 '21 at 08:19
0

Have a look at:

https://developer.apple.com/library/ios/documentation/MacOSX/Conceptual/BPInternational/TestingYourInternationalApp/TestingYourInternationalApp.html Search for "Testing Specific Languages and Regions"

Perhaps it could also be a solution creating different targets. Each target has configured another language

charlyatwork
  • 1,187
  • 8
  • 13
0
export UDID=202B1006-C2DE-4CC6–8791–6EA4C3782XXX
plutil -replace AppleLocale -string "en_GB" ~/Library/Developer/CoreSimulator/Devices/$UDID/data/Library/Preferences/.GlobalPreferences.plist
xcrun simctl shutdown $UDID
xcrun simctl boot $UDID
Tejasvi Manmatha
  • 564
  • 7
  • 12