-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from seunbanwo/feature/image-feed/ui/localization
Localization - English, Portuguese (pt-BR), and Greek
- Loading branch information
Showing
17 changed files
with
191 additions
and
29 deletions.
There are no files selected for viewing
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
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
9 changes: 9 additions & 0 deletions
9
EssentialFeed/EssentialFeediOS/Feed Presentation/el.lproj/Feed.strings
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
Feed.strings | ||
EssentialFeed | ||
|
||
Created by Oluwaseun Adebanwo on 29/11/2023. | ||
|
||
*/ | ||
|
||
"FEED_VIEW_TITLE" = "Το Feed μου"; |
9 changes: 9 additions & 0 deletions
9
EssentialFeed/EssentialFeediOS/Feed Presentation/en.lproj/Feed.strings
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
Feed.strings | ||
EssentialFeed | ||
|
||
Created by Oluwaseun Adebanwo on 29/11/2023. | ||
|
||
*/ | ||
|
||
"FEED_VIEW_TITLE" = "My Feed"; |
9 changes: 9 additions & 0 deletions
9
EssentialFeed/EssentialFeediOS/Feed Presentation/pt-BR.lproj/Feed.strings
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
Feed.strings | ||
EssentialFeed | ||
|
||
Created by Oluwaseun Adebanwo on 29/11/2023. | ||
|
||
*/ | ||
|
||
"FEED_VIEW_TITLE" = "Meu Feed"; |
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
64 changes: 64 additions & 0 deletions
64
EssentialFeed/EssentialFeediOSTests/Feed Presentation/FeedLocalizationTests.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// | ||
// FeedLocalizationTests.swift | ||
// EssentialFeediOSTests | ||
// | ||
// Created by Oluwaseun Adebanwo on 29/11/2023. | ||
// | ||
|
||
import XCTest | ||
@testable import EssentialFeediOS | ||
|
||
final class FeedLocalizationTests: XCTestCase { | ||
|
||
func test_localizedStrings_haveKeysAndValuesForAllSupportedLocalizations() { | ||
let table = "Feed" | ||
let presentationBundle = Bundle(for: FeedPresenter.self) | ||
let localizationBundles = allLocalizationBundles(in: presentationBundle) | ||
let localizedStringKeys = allLocalizedStringKeys(in: localizationBundles, table: table) | ||
|
||
localizationBundles.forEach { (bundle, localization) in | ||
localizedStringKeys.forEach { key in | ||
let localizedString = bundle.localizedString(forKey: key, value: nil, table: table) | ||
|
||
if localizedString == key { | ||
let language = Locale.current.localizedString(forLanguageCode: localization) ?? "" | ||
|
||
XCTFail("Missing \(language) (\(localization)) localized string for key: '\(key)' in table: '\(table)'") | ||
} | ||
} | ||
} | ||
} | ||
|
||
// MARK: - Helpers | ||
|
||
private typealias LocalizedBundle = (bundle: Bundle, localization: String) | ||
|
||
private func allLocalizationBundles(in bundle: Bundle, file: StaticString = #file, line: UInt = #line) -> [LocalizedBundle] { | ||
return bundle.localizations.compactMap { localization in | ||
guard | ||
let path = bundle.path(forResource: localization, ofType: "lproj"), | ||
let localizedBundle = Bundle(path: path) | ||
else { | ||
XCTFail("Couldn't find bundle for localization: \(localization)", file: file, line: line) | ||
return nil | ||
} | ||
|
||
return (localizedBundle, localization) | ||
} | ||
} | ||
|
||
private func allLocalizedStringKeys(in bundles: [LocalizedBundle], table: String, file: StaticString = #file, line: UInt = #line) -> Set<String> { | ||
return bundles.reduce([]) { (acc, current) in | ||
guard | ||
let path = current.bundle.path(forResource: table, ofType: "strings"), | ||
let strings = NSDictionary(contentsOfFile: path), | ||
let keys = strings.allKeys as? [String] | ||
else { | ||
XCTFail("Couldn't load localized strings for localization: \(current.localization)", file: file, line: line) | ||
return acc | ||
} | ||
|
||
return acc.union(Set(keys)) | ||
} | ||
} | ||
} |
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
File renamed without changes.
File renamed without changes.
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
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
22 changes: 22 additions & 0 deletions
22
...tialFeed/EssentialFeediOSTests/Feed UI/Helpers/FeedViewControllerTests+Localization.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// FeedViewControllerTests+Localization.swift | ||
// EssentialFeediOSTests | ||
// | ||
// Created by Oluwaseun Adebanwo on 29/11/2023. | ||
// | ||
|
||
import Foundation | ||
import XCTest | ||
import EssentialFeediOS | ||
|
||
extension FeedUIIntegrationTests { | ||
func localized(_ key: String, file: StaticString = #file, line: UInt = #line) -> String { | ||
let table = "Feed" | ||
let bundle = Bundle(for: FeedViewController.self) | ||
let value = bundle.localizedString(forKey: key, value: nil, table: table) | ||
if value == key { | ||
XCTFail("Missing localized string for key: \(key) in table: \(table)", file: file, line: line) | ||
} | ||
return value | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.