Skip to content

Commit

Permalink
Fixed plurals when all plural cases are the same. Version 2.51.
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Krasnocka committed Aug 23, 2023
1 parent f369292 commit 4d74e55
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
4 changes: 4 additions & 0 deletions LocsUtil.xcodeproj/xcshareddata/xcschemes/LocsUtil.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@
</BuildableReference>
</BuildableProductRunnable>
<CommandLineArguments>
<CommandLineArgument
argument = "ios"
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "input/localizations.xlsx"
isEnabled = "YES">
Expand Down
2 changes: 1 addition & 1 deletion LocsUtil/LocsGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class LocsGenerator: NSObject {
var xlsxReader: XlsxReader
let langRowIndex = 0 // Language definitions - row index in XSLSX document
let keyColumnId = "A" // Key definitions - column index in XSLSX document
let version = "2.50"
let version = "2.51"

override init() {
// csvReader = CsvReader()
Expand Down
23 changes: 16 additions & 7 deletions LocsUtil/PluralsHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,23 @@ extension Array where Element == String {
}
}

if let distinctIndex = distinctIndex, let components = allComponents.first {
var mutatedComponents = components

let pluralWords = allComponents.map { components in
components[distinctIndex]
if let components = allComponents.first {
if let distinctIndex = distinctIndex {
var mutatedComponents = components

let pluralWords = allComponents.map { components in
components[distinctIndex]
}
mutatedComponents[distinctIndex] = "%#@\(pluralFormatPlaceholder)@"
return (mutatedComponents.joined(separator: " "), pluralWords)
} else {
// there's no distinctIndex - every form of the plural string is the same
var emptyPlurals = [String]()
for _ in 0..<allComponents.count {
emptyPlurals.append("")
}
return (components.joined(separator: " ") + "%#@\(pluralFormatPlaceholder)@", emptyPlurals)
}
mutatedComponents[distinctIndex] = "%#@\(pluralFormatPlaceholder)@"
return (mutatedComponents.joined(separator: " "), pluralWords)
} else {
return nil
}
Expand Down
Binary file modified bin/locsutil
Binary file not shown.

0 comments on commit 4d74e55

Please sign in to comment.