Faults of iOS App Localization
Hello.
I’m just a beginner in an iOS Development. And I have decided to make my first app as a Keyboard Extension — keyboard, which will allow you to fastly type shortcuts’ symbols on your iOS device.
After I’ve done the app, my friends who don’t know English, asked me every day like: “Please, translate it. Please-please-please.”
Once I decided to do it. Let’s localize the app.
The main thing you’ll do at first is to open Google and ask it for something like “how to localize an ios app”. I did the same.
I’ve localized. As you can see, what I’ve got was far away from what I was expecting for.
Preparations.
Probably, you’ve started with going into “Project → Info → Localizations…” and added a new one:
Then you activated it in File Inspector:
And got a new .strings file:
Which contains dictionary where the key means Storyboard Object ID and assigned value of a new translation.
Okay. Let’s try to localize:
And you’re done! Just start your app, change the language in “Product → Scheme → Edit Scheme…” to prevent it from the necessity of manual changing from the Simulator’s menu.
Running the simulator.
And look at the results:
You and I expected to see fully-localized screen. But what we see is a disappointment.
I googled this and found only the one article on Stackoverflow which says that this bug exists since beardy versions of iOS. There’re no solutions to solve this problem. Oh, sorry, there are.
Anything else?
You can transform your strings file, for example, into a Storyboard. You can try this, but I bet you’ll drop this solution.
Why? Just because when you modify the main Storyboard file (move views, change label captions, etc.), localized ones won’t be updated. Also, if you want to update the strings in code, there’s no way to do that automatically.
In conclusion, I highly recommend you not to use these ways to localize your app.
My way of localizing the app.
Why? Just because I haven’t found an acceptable solution on the Internet in one simple article which will provide you from adding new language to your project to finally opening the app in Simulator and feasting your eyes on the app.
The guidelines
- Let’s use nested naming for keys. For example, instead of using names like “BACK_BUTTON_TITLE”, we’ll use “MainScreen.Back” which describes “WhereTranslate.WhatTranslate”.
- Make a String class extension to get the localized string from .strings file.
Adding .string file to the project
Open “File → New → File…”.
Choose “Strings File”:
Then name it “Localizable”:
So, we’re done! Just add new localization in File Inspector and you’ll see different variaties of .strings file you’ll have to localize.
Make some magic and fill in the file:
Localizing
So, to use this approach, create outlets for the views which you want to localize.
And use our string extension to get the translated versions of the strings.
Using this approach you also can translate formatted strings:
Simulator, how’re you doing?
Don’t forget to use your new localized() method.
Try opening the app and enjoy the results:
Localization of an iOS Bundle
Oh… This is one story about that. It doesn’t work in XCode now. Just doesn’t work…
To localize the bundle use your hands.
Go to the project folder, choose the bundle and right click “Show Package Contents”.
Copy “en.lproj” folder and rename it in a way related to the language which you want to add.
The folder should contain “Root.strings” file.
Call the Wizard and make some Magic
Restart Xcode to apply changes.
Now you’re able to localize your Bundle.
Thank you!
Hope, I helped you a lot while localizing the app.