Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Let's add a rule not to use interpolated strings in translations #16

Open
jkmassel opened this issue Nov 23, 2018 · 1 comment
Assignees

Comments

@jkmassel
Copy link

jkmassel commented Nov 23, 2018

Don't use interpolated strings inside of a call to NSLocalizedString. Use String(format: instead.

Examples

// Correct
let year = 2018
let template = NSLocalizedString("© %d Automattic, Inc.", comment: "Copyright Notice")
let str = String(format: template, year)


// Wrong
let year = 2018
let str = NSLocalizedString("© \(year) Automattic, Inc.", comment: "Copyright Notice")

Rationale

Some translators mentioned in the community Slack that they didn't understand what was being asked for. Because of that, I opened wordpress-mobile/WordPress-iOS#10511. Per @rachelmcr – doing translations this way doesn't work, because the escaping \ doesn't make it into the translation, so it's actually impossible to translate strings that use this format.

Enforcing the rule

I've opened a PR suggesting a Danger rule for this that uses Swiftlint: wordpress-mobile/WordPress-iOS#10526. This issue is an accompaniment to that rule.

@jkmassel jkmassel self-assigned this Nov 23, 2018
@jleandroperez
Copy link
Contributor

Thumbs up on this one!!! Thanks for doing this sir!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants