(There are similar questions. Some resulted in answers that I've tried and found not to work. Others got no answers, I assume because the querents didn't supply as much detail as I'm about to.)
I started with a storyboard that worked well for my app; the strings it contains are in English. I wanted to add a French localization. I did this:
MainStoryboard.storyboard
from en.lproj
to Base.lproj
.InfoPlist.strings
(English)
and MainStoryboard.storyboard
(Base) into fr.lproj
.UISegmentedControl
) in the French MainStoryboard.storyboard
.Result: This worked; my changed strings showed up in the running application.
But I want to be all fancy. I want to do the French localization using a .strings
file. (It's not just a matter of being fancy; the French localization will be turned over to nontechnical translators, who can't be expected to master Interface Builder.) So:
MainStoryboard.storyboard
in the Xcode Project
navigator..strings
file, which appears in the Assistant editor.IBUISegmentedControl...segmentTitles
; and the label text doesn't
appear anywhere else in the .strings
file.Result: The view uses the base (originally English) localization, instead of loading the French strings.
This isn't satisfactory. I've tried deleting the app from the simulator, and even deleting the derived-data folder. The bug persists.
As I said, I can't turn a .storyboard
file over to a nontechnical translator. How can I get iOS to accept the storyboard localizations from a .strings
file?
Click on iOS->App/Single View App->Next. Name your project and select the language as Swift. Select a desired location and click on Create. To start with Localization, click on your Project Name -> go to Info Tab -> Under Localizations, click on the '+' button.
Open Info tab, and click “+” button under Localizations section. Then choose a language you want to support from the dropdown list shown. XCode opens a dialog showing resources to be added for the new language.
Here is how I solved it:
in viewDidLoad:
[self.segmentedControl setTitle:NSLocalizedString(@"Title", @"Your localize comment") forSegmentAtIndex:0];
You can do the same for the search placeholder:
[self.searchBar setPlaceholder:NSLocalizedString(@"Your string placeholder", @"Your comment for localizers")];
Then just create a Localizable.strings file and it will work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With