2

What are the advantages and disadvantages of creating following function in a project:

@warn_unused_result
public func NSLocalizedString(key: String) -> String {
    return NSLocalizedString(key)
}

Mostly, we fill NSLocalizedString like this: NSLocalizedString("somekey", comment: ""). Therefore, the code would be more readable, but are there any tools that could be not used, or any other problems we are not aware of?

Kampai
  • 22,848
  • 21
  • 95
  • 95
Daniel
  • 20,420
  • 10
  • 92
  • 149

2 Answers2

1

There is a command line utility called genstrings that goes through all the source code in your project, finds calls to NSLocalizedString, and builds a Localized.strings file from what it finds.

I haven't tried to use it on Swift files yet, so I'm not sure if it even works, but your function might cause problems with that.

Duncan C
  • 128,072
  • 22
  • 173
  • 272
  • Yes, but `genstrings` does not know how to update existing Localizable.string files, so we won't be using it – Daniel May 18 '16 at 14:27
  • there is an [update script](https://github.com/anlcan/AcbUpdateStrings) but it still has some flaws (I already tried it some time ago) – Daniel May 18 '16 at 14:30
0

If you use a 3rd party localization service the comment can provide context for the translator. Keep in mind that the service many not have access to the computer code.

zaph
  • 111,848
  • 21
  • 189
  • 228
  • 1
    yes, but it is not being filled anyways, I mean, if we were to use such a tool later, we could still extend the functions with the comment – Daniel May 18 '16 at 14:26