Search code examples
iosswiftlocalizable.strings

Localizable.strings (Base) file strings not read by other language set in iPhone?


I've implemented multilingual in my app and having multiple Localizable.strings files created.

enter image description here

I have all strings key and value in Localizable.strings (Base) file, as its default file read from all other languages if perticular string missing in specific language string file e.g. Localizable.strings (Japanese) and some strings are missing in Japanese file so I expecting to get string translation from Base.

But it doesn't happen, thats my problem.


Solution

  • I faced the same issue and applied this solution:

    1. Create new default String localize file for English (DefaultEnglish.strings) E.g: "hello_key" = "Hello"
    2. Add other language support to Localizable.strings file E.g: Japanese string: "hello_key" = "こんにちは"

    enter image description here

    1. Create String extension

      extension String {
      
      func localizedStringKey(bundle _: Bundle = .main, tableName: String = "Localizable") -> String {
          return NSLocalizedString(self, tableName: tableName, value: "\(NSLocalizedString(self, tableName: "DefaultEnglish", bundle: .main, value: self, comment: ""))", comment: "")
      }     }
      
    2. and set string "hello_key".localizedStringKey()