From b614b344103cb8d46c7b5bafea79f9ad01f76ca6 Mon Sep 17 00:00:00 2001 From: Jakub Olejnik Date: Fri, 11 Sep 2020 16:20:41 +0200 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20Fix=20creation=20of=20empty?= =?UTF-8?q?=20files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/ACKLocalizationCore/ACKLocalization.swift | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Sources/ACKLocalizationCore/ACKLocalization.swift b/Sources/ACKLocalizationCore/ACKLocalization.swift index 8516b43..aac6353 100644 --- a/Sources/ACKLocalizationCore/ACKLocalization.swift +++ b/Sources/ACKLocalizationCore/ACKLocalization.swift @@ -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) } @@ -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) From 89f62a63111ad48dbb6e9af3e07421f9d6fc31ac Mon Sep 17 00:00:00 2001 From: Jakub Olejnik Date: Fri, 11 Sep 2020 16:30:54 +0200 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=93=9D=20Update=20CHANGELOG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c2e4bfa..43dd0b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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