When I was experimenting with localization in a copy of my project, everything worked fine. Then I moved the task to my main project.
- I added base localization
- i added hindi as a language.
- a .strings (hindi) file was created for the main storyboard and each xib in my app.
- it had all the key value pairs for hard coded string. i added its hindi translation in the value of each pair
- i added softcoded string key values with comments like /*ListViewController*/ and passed @"ListViewController*/ as argument to the 'comments' parameter of NSLocalizedString macro. similary for each view controllers.
- i cleaned the build folder. i deleted the app from the iphone.
- the region is set to india and language to hindi.
now here is the deal...
dates and currency are appearing localized as expected.
NONE of the hardcoded or soft coded strings appear in Hindi!
I can understand if i have not done the comments argument to NSLocalizedString right but atleast the hardcoded strings should appear normally.
Can someone tell me what i am not doing right?
Note, this worked fine with the copy of the project folder while experimenting and learning localization.
Thanks.
Neerav
the probelm is that adding key value pairs for softcoded strings in the same file generated for storyboards and xibs which have key value pairs for hardcoded strings, dont work!
That’s not expected to work. Localisable strings that you access via
NSLocalizedString are stored in your bundle’s
Localizable.strings file. So, starting with a standard project:
in your code, get the localised string with a call to
, as shown belowNSLocalizedStringadd a
file to your projectLocalizable.stringsadd an entry for your localised string, also shown below
explicitly localise your
file (via the File Inspector in Xcode)Localizable.strings
NSLocalizedString("Are you sure you want to activate the self-destruct sequence?", comment: "Explanatory text for the self-destruct warning alert.")/* Explanatory text for the self-destruct warning alert. */
"Are you sure you want to activate the self-destruct sequence?" = "Are you sure you want to activate the self-destruct sequence?";genstrings to create your initial
Localizable.strings files from your source code (although be aware that it generates UTF-16 files (r. 6844223) whereas most folks use UTF-8 for their source
.strings files, with Xcode converting them to the right format as it builds your project).
Finally, with regards strings in your bundle’s
Info.plist file, you localised those by creating another
.strings file,
InfoPlist.strings.
Share and Enjoy
—
Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"