Snippet of the Week: `NSLocalizedString(_:)`

It’s a good habit to start localizing all your user-facing strings from the get-go, even if you’re just tinkering around on a side project. But, while this is a good habit, it riddles your code with strings like these;

NSLocalizedString("some interesting text", comment: "")

Can you see what’s off? comment: "", that’s what’s off. While the comment is useful for translators later, when you’re in one of your own side-projects, it’s just annoying. And if you make your keys contextual, comments are hardly ever needed at all.

So, I’m planning on starting off with the following snippet in all my iOS side-projects, just to get rid of the comment.

/// Returns `NSLocalizedString(key, comment: "")`
public func NSLocalizedString(_ key: String) -> String {
    return NSLocalizedString(key, comment: "")

If you think the snippet is useful – or have an improvement – send me tweet or a toot!