Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make iOS application localized without storyboard?

I followed various tutorials on "How To Localize an iOS(iPhone) App". All of them were suggesting to perform following steps,

  1. Select your project from Project Navigator
  2. Click the checkbox for “Use Base Internationalization”
  3. Select your storyboard to Localizable Strings

But my iOS application xcode 7.2 project does not include any storyboard, so I am not able to enable “Use Base Internationalization” in my iOS application.

Please help me out how to enable “Use Base Internationalization” without storyboard selection and what should I do to perform various alert messages to be localized using "Localizable.strings" file.

like image 383
Chetan Mahajan Avatar asked Jan 14 '16 05:01

Chetan Mahajan


People also ask

How do you do localization in SwiftUI?

Use it in custom SwiftUI views to make them ready for localization. Enable the "Use Compiler to Extract Swift Strings" build setting to extract LocalizedStringKeys from code when exporting for localization in Xcode. Format your strings to internationalize your code, and style them with Markdown.


Video Answer


2 Answers

Go to project->New Files->Resource-> String File-> Save it as Localizable.string

now

  1. Now again go to project setting... then choose project instead of target in setting... Where you have only two options... Go in info section where you find localization... add your language here for localization.

  2. created file is already in base Internationalization mode... now go to file and in side bar of right side check localize button... click on it and chooose language which you added in your project.

  3. now this file add a dropdown in it.. click on arrow... which will show you localized file.string now first one is base english... which is default and second one localized string file...
  4. copy all text which you hardcode in both file like this

Base File-> "Enter a keyword to search" = "Enter a keyword to search"; Localize file -> "Enter a keyword to search" = "Localized String";

now to use this localized string you can fetch strings like this

label.text = NSLocalizedString("your String",nil);

Note:- string file should have name "Localizable"... if you not save it with this name... this will not work.. and you have to provide path every time you use localized string

like image 173
Divyanshu Sharma Avatar answered Nov 14 '22 20:11

Divyanshu Sharma


Thanks to Divyanshu Sharma.
Here is steps for Xcode 8 (Swift 3).

  1. File > New > File... ( ⌘N )
  2. Scroll to "Resource" section and choose "Strings File", press Next
  3. Save it as "Localizable.string" in to your project
  4. In Project Navigator select your new file "Localizable.string" (usually already selected after creating new file)
  5. Go to View > Utilities > Show File Inspector (⌥⌘1)
  6. Locate Localization section and select "Localize..."
  7. Choose base language (I chose English), then click Localize
  8. Open to Project Info settings and in
  9. Press (+) to add new language in Localizations section
  10. Select "Localizable.string" and press Finish in newly opened localizable resource selection window

Now you should have default localizations without Storyboards.

like image 42
Jonauz Avatar answered Nov 14 '22 20:11

Jonauz