Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppress User-facing text should use localized string macro warning

Tags:

I am using unlocalized strings and getting below warning

User-facing text should use localized string macro

How to suppress this warning ?

like image 379
Parag Bafna Avatar asked Dec 29 '16 08:12

Parag Bafna


People also ask

What is string localization?

The Localization IdentifierAn unique identifier is attached to each translated string called the "Localization Identifier". It is used to search the dictionaries and locate the value of the string in different languages.

How does NSLocalizedString work?

NSLocalizedString is a Foundation macro that returns a localized version of a string. It has two arguments: key , which uniquely identifies the string to be localized, and comment , a string that is used to provide sufficient context for accurate translation.


2 Answers

From clang documentation:

you can suppress the analyzer warnings (and document your intent) with a function that just returns its input but is annotated to return a localized string:

__attribute__((annotate("returns_localized_nsstring"))) static inline NSString *LocalizationNotNeeded(NSString *s) {   return s; }  [field setStringValue:LocalizationNotNeeded(@"Debug")]; 

Some projects may also find it useful to use NSLocalizedString but add "DNL" or "Do Not Localize" to the string contents

like image 59
Parag Bafna Avatar answered Sep 30 '22 20:09

Parag Bafna


in the project Build Settings: "Static Analyzer - Issues - Apple APIs" set "Missing Localizability" to No

also make sure to not have any Localizations, otherwise will xcode 9 will warn you to turn on "Missing Localizability" analyzer warnings again.

this was trickier for me, i had to open the project file (project.pbxproj) with a text editor and manually empty the list of "knownRegions" otherwise they would not stay deleted

like image 37
Hogdotmac Avatar answered Sep 30 '22 20:09

Hogdotmac