Skip to content

Move strings to localiztion files#1360

Merged
sosnovsky merged 9 commits intomasterfrom
feature/issue-956-texts
Feb 8, 2022
Merged

Move strings to localiztion files#1360
sosnovsky merged 9 commits intomasterfrom
feature/issue-956-texts

Conversation

@Kharchevskyi
Copy link
Contributor

@Kharchevskyi Kharchevskyi commented Feb 3, 2022

This PR moves texts to separate strings files.

  • Add missed localizations
  • @inline(__always) func localizeWithArguments(_ arguments: String...) -> String changed to accept only strings arguments to prevent crashes in runtime
  • Enable showNonLocalizedStrings for debug scheme

close #956


Tests (delete all except exactly one):

  • Does not need tests (refactor only, docs or internal changes)

To be filled by reviewers

I have reviewed that this PR... (tick whichever items you personally focused on during this review):

  • addresses the issue it closes (if any)
  • code is readable and understandable
  • is accompanied with tests, or tests are not needed
  • is free of vulnerabilities
  • is documented clearly and usefully, or doesn't need documentation

@Kharchevskyi Kharchevskyi marked this pull request as ready for review February 6, 2022 14:14
@sosnovsky
Copy link
Collaborator

@Kharchevskyi
Copy link
Contributor Author

@sosnovsky thanks, already on it. Checking

Copy link
Collaborator

@sosnovsky sosnovsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just need to fix ui tests and use stringsdict for pluralisation support

userInfoMessage = "import_no_backups_clipboard".localized + user
} else {
userInfoMessage = "Found \(privateKey.count) key\(privateKey.count > 1 ? "s" : "")"
let key = privateKey.count > 1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For such cases it's better to use stringsdict with pluralisation support - it'll automatically use appropriate localization for provided parameter (privateKey.count) - https://github.com/FlowCrypt/flowcrypt-ios/blob/master/FlowCrypt/Resources/Localizable.stringsdict

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why I do not prefer this solution because NSLocalizedString accepts array of CVarArg as arguments and in case we pass string instead of int we will get a crash in runtime

As you see to prevent that I have changed implementation for localizeWithArguments to accept only stings in code and all parameters in localization.strings accepts only %@ as String parameter

@inline(__always) func localizeWithArguments(_ arguments: String...)

With stringsdict solution we need to explicitly pass Int as a variable to be able to distinguish is it variable plural.
Do we really want to have this possibility?

Copy link
Contributor Author

@Kharchevskyi Kharchevskyi Feb 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sosnovsky
What do you think if I leave only Strings as parameters here in localizeWithArguments implementation? And we will use only string as a parameter in localizable files

And will add a separate func localizePluralWithArguments to accept Int and use stringsdict?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sosnovsky What do you think if I leave only Strings as parameters here in localizeWithArguments implementation? And we will use only string as a parameter in localizable files

And will add a separate func localizePluralWithArguments to accept Int and use stringsdict?

Sounds good for me, let's do it this way 👍

switch subtitleType {
case let .fetchedKeys(count):
subtitle = "Found \(count) key backup\(count > 1 ? "s" : "")"
let key = count > 1 ? "setup_fetched_keys" : "setup_fetched_key"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stringsdict should be used here too

@sosnovsky sosnovsky merged commit bf280f4 into master Feb 8, 2022
@sosnovsky sosnovsky deleted the feature/issue-956-texts branch February 8, 2022 20:09
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

Successfully merging this pull request may close these issues.

all texts to be in separate strings files

2 participants