Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Localized strings not working

I check my Localized files and they are free of errors. I'm using the library https://github.com/d0ping/DBAttachmentPickerController and looks like the source of my problems.

I have the following error:

2017-06-23 15:50:31.056756+0200 MyApp[5116:1989916] No localized string for 'file_infected' in 'DBAttachmentPickerController'

DBAttachmentPickerController belongs to the library that I had installed with cocoapods and 'file_infected' is a string that belongs to my project Localized files.

like image 373
Ricardo Avatar asked Feb 28 '26 19:02

Ricardo


1 Answers

I've had this trouble using a library in the past.

I gather both your project and the library you are using will also contain a Localizable.strings. During build time, only one of these files will be copied (or one will overwrite the other). This leads to some interesting intermittent bugs where sometimes your strings are translated, and sometimes they are not!

The most robust solution, though not the fastest is to rename your strings file and use the tableName parameter of NSLocalizedString. e.g. for a file named "RicardosProject.strings", I believe the tableName should be "RicardosProject"

    func NSLocalizedString(
    key: String,
    tableName: String? = default,
    bundle: NSBundle = default,
    value: String = default,
    #comment: String) -> String
like image 69
James Webster Avatar answered Mar 03 '26 08:03

James Webster