Swift localization
select project-> info -> localization
click + sign and select required languages
in ios string files can add in two places
for storyboard wise localization
these strings cannot apply programatically
in inspector tab select required locations
this will create new string files in project->project name folder-> lancode.IProj folder -> Main.String
if launcher storyboard localization added it will create LaunchScreen.strings file in same folder
*** These language applied when user changed the device language in setting.
when app specific language change can do by changing the budle as below. but user needs to restart the app to use these strings.
programatically access strings
select project-> new file -> String -> name as Localizable.strings (name should be this)
this will create a file in project-> Localizable.strings file
select that file and click localize button in inspector tab
select required languages
add strings in this format
"key" = "value";
these string files access in program by attach bundle path to these files. to change path
let path: String? = Bundle.main.path(forResource: lang, ofType: "lproj")
if path == nil {
bundle = Bundle.main
}
else {
bundle = Bundle(path: path!)
}
No comments:
Post a Comment