App wont read my localized string file

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

Answered by DTS Engineer in 90178022

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:
  1. in your code, get the localised string with a call to

    NSLocalizedString
    , as shown below
  2. add a

    Localizable.strings
    file to your project
  3. add an entry for your localised string, also shown below

  4. explicitly localise your

    Localizable.strings
    file (via the File Inspector in Xcode)
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?";

It’s traditional to use

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"

I have isolated the problem but dont know the solution.


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!


i removed them and the hard coded strings appear fine.


now the objective is two fold...

  1. where am i supposed to add the key value pair for softcoded strings? the documentation guide for internationalization mentions nothing about it.
  2. i have added localised app name for 'bundle display name' in the languiage's corresponding info.plist file. it doesn't seem to take effect on storyboard!


please help me get this sorted. thanks.

Neerav

The terms you’re using, softcoded and hardcoded, are not Apple terms, so I’m struggling to understand your question. Please explain what you mean by them?

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

I must have picked up those words from some online tutorial.


here, hardcoded = storyboard and xib strings coded directly into interface builder.

softcoded = strings used in code to update UI text. like labe.text = @"hello";


Neerav

hard coded = static strings

soft coded = dynamic strings.

Accepted Answer

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:
  1. in your code, get the localised string with a call to

    NSLocalizedString
    , as shown below
  2. add a

    Localizable.strings
    file to your project
  3. add an entry for your localised string, also shown below

  4. explicitly localise your

    Localizable.strings
    file (via the File Inspector in Xcode)
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?";

It’s traditional to use

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"

i finally figure it out yesterday. But thank u so much for replying here. Ill mark it as correct answer so others can be helped.

App wont read my localized string file
 
 
Q