What is the second parameter of NSLocalizedString?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
The second parameter of NSLocalizedString is the translator comment, provided using the comment label in Swift. It is not displayed to end users at runtime. Its purpose is to give localization context so translators can choose accurate wording.
Basic Signature and Intent
Typical Swift usage:
- First argument: localization key.
- Second argument: context comment for translators.
This comment is metadata for localization workflow, not user interface text.
Why Comments Improve Translation Quality
Many UI strings are ambiguous without context. A short note prevents mistranslation.
Examples of ambiguous strings:
Opencan be a verb or adjective.Savecan mean persist a file or reduce cost.
Contextual comment example:
Clear notes reduce translation churn and review cycles.
Advanced Variant with Table and Bundle
Foundation also provides a more detailed API:
In this variant:
tableNameselects localization table.bundleselects resource bundle.valueis fallback text.commentstill provides translator context.
This is useful in modular apps and frameworks.
Localization Workflow Perspective
Comments are especially important when strings are extracted and sent to external localization vendors. Translators often work without direct app context, so notes are their primary hint.
Useful comment content:
- Where text appears.
- Tone requirements, if relevant.
- Placeholder meaning.
For format strings, explain dynamic values clearly.
When Empty Comments Are Acceptable
In tiny internal tools with one language and one developer, empty comments might be tolerable. In most products, they become a maintenance cost.
As soon as multiple languages, translators, or teams are involved, meaningful comments should be treated as standard practice.
Key Naming and Comments Together
Comments work best when keys are stable and semantic.
- Prefer keys like
checkout.button.confirm. - Avoid using full source text as key.
Stable keys plus descriptive comments give both engineering and localization teams a predictable system.
Plurals, Formatting, and Comment Quality
Localization is not only key lookup. Pluralization and formatted values need additional context to avoid grammatical errors. When using format placeholders, comment text should explain meaning, units, and expected range.
For production apps, also test pseudo-localized builds and long-string languages to confirm UI still reads correctly. Translator comments reduce semantic mistakes, while visual testing catches layout issues such as clipping and truncation. Both are necessary for high-quality localization.
Common Pitfalls
A common pitfall is using identical keys for different contexts to reduce key count. Same source text can require different translations depending on screen meaning.
Another issue is stale comments after feature changes. If UI meaning changes but comments do not, translation quality drops.
Developers also forget to document placeholder semantics, causing format errors or unnatural translations.
Finally, skipping comments for critical user flows like billing and permissions can create expensive production fixes after localization review.
Summary
- The second parameter of
NSLocalizedStringis a translator comment. - It is context metadata, not runtime UI text.
- Good comments reduce ambiguity and improve translation quality.
- The same concept applies in advanced localization API variants.
- Keep comments current and aligned with key semantics.
Related reading
- What is the second parameter of NSLocalizedString?
- What is the shortcut to Auto import all in Android Studio?
- What is the simplest and most robust way to get the user's current location on Android?
- What is the simplest and most robust way to get the user's current location on Android?
- What is the size of ActionBar in pixels?
- What is the some keyword in SwiftUI?
- What is the Swift equivalent of -NSObject description?
- What is the Swift equivalent of isEqualToString in Objective-C?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.