Skip to content

Commit

Permalink
Merge pull request #829 from glouel/master
Browse files Browse the repository at this point in the history
Greatly simplify language handling, there's now a single language pic…
  • Loading branch information
glouel authored Jul 8, 2019
2 parents 5a870b1 + 36b0ab0 commit 96f83cd
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 113 deletions.
8 changes: 4 additions & 4 deletions Aerial.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1175,15 +1175,15 @@
CODE_SIGN_IDENTITY = "Developer ID Application: Guillaume Louel (3L54M5L5KK)";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1.5.1beta8;
CURRENT_PROJECT_VERSION = 1.5.1beta9;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = 3L54M5L5KK;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = "$(SRCROOT)/Resources/Info.plist";
INSTALL_PATH = "$(HOME)/Library/Screen Savers";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.9;
MARKETING_VERSION = 1.5.1beta8;
MARKETING_VERSION = 1.5.1beta9;
PRODUCT_BUNDLE_IDENTIFIER = com.johncoates.Aerial;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -1204,15 +1204,15 @@
CODE_SIGN_IDENTITY = "Developer ID Application: Guillaume Louel (3L54M5L5KK)";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1.5.1beta8;
CURRENT_PROJECT_VERSION = 1.5.1beta9;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = 3L54M5L5KK;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = "$(SRCROOT)/Resources/Info.plist";
INSTALL_PATH = "$(HOME)/Library/Screen Savers";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.9;
MARKETING_VERSION = 1.5.1beta8;
MARKETING_VERSION = 1.5.1beta9;
OTHER_CODE_SIGN_FLAGS = "--timestamp";
PRODUCT_BUNDLE_IDENTIFIER = com.johncoates.Aerial;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
3 changes: 0 additions & 3 deletions Aerial/Source/Controllers/PWC Tabs/PWC+Cache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ extension PreferencesWindowController {
if preferences.neverStreamPreviews {
neverStreamPreviewsCheckbox.state = .on
}
if !preferences.useCommunityDescriptions {
useCommunityCheckbox.state = .off
}
if !preferences.cacheAerials {
cacheAerialsAsTheyPlayCheckbox.state = .off
}
Expand Down
21 changes: 2 additions & 19 deletions Aerial/Source/Controllers/PWC Tabs/PWC+Text.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ extension PreferencesWindowController {
} else {
changeTextState(to: false)
}
if preferences.localizeDescriptions {
localizeForTvOS12Checkbox.state = .on
}
if preferences.overrideMargins {
changeCornerMargins.state = .on
marginHorizontalTextfield.isEnabled = true
Expand Down Expand Up @@ -140,8 +137,8 @@ extension PreferencesWindowController {

func changeTextState(to: Bool) {
// Location information
useCommunityCheckbox.isEnabled = to
localizeForTvOS12Checkbox.isEnabled = to
//useCommunityCheckbox.isEnabled = to
//localizeForTvOS12Checkbox.isEnabled = to
descriptionModePopup.isEnabled = to
fadeInOutTextModePopup.isEnabled = to
fontPickerButton.isEnabled = to
Expand Down Expand Up @@ -176,26 +173,12 @@ extension PreferencesWindowController {
extraCornerPopup.isEnabled = to
}

@IBAction func useCommunityClick(_ button: NSButton) {
let state = useCommunityCheckbox.state
let onState = state == .on
preferences.useCommunityDescriptions = onState
debugLog("UI useCommunity: \(onState)")
}

@IBAction func communityLanguagePopupChange(_ sender: NSPopUpButton) {
debugLog("UI communityLanguagePopupChange: \(sender.indexOfSelectedItem)")
let poisp = PoiStringProvider.sharedInstance
preferences.ciOverrideLanguage = poisp.getLanguageStringFromPosition(pos: sender.indexOfSelectedItem)
}

@IBAction func localizeForTvOS12Click(button: NSButton?) {
let state = localizeForTvOS12Checkbox.state
let onState = state == .on
preferences.localizeDescriptions = onState
debugLog("UI localizeDescriptions: \(onState)")
}

@IBAction func descriptionModePopupChange(_ sender: NSPopUpButton) {
debugLog("UI descriptionMode: \(sender.indexOfSelectedItem)")
preferences.showDescriptionsMode = sender.indexOfSelectedItem
Expand Down
22 changes: 0 additions & 22 deletions Aerial/Source/Controllers/Preferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ final class Preferences {
case customCacheDirectory = "cacheDirectory"
case videoFormat = "videoFormat"
case showDescriptions = "showDescriptions"
case useCommunityDescriptions = "useCommunityDescriptions"
case showDescriptionsMode = "showDescriptionsMode"
case neverStreamVideos = "neverStreamVideos"
case neverStreamPreviews = "neverStreamPreviews"
case localizeDescriptions = "localizeDescriptions"
case timeMode = "timeMode"
case manualSunrise = "manualSunrise"
case manualSunset = "manualSunset"
Expand Down Expand Up @@ -172,11 +170,9 @@ final class Preferences {
defaultValues[.cacheAerials] = true
defaultValues[.videoFormat] = VideoFormat.v1080pH264
defaultValues[.showDescriptions] = true
defaultValues[.useCommunityDescriptions] = true
defaultValues[.showDescriptionsMode] = DescriptionMode.fade10seconds
defaultValues[.neverStreamVideos] = false
defaultValues[.neverStreamPreviews] = false
defaultValues[.localizeDescriptions] = false
defaultValues[.timeMode] = TimeMode.disabled
defaultValues[.manualSunrise] = "09:00"
defaultValues[.manualSunset] = "19:00"
Expand Down Expand Up @@ -437,15 +433,6 @@ final class Preferences {
}
}

var useCommunityDescriptions: Bool {
get {
return value(forIdentifier: .useCommunityDescriptions)
}
set {
setValue(forIdentifier: .useCommunityDescriptions, value: newValue)
}
}

var dimBrightness: Bool {
get {
return value(forIdentifier: .dimBrightness)
Expand Down Expand Up @@ -644,15 +631,6 @@ final class Preferences {
}
}

var localizeDescriptions: Bool {
get {
return value(forIdentifier: .localizeDescriptions)
}
set {
setValue(forIdentifier: .localizeDescriptions, value: newValue)
}
}

var fontName: String? {
get {
return optionalValue(forIdentifier: .fontName)
Expand Down
52 changes: 22 additions & 30 deletions Aerial/Source/Models/Cache/PoiStringProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ final class PoiStringProvider {
let preferences = Preferences.sharedInstance

var bundlePath = VideoCache.appSupportDirectory!
if preferences.localizeDescriptions {
if preferences.ciOverrideLanguage == "" {
// We load the bundle and let system grab the closest available preferred language
bundlePath.append(contentsOf: "/TVIdleScreenStrings.bundle")
} else {
bundlePath.append(contentsOf: "/TVIdleScreenStrings.bundle/en.lproj/")
// Or we load the overriden one
bundlePath.append(contentsOf: "/TVIdleScreenStrings.bundle/" + preferences.ciOverrideLanguage! + ".lproj/")
}

if let sb = Bundle.init(path: bundlePath) {
Expand All @@ -59,17 +61,14 @@ final class PoiStringProvider {

self.stringBundle = sb
self.loadedDescriptions = true
self.loadedDescriptionsWasLocalized = preferences.localizeDescriptions
} else {
errorLog("TVIdleScreenStrings.bundle is missing, please remove entries.json in Cache folder to fix the issue")
}
}

// Make sure we have the correct bundle loaded
private func ensureLoadedBundle() -> Bool {
let preferences = Preferences.sharedInstance

if loadedDescriptions && loadedDescriptionsWasLocalized == preferences.localizeDescriptions {
if loadedDescriptions {
return true
} else {
loadBundle()
Expand All @@ -81,16 +80,16 @@ final class PoiStringProvider {
func getString(key: String, video: AerialVideo) -> String {
guard ensureLoadedBundle() else { return "" }

let preferences = Preferences.sharedInstance
/*let preferences = Preferences.sharedInstance
let locale: NSLocale = NSLocale(localeIdentifier: Locale.preferredLanguages[0])

if #available(OSX 10.12, *) {
if preferences.localizeDescriptions && locale.languageCode != communityLanguage && preferences.ciOverrideLanguage == "" {
return stringBundle!.localizedString(forKey: key, value: "", table: "Localizable.nocache")
}
}
}*/

if preferences.useCommunityDescriptions && !video.communityPoi.isEmpty {
if !video.communityPoi.isEmpty {
return key // We directly store the string in the key
} else {
return stringBundle!.localizedString(forKey: key, value: "", table: "Localizable.nocache")
Expand All @@ -111,16 +110,16 @@ final class PoiStringProvider {

//
func getPoiKeys(video: AerialVideo) -> [String: String] {
let preferences = Preferences.sharedInstance
/*let preferences = Preferences.sharedInstance
let locale: NSLocale = NSLocale(localeIdentifier: Locale.preferredLanguages[0])
if #available(OSX 10.12, *) {
debugLog("locale.languageCode \(locale.languageCode)")
if preferences.localizeDescriptions && locale.languageCode != communityLanguage && preferences.ciOverrideLanguage == "" {
return video.poi
}
}
}*/

if preferences.useCommunityDescriptions && !video.communityPoi.isEmpty {
if !video.communityPoi.isEmpty {
return video.communityPoi
} else {
return video.poi
Expand All @@ -133,8 +132,8 @@ final class PoiStringProvider {
let preferences = Preferences.sharedInstance
let locale: NSLocale = NSLocale(localeIdentifier: Locale.preferredLanguages[0])

// Do we have a community language override ?
if preferences.localizeDescriptions && preferences.ciOverrideLanguage != "" {
// Do we have a language override ?
if preferences.ciOverrideLanguage != "" {
let path = Bundle(for: PoiStringProvider.self).path(forResource: preferences.ciOverrideLanguage, ofType: "json")
if path != nil {
let fileManager = FileManager.default
Expand All @@ -155,10 +154,8 @@ final class PoiStringProvider {

if cacheUrl.hasDirectoryPath {
debugLog("Aerial cache directory contains /locale")
var cc = locale.languageCode
if !preferences.localizeDescriptions {
cc = "en"
}

let cc = locale.languageCode
debugLog("Looking for \(cc).json")

let fileUrl = URL(fileURLWithPath: cacheResourcesString.appending("/\(cc).json"))
Expand All @@ -174,20 +171,15 @@ final class PoiStringProvider {
}
debugLog("Defaulting to bundle")
let cc = locale.languageCode
// Just in case, cause we had a crash earlier with the fr one for some reason...
// This is probably no longer needed
// if cc == "en" || cc == "es" || cc == "fr" || cc == "pl" || cc == "de" || cc == "he" || cc == "ar" {
if preferences.localizeDescriptions {
let path = Bundle(for: PoiStringProvider.self).path(forResource: cc, ofType: "json")
if path != nil {
let fileManager = FileManager.default
if fileManager.fileExists(atPath: path!) {
communityLanguage = cc
return path!
}

let path = Bundle(for: PoiStringProvider.self).path(forResource: cc, ofType: "json")
if path != nil {
let fileManager = FileManager.default
if fileManager.fileExists(atPath: path!) {
communityLanguage = cc
return path!
}
}
//}
}

// Fallback to english in bundle
Expand Down
2 changes: 1 addition & 1 deletion Aerial/Source/Views/AerialView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ final class AerialView: ScreenSaverView, CAAnimationDelegate {
if preferences.showDescriptions {
// Preventively, make sure we have poi as tvOS11/10 videos won't have them
if (!video.poi.isEmpty && poiStringProvider.loadedDescriptions) ||
(preferences.useCommunityDescriptions && !video.communityPoi.isEmpty && !poiStringProvider.getPoiKeys(video: video).isEmpty) {
(!video.communityPoi.isEmpty && !poiStringProvider.getPoiKeys(video: video).isEmpty) {
// Collect all the timestamps from the JSON
var times = [NSValue]()
let keys = poiStringProvider.getPoiKeys(video: video)
Expand Down
Loading

0 comments on commit 96f83cd

Please sign in to comment.