Problem of localization with formatting and its (temporary) solution

This post is partly a bug report and partly an overview of the problem with solution, for those with the same problem.

Localization on iOS is done through calls to NSLocalizedString and localizedStringWithFormat (more info). Localizing simple strings via NSLocalizedString works, the problem is with plural strings.

If I understand correctly, NSLocalizedString does not return a standard NSString but a somehow different version with metadata. This metadata does not survive MOE’s conversions and instead of (for example) “one message received”, NSString.localizedStringWithFormat(NSLocalizedString(localizationKey), amount).toString() returns “%#@msgs@ received”, which is clearly wrong.

However, there is a solution - doing the localization in ObjC.

Add these two files to your MOE project. The way it works is simple - the localization is done in ObjC. I needed to format only with single integer number, therefore there is only localize1, but someone fluent in ObjC could easily extend that to variable argument amount.

I hope this helps someone, but as a MOE/ObjC noob, it may be wrong, so feel free to correct me.

1 Like