Skip to content

Commit

Permalink
Merge pull request #641 from glouel/feature/1.4.6
Browse files Browse the repository at this point in the history
Beta 2 with support for community translations in /locale folder in c…
  • Loading branch information
glouel authored Nov 11, 2018
2 parents 6b34efa + 184530f commit cc7266e
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 31 deletions.
4 changes: 3 additions & 1 deletion Aerial/Source/Controllers/PreferencesWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ class PreferencesWindowController: NSWindowController, NSOutlineViewDataSource,
@IBOutlet weak var cacheSizeTextField: NSTextField!
@IBOutlet var newVideosModePopup: NSPopUpButton!

@IBOutlet var lastCheckedVideosLabel: NSTextField!

var player: AVPlayer = AVPlayer()

var videos: [AerialVideo]?
Expand Down Expand Up @@ -509,7 +511,7 @@ class PreferencesWindowController: NSWindowController, NSOutlineViewDataSource,
extraCornerPopup.selectItem(at: preferences.extraCorner!)

newVideosModePopup.selectItem(at: preferences.newVideosMode!)

lastCheckedVideosLabel.stringValue = "Last checked on " + preferences.lastVideoCheck!
colorizeProjectPageLinks()

if let cacheDirectory = VideoCache.cacheDirectory {
Expand Down
70 changes: 55 additions & 15 deletions Aerial/Source/Models/Cache/PoiStringProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class PoiStringProvider {
var stringDict: NSDictionary?

var communityStrings = [CommunityStrings]()

var communityLanguage = ""
// MARK: - Lifecycle
init() {
debugLog("Poi Strings Provider initialized")
Expand Down Expand Up @@ -86,7 +86,7 @@ class PoiStringProvider {
let locale: NSLocale = NSLocale(localeIdentifier: Locale.preferredLanguages[0])

if #available(OSX 10.12, *) {
if preferences.localizeDescriptions && locale.languageCode != "en" {
if preferences.localizeDescriptions && locale.languageCode != communityLanguage {
return stringBundle!.localizedString(forKey: key, value: "", table: "Localizable.nocache")
}
}
Expand Down Expand Up @@ -121,7 +121,7 @@ class PoiStringProvider {
let locale: NSLocale = NSLocale(localeIdentifier: Locale.preferredLanguages[0])

if #available(OSX 10.12, *) {
if preferences.localizeDescriptions && locale.languageCode != "en" {
if preferences.localizeDescriptions && locale.languageCode != communityLanguage {
return video.poi
}
}
Expand All @@ -135,20 +135,60 @@ class PoiStringProvider {

// MARK: - Community data

// Load the community strings
private func loadCommunity() {
private func getCommunityPathForLocale() -> String {
let preferences = Preferences.sharedInstance
let locale: NSLocale = NSLocale(localeIdentifier: Locale.preferredLanguages[0])

var bundlePath: String
if preferences.localizeDescriptions {
bundlePath = Bundle(for: PoiStringProvider.self).path(forResource: "en", ofType: "json")!
//bundlePath = Bundle.main.path(forResource: "en", ofType: "json")!
} else {
// TODO
bundlePath = Bundle(for: PoiStringProvider.self).path(forResource: "en", ofType: "json")!
//bundlePath = Bundle.main.path(forResource: "en", ofType: "json")!
if #available(OSX 10.12, *) {
// First we look in the Cache Folder for a locale directory
let cacheDirectory = VideoCache.cacheDirectory!
var cacheResourcesString = cacheDirectory
cacheResourcesString.append(contentsOf: "/locale")
let cacheUrl = URL(fileURLWithPath: cacheResourcesString)

if cacheUrl.hasDirectoryPath {
debugLog("Aerial cache directory contains /locale")
var cc = locale.countryCode!.lowercased()
if !preferences.localizeDescriptions {
cc = "en"
}
debugLog("Looking for \(cc).json")

let fileUrl = URL(fileURLWithPath: cacheResourcesString.appending("/\(cc).json"))
debugLog(fileUrl.absoluteString)
let fileManager = FileManager.default
if fileManager.fileExists(atPath: fileUrl.path) {
debugLog("Locale description found")
communityLanguage = cc
return fileUrl.path
} else {
debugLog("Locale description not found")
}
}
debugLog("Defaulting to bundle")
let cc = locale.countryCode!.lowercased()
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!
}
}
}
}

// Fallback to english in bundle
communityLanguage = "en"
return Bundle(for: PoiStringProvider.self).path(forResource: "en", ofType: "json")!
}

// Load the community strings
private func loadCommunity() {
let bundlePath = getCommunityPathForLocale()
debugLog("path : \(bundlePath)")

do {
let data = try Data(contentsOf: URL(fileURLWithPath: bundlePath), options: .mappedIfSafe)
let batches = try JSONSerialization.jsonObject(with: data, options: .allowFragments)
Expand All @@ -168,9 +208,9 @@ class PoiStringProvider {
}
} catch {
// handle error
errorLog("Community JSON ERROR")
errorLog("Community JSON ERROR : \(error)")
}
debugLog("Community JSON : \(communityStrings.count)")
debugLog("Community JSON : \(communityStrings.count) entries")
}

func getCommunityName(id: String) -> String? {
Expand Down
8 changes: 7 additions & 1 deletion Aerial/Source/Models/ManifestLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,11 @@ class ManifestLoader {
} else {
// Ok then, we fetch them...
debugLog("Fetching missing manifests online")
let dateFormatter = DateFormatter()
let current = Date()
dateFormatter.dateFormat = "yyyy-MM-dd"
preferences.lastVideoCheck = dateFormatter.string(from: current)

let downloadManager = DownloadManager()

var urls: [URL] = []
Expand Down Expand Up @@ -322,7 +327,8 @@ class ManifestLoader {
// Fallback on earlier versions
}

if Int((dateObj?.timeIntervalSinceNow)!) > dayCheck * 1440 {
debugLog("Interval : \(String(describing: dateObj?.timeIntervalSinceNow))")
if Int((dateObj?.timeIntervalSinceNow)!) < -dayCheck * 86400 {
// We need to redownload
debugLog("Checking for new videos")
moveOldManifests()
Expand Down
4 changes: 2 additions & 2 deletions Resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.4.6beta1</string>
<string>1.4.6beta2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.4.6beta1</string>
<string>1.4.6beta2</string>
<key>LSApplicationCategoryType</key>
<string></string>
<key>LSMinimumSystemVersion</key>
Expand Down
34 changes: 22 additions & 12 deletions Resources/PreferencesWindow.xib
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<outlet property="iconTime1" destination="lQX-Ux-Sz8" id="JNc-dR-kDA"/>
<outlet property="iconTime2" destination="VuJ-HC-hN5" id="AbN-SY-Tux"/>
<outlet property="iconTime3" destination="W77-TL-rnp" id="ncL-NO-Mb0"/>
<outlet property="lastCheckedVideosLabel" destination="N4V-cr-IpU" id="e9x-ZB-zu3"/>
<outlet property="latitudeFormatter" destination="XKU-5s-ymT" id="ER9-CV-byp"/>
<outlet property="latitudeTextField" destination="d5o-Ad-4FR" id="CnE-zq-n5o"/>
<outlet property="lightDarkModeLabel" destination="XQ7-f2-0uN" id="UUs-Je-cud"/>
Expand Down Expand Up @@ -905,7 +906,7 @@ should appear</string>
</view>
</tabViewItem>
<tabViewItem label="Time" identifier="" id="PtY-yV-jgj">
<view key="view" ambiguous="YES" id="ziy-Hg-uzO">
<view key="view" id="ziy-Hg-uzO">
<rect key="frame" x="10" y="33" width="614" height="381"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
Expand Down Expand Up @@ -1322,7 +1323,7 @@ Shift, but macOS 10.12.4 or above and a compatible Mac are required) </string>
</view>
</tabViewItem>
<tabViewItem label="Cache" identifier="2" id="kp1-xv-zNG">
<view key="view" id="93q-v8-yxM">
<view key="view" ambiguous="YES" id="93q-v8-yxM">
<rect key="frame" x="10" y="33" width="614" height="381"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
Expand All @@ -1349,7 +1350,7 @@ Shift, but macOS 10.12.4 or above and a compatible Mac are required) </string>
</connections>
</button>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="ZO8-hg-MHd">
<rect key="frame" x="11" y="154" width="172" height="32"/>
<rect key="frame" x="11" y="109" width="172" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="push" title="Change Cache Location" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="wqv-ni-QwP">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
Expand All @@ -1360,7 +1361,7 @@ Shift, but macOS 10.12.4 or above and a compatible Mac are required) </string>
</connections>
</button>
<button toolTip="Download all missing videos for your currently selected format" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="118-Gb-ppx">
<rect key="frame" x="12" y="73" width="131" height="32"/>
<rect key="frame" x="12" y="28" width="131" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="push" title="Download Now" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="OL6-Qf-3eQ">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
Expand All @@ -1371,7 +1372,7 @@ Shift, but macOS 10.12.4 or above and a compatible Mac are required) </string>
</connections>
</button>
<pathControl verticalHuggingPriority="750" fixedFrame="YES" allowsExpansionToolTips="YES" translatesAutoresizingMaskIntoConstraints="NO" id="XAJ-Se-rwG">
<rect key="frame" x="14" y="198" width="587" height="22"/>
<rect key="frame" x="14" y="153" width="587" height="22"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<pathCell key="cell" selectable="YES" editable="YES" alignment="left" placeholderString="Failed to load cache location" id="gVD-I9-Ldu">
<font key="font" metaFont="system"/>
Expand All @@ -1390,7 +1391,7 @@ Shift, but macOS 10.12.4 or above and a compatible Mac are required) </string>
</connections>
</button>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="918-ug-3EV">
<rect key="frame" x="431" y="154" width="172" height="32"/>
<rect key="frame" x="431" y="109" width="172" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="push" title="Show in Finder" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="MMG-EW-6UN">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
Expand All @@ -1401,11 +1402,11 @@ Shift, but macOS 10.12.4 or above and a compatible Mac are required) </string>
</connections>
</button>
<box verticalHuggingPriority="750" fixedFrame="YES" boxType="separator" translatesAutoresizingMaskIntoConstraints="NO" id="yTU-fU-3PQ">
<rect key="frame" x="10" y="258" width="595" height="5"/>
<rect key="frame" x="10" y="213" width="595" height="5"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
</box>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="moU-Bx-4Wo">
<rect key="frame" x="8" y="235" width="98" height="17"/>
<rect key="frame" x="8" y="190" width="98" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="Cache location:" id="TL8-4s-qsK">
<font key="font" metaFont="system"/>
Expand All @@ -1414,11 +1415,11 @@ Shift, but macOS 10.12.4 or above and a compatible Mac are required) </string>
</textFieldCell>
</textField>
<box verticalHuggingPriority="750" fixedFrame="YES" boxType="separator" translatesAutoresizingMaskIntoConstraints="NO" id="Q9n-mn-wEk">
<rect key="frame" x="10" y="139" width="595" height="5"/>
<rect key="frame" x="10" y="94" width="595" height="5"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
</box>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="L70-Vj-qPk">
<rect key="frame" x="8" y="116" width="293" height="17"/>
<rect key="frame" x="8" y="71" width="293" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="Cache all videos (around 20 GB required in 4K):" id="G1X-uz-p5V">
<font key="font" metaFont="system"/>
Expand All @@ -1427,7 +1428,7 @@ Shift, but macOS 10.12.4 or above and a compatible Mac are required) </string>
</textFieldCell>
</textField>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="s26-kk-0xc">
<rect key="frame" x="221" y="154" width="172" height="32"/>
<rect key="frame" x="221" y="109" width="172" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="push" title="Reset to Default" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="aQN-yr-MJE">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
Expand Down Expand Up @@ -1464,6 +1465,15 @@ Shift, but macOS 10.12.4 or above and a compatible Mac are required) </string>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="N4V-cr-IpU">
<rect key="frame" x="26" y="243" width="573" height="17"/>
<autoresizingMask key="autoresizingMask"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="Last checked on " id="bSi-OR-QoO">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
</view>
</tabViewItem>
Expand Down Expand Up @@ -2114,7 +2124,7 @@ You can enable it when on battery, or only when your battery reach 20%.</string>
<resources>
<image name="NSActionTemplate" width="14" height="14"/>
<image name="NSBookmarksTemplate" width="17" height="18"/>
<image name="NSCaution" width="128" height="128"/>
<image name="NSCaution" width="32" height="32"/>
<image name="NSGoLeftTemplate" width="9" height="12"/>
<image name="NSHomeTemplate" width="14" height="14"/>
<image name="NSRefreshTemplate" width="11" height="15"/>
Expand Down

0 comments on commit cc7266e

Please sign in to comment.