modify language unit tests to work on all locales

This commit is contained in:
Satindar Dhillon
2023-01-25 10:23:01 -08:00
parent 06b3150252
commit 3b5350eced
5 changed files with 44 additions and 17 deletions

View File

@ -1,7 +1,7 @@
import Foundation
public enum LocalText {
public static func localText(key: String, comment: String? = nil) -> String {
private static func localText(key: String, comment: String? = nil) -> String {
NSLocalizedString(key, bundle: .module, comment: comment ?? "no comment provided by developer")
}

View File

@ -1,3 +1,7 @@
// Unit test Entry -- Do not remove this or add entries before this one.
// This allows us to check for syntax errors in this file with a unit test
"unitTestLeadingEntry" = "For testing purposes only.";
// share extension
"saveArticleSavedState" = "Saved to Omnivore";
"saveArticleProcessingState" = "Saved to Omnivore";
@ -190,3 +194,7 @@
"errorNetwork" = "We are having trouble connecting to the internet.";
// TODO: search navigationTitle, toggle, section, button, Label
// Unit test Entry -- Do not remove this or add entries after this one.
// This allows us to check for syntax errors in this file with a unit test
"unitTestTrailingEntry" = "For testing purposes only.";

View File

@ -1 +1,9 @@
// Unit test Entry -- Do not remove this or add entries before this one.
// This allows us to check for syntax errors in this file with a unit test
"unitTestLeadingEntry" = "For testing purposes only.";
"googleSignInButton" = "Continuar con Google";
// Unit test Entry -- Do not remove this or add entries after this one.
// This allows us to check for syntax errors in this file with a unit test
"unitTestTrailingEntry" = "For testing purposes only.";

View File

@ -1,3 +1,7 @@
// Unit test Entry -- Do not remove this or add entries before this one.
// This allows us to check for syntax errors in this file with a unit test
"unitTestLeadingEntry" = "For testing purposes only.";
// share extension
"saveArticleSavedState" = "正在保存到 Omnivore 中";
"saveArticleProcessingState" = "已经保存到 Omnivore 中";
@ -198,3 +202,7 @@
// "username.validation.error.tooshort" = "用户名应至少包含 3 个英文字符.";
// "username.validation.error.toolong" = "用户名不能超过 15 个英文字符.";
// "saveArticleSavingState" = "保存中...";
// Unit test Entry -- Do not remove this or add entries after this one.
// This allows us to check for syntax errors in this file with a unit test
"unitTestTrailingEntry" = "For testing purposes only.";

View File

@ -7,25 +7,28 @@ final class LocalTextTests: XCTestCase {
// Testing the first and last entry in teh strings file is adequate for finding syntax errors.
// If any entry is not proper than the key will be returned and the test will fail.
// English (test default)
XCTAssertNotEqual(LocalText.saveArticleSavedState, "saveArticleSavedState")
XCTAssertNotEqual(LocalText.errorNetwork, "errorNetwork")
// Simple Chinese
XCTAssertNotEqual(simpleChineseText(key: "saveArticleSavedState"), "saveArticleSavedState")
XCTAssertNotEqual(simpleChineseText(key: "errorNetwork"), "errorNetwork")
}
private func simpleChineseText(key: String) -> String {
guard
let bundlePath = Bundle.module.path(forResource: "zh-Hans", ofType: "lproj"),
let bundle = Bundle(path: bundlePath)
else { return key }
return NSLocalizedString(key, bundle: bundle, comment: "")
for languageCode in LanguageCode.allCases {
XCTAssertNotEqual(languageCode.translation(key: "unitTestLeadingEntry"), "unitTestLeadingEntry")
XCTAssertNotEqual(languageCode.translation(key: "unitTestTrailingEntry"), "unitTestTrailingEntry")
}
}
static var allTests = [
("testThatLocalTextFindsStrings", testThatLocalTextFindsStrings)
]
}
private enum LanguageCode: String, CaseIterable {
case english = "en"
case simpleChinese = "zh-Hans"
case spanish = "es"
func translation(key: String) -> String {
guard
let bundlePath = Bundle.module.path(forResource: rawValue, ofType: "lproj"),
let bundle = Bundle(path: bundlePath)
else { return key }
return NSLocalizedString(key, bundle: bundle, comment: "")
}
}