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

🐛 Fix creation of empty files #20

Merged
merged 2 commits into from
Sep 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

## master

### Fixed
- Fix creating empty files when spreadsheet doesn't contain any plurals or only plurals ([#20](https://github.com/AckeeCZ/ACKLocalization/pull/17), kudos to @olejnjak)

## 1.1.1

### Fixed
Expand Down
14 changes: 9 additions & 5 deletions Sources/ACKLocalizationCore/ACKLocalization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,13 @@ public final class ACKLocalization {

try plistOutputs.forEach { try writeRows($1, to: dirPath + "/" + $0 + ".strings") }

// Create stringDict from data and save it
let encoder = PropertyListEncoder()
encoder.outputFormat = .xml
let data = try encoder.encode(plurals)
try data.write(to: URL(fileURLWithPath: pluralsPath))
if plurals.count > 0 {
// Create stringDict from data and save it
let encoder = PropertyListEncoder()
encoder.outputFormat = .xml
let data = try encoder.encode(plurals)
try data.write(to: URL(fileURLWithPath: pluralsPath))
}
} catch {
throw LocalizationError(message: "Unable to save mapped values - " + error.localizedDescription)
}
Expand Down Expand Up @@ -319,6 +321,8 @@ public final class ACKLocalization {

/// Actually writes given `rows` to given `file`
private func writeRows(_ rows: [LocRow], to file: String) throws {
guard rows.count > 0 else { return }

try rows.map { $0.localizableRow }
.joined(separator: "\n")
.write(toFile: file, atomically: true, encoding: .utf8)
Expand Down