-
-
Save toddhopkinson/3797d5ee37c8d250dc82ea772b49a30f to your computer and use it in GitHub Desktop.
Very simple automated test to ensure localizations exist and are well-formed on iOS.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import XCTest | |
/// Basic sanity check that ensures that we are able to retrieve localized strings for all languages | |
/// we support. | |
final class L10NTests: XCTestCase { | |
func testLocalizations() { | |
let locales = ["en", "es", "zh-Hans", "zh-Hant", "fi"] | |
for locale in locales { | |
verify(localeIdentifier: locale) | |
} | |
} | |
} | |
extension L10NTests { | |
/// Verifies a localization is available by fetching one string from the Localizable.strings file. | |
func verify(localeIdentifier: String) { | |
guard let path = Bundle.main.path(forResource: localeIdentifier, ofType: "lproj"), | |
let bundle = Bundle(path: path) else { | |
XCTFail("Missing localization for \(localeIdentifier)"); return | |
} | |
// Pick any string from the Localizable.strings file; ideally one that's unlikely to be removed ;) | |
let string = bundle.localizedString(forKey: "generic.delete", value: nil, table: nil) | |
XCTAssertFalse(string.isEmpty) | |
XCTAssertNotEqual(string, "generic.delete") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment