Skip to content

Commit

Permalink
Merge pull request #744 from glouel/master
Browse files Browse the repository at this point in the history
Add Arabic language support
  • Loading branch information
glouel committed Apr 17, 2019
2 parents 5bdfe7a + e5a0fac commit 7cd4f36
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 13 deletions.
6 changes: 6 additions & 0 deletions Aerial.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
035A92A7225F8C480095AB85 /* de.json in Resources */ = {isa = PBXBuildFile; fileRef = 035A92A4225F8C480095AB85 /* de.json */; };
035A92A8225F8C480095AB85 /* he.json in Resources */ = {isa = PBXBuildFile; fileRef = 035A92A5225F8C480095AB85 /* he.json */; };
035A92A9225F8C480095AB85 /* he.json in Resources */ = {isa = PBXBuildFile; fileRef = 035A92A5225F8C480095AB85 /* he.json */; };
035A92AC226754760095AB85 /* ar.json in Resources */ = {isa = PBXBuildFile; fileRef = 035A92AB226754760095AB85 /* ar.json */; };
035A92AD226754760095AB85 /* ar.json in Resources */ = {isa = PBXBuildFile; fileRef = 035A92AB226754760095AB85 /* ar.json */; };
0369985D2196103300E359D3 /* missingvideos.json in Resources */ = {isa = PBXBuildFile; fileRef = 0369985C2196103300E359D3 /* missingvideos.json */; };
0369985E2196129C00E359D3 /* missingvideos.json in Resources */ = {isa = PBXBuildFile; fileRef = 0369985C2196103300E359D3 /* missingvideos.json */; };
03893CB3217749F0008E7125 /* ErrorLog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03893CB2217749F0008E7125 /* ErrorLog.swift */; };
Expand Down Expand Up @@ -114,6 +116,7 @@
03510C722185EF76008F74F2 /* CoreLocation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreLocation.framework; path = System/Library/Frameworks/CoreLocation.framework; sourceTree = SDKROOT; };
035A92A4225F8C480095AB85 /* de.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = de.json; sourceTree = "<group>"; };
035A92A5225F8C480095AB85 /* he.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = he.json; sourceTree = "<group>"; };
035A92AB226754760095AB85 /* ar.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = ar.json; sourceTree = "<group>"; };
0369985C2196103300E359D3 /* missingvideos.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = missingvideos.json; sourceTree = "<group>"; };
03893CB2217749F0008E7125 /* ErrorLog.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ErrorLog.swift; sourceTree = "<group>"; };
039385792175D4B80040B850 /* AVPlayerViewExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AVPlayerViewExtension.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -199,6 +202,7 @@
033192DF217B77E90073B580 /* Community */ = {
isa = PBXGroup;
children = (
035A92AB226754760095AB85 /* ar.json */,
035A92A4225F8C480095AB85 /* de.json */,
035A92A5225F8C480095AB85 /* he.json */,
03D3DAC3221F286700BDA52F /* pl.json */,
Expand Down Expand Up @@ -526,6 +530,7 @@
0369985E2196129C00E359D3 /* missingvideos.json in Resources */,
033D62B0216CAE2C00F3AF83 /* icon-night-dark.pdf in Resources */,
0395835621807D1F008E8F9C /* thumbnail.png in Resources */,
035A92AD226754760095AB85 /* ar.json in Resources */,
03D3DAC5221F286D00BDA52F /* pl.json in Resources */,
FAC36F481BE1756D007F2A20 /* Assets.xcassets in Resources */,
033D62AC216CADCD00F3AF83 /* icon-day-dark.pdf in Resources */,
Expand Down Expand Up @@ -554,6 +559,7 @@
FAC36F531BE1756D007F2A20 /* PreferencesWindow.xib in Resources */,
035A92A6225F8C480095AB85 /* de.json in Resources */,
03D37FDB22145487005A146F /* fr.json in Resources */,
035A92AC226754760095AB85 /* ar.json in Resources */,
FAC36F4D1BE1756D007F2A20 /* icon-day.pdf in Resources */,
035A92A8225F8C480095AB85 /* he.json in Resources */,
03D3DAC4221F286700BDA52F /* pl.json in Resources */,
Expand Down
9 changes: 9 additions & 0 deletions Aerial.xcodeproj/xcshareddata/xcschemes/Aerial.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,14 @@
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
<PostActions>
<ExecutionAction
ActionType = "Xcode.IDEStandardExecutionActionsCore.ExecutionActionType.ShellScriptAction">
<ActionContent
title = "Run Script"
scriptText = "# Type a script or drag a script file from your workspace to insert its path.&#10;">
</ActionContent>
</ExecutionAction>
</PostActions>
</ArchiveAction>
</Scheme>
11 changes: 11 additions & 0 deletions Aerial/Source/Controllers/Preferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ final class Preferences {
case darkModeNightOverride = "darkModeNightOverride"
case newVideosMode = "newVideosMode"
case lastVideoCheck = "lastVideoCheck"
case ciOverrideLanguage = "ciOverrideLanguage"
}

enum NewVideosMode: Int {
Expand Down Expand Up @@ -183,6 +184,7 @@ final class Preferences {
defaultValues[.alternateVideoFormat] = AlternateVideoFormat.powerSaving
defaultValues[.darkModeNightOverride] = false
defaultValues[.newVideosMode] = NewVideosMode.weekly
defaultValues[.ciOverrideLanguage] = ""

// Set today's date as default
let dateFormatter = DateFormatter()
Expand Down Expand Up @@ -399,6 +401,15 @@ final class Preferences {
}
}

var ciOverrideLanguage: String? {
get {
return optionalValue(forIdentifier: .ciOverrideLanguage)
}
set {
setValue(forIdentifier: .ciOverrideLanguage, value: newValue)
}
}

var latitude: String? {
get {
return optionalValue(forIdentifier: .latitude)
Expand Down
12 changes: 12 additions & 0 deletions Aerial/Source/Controllers/PreferencesWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ final class PreferencesWindowController: NSWindowController, NSOutlineViewDataSo

@IBOutlet var fadeInOutModePopup: NSPopUpButton!
@IBOutlet weak var fadeInOutTextModePopup: NSPopUpButton!
@IBOutlet var ciOverrideLanguagePopup: NSPopUpButton!

@IBOutlet weak var downloadProgressIndicator: NSProgressIndicator!
@IBOutlet weak var downloadStopButton: NSButton!
Expand Down Expand Up @@ -350,6 +351,11 @@ final class PreferencesWindowController: NSWindowController, NSOutlineViewDataSo
currentLocaleLabel.stringValue = ""
}

let poisp = PoiStringProvider.sharedInstance

// Should we override the community language ?
ciOverrideLanguagePopup.selectItem(at: poisp.getLanguagePosition())

// Videos panel
playerView.player = player
playerView.controlsStyle = .none
Expand Down Expand Up @@ -871,6 +877,12 @@ final class PreferencesWindowController: NSWindowController, NSOutlineViewDataSo
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
Expand Down
66 changes: 62 additions & 4 deletions Aerial/Source/Models/Cache/PoiStringProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ final class PoiStringProvider {
let locale: NSLocale = NSLocale(localeIdentifier: Locale.preferredLanguages[0])

if #available(OSX 10.12, *) {
if preferences.localizeDescriptions && locale.languageCode != communityLanguage {
if preferences.localizeDescriptions && locale.languageCode != communityLanguage && preferences.ciOverrideLanguage == "" {
return stringBundle!.localizedString(forKey: key, value: "", table: "Localizable.nocache")
}
}
Expand Down Expand Up @@ -115,7 +115,7 @@ final class PoiStringProvider {
let locale: NSLocale = NSLocale(localeIdentifier: Locale.preferredLanguages[0])
if #available(OSX 10.12, *) {
debugLog("locale.languageCode \(locale.languageCode)")
if preferences.localizeDescriptions && locale.languageCode != communityLanguage {
if preferences.localizeDescriptions && locale.languageCode != communityLanguage && preferences.ciOverrideLanguage == "" {
return video.poi
}
}
Expand All @@ -128,11 +128,24 @@ final class PoiStringProvider {
}

// MARK: - Community data

// swiftlint:disable:next cyclomatic_complexity
private func getCommunityPathForLocale() -> String {
let preferences = Preferences.sharedInstance
let locale: NSLocale = NSLocale(localeIdentifier: Locale.preferredLanguages[0])

// Do we have a community language override ?
if preferences.localizeDescriptions && preferences.ciOverrideLanguage != "" {
let path = Bundle(for: PoiStringProvider.self).path(forResource: preferences.ciOverrideLanguage, ofType: "json")
if path != nil {
let fileManager = FileManager.default
if fileManager.fileExists(atPath: path!) {
debugLog("Community Language overriden to : \(preferences.ciOverrideLanguage!)")
communityLanguage = preferences.ciOverrideLanguage!
return path!
}
}
}

if #available(OSX 10.12, *) {
// First we look in the Cache Folder for a locale directory
let cacheDirectory = VideoCache.cacheDirectory!
Expand Down Expand Up @@ -163,7 +176,7 @@ final class PoiStringProvider {
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" {
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 {
Expand Down Expand Up @@ -217,4 +230,49 @@ final class PoiStringProvider {
func getCommunityPoi(id: String) -> [String: String] {
return communityStrings.first(where: { $0.id == id }).map { $0.poi } ?? [:]
}

// Helpers for the main popup
func getLanguagePosition() -> Int {
let preferences = Preferences.sharedInstance
// The list is alphabetized based on their english name in the UI
switch preferences.ciOverrideLanguage {
case "ar": // Arabic
return 1
case "en": // English
return 2
case "fr": // French
return 3
case "de": // German
return 4
case "he": // Hebrew
return 5
case "pl": // Polish
return 6
case "es": // Spanish
return 7
default: // This is the default, preferred language
return 0
}
}

func getLanguageStringFromPosition(pos: Int) -> String {
switch pos {
case 1:
return "ar"
case 2:
return "en"
case 3:
return "fr"
case 4:
return "de"
case 5:
return "he"
case 6:
return "pl"
case 7:
return "es"
default:
return ""
}
}
}
1 change: 1 addition & 0 deletions Aerial/Source/Views/AerialView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ final class AerialView: ScreenSaverView {
class var sharedPlayer: AVPlayer {
struct Static {
static let instance: AVPlayer = AVPlayer()
// swiftlint:disable:next identifier_name
static var _player: AVPlayer?
static var player: AVPlayer {
if let activePlayer = _player {
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.7beta7</string>
<string>1.4.7beta8</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.4.7beta7</string>
<string>1.4.7beta8</string>
<key>LSApplicationCategoryType</key>
<string></string>
<key>LSMinimumSystemVersion</key>
Expand Down
48 changes: 41 additions & 7 deletions Resources/PreferencesWindow.xib
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.AVKitIBPlugin" version="14460.31"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14460.31"/>
<plugIn identifier="com.apple.AVKitIBPlugin" version="14490.70"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14490.70"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand All @@ -17,6 +17,7 @@
<outlet property="calculateCoordinatesLabel" destination="YXF-Ei-ZTD" id="LEn-QN-uyy"/>
<outlet property="changeCornerMargins" destination="VPG-cS-U1N" id="F9P-rV-FaD"/>
<outlet property="checkNowButton" destination="EeC-Lg-0GW" id="3zr-3y-AW9"/>
<outlet property="ciOverrideLanguagePopup" destination="Thy-6K-bQe" id="eGe-Iv-gxJ"/>
<outlet property="cornerBottomLeft" destination="Qhn-AB-VZ5" id="YIg-vu-QIS"/>
<outlet property="cornerBottomRight" destination="4Rr-4h-bRr" id="5oY-Eh-CdE"/>
<outlet property="cornerContainer" destination="NQf-K9-FZk" id="SU0-YA-s4F"/>
Expand Down Expand Up @@ -144,7 +145,7 @@
<font key="font" metaFont="system"/>
<tabViewItems>
<tabViewItem label="Videos" identifier="1" id="dfl-QA-fvD">
<view key="view" ambiguous="YES" id="zsM-Ha-kCO">
<view key="view" id="zsM-Ha-kCO">
<rect key="frame" x="10" y="33" width="614" height="381"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
Expand Down Expand Up @@ -531,7 +532,7 @@ is disabled
</view>
</tabViewItem>
<tabViewItem label="Text" identifier="" id="bPY-uP-DGa">
<view key="view" id="M1m-ud-C95">
<view key="view" ambiguous="YES" id="M1m-ud-C95">
<rect key="frame" x="10" y="33" width="614" height="381"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
Expand Down Expand Up @@ -766,9 +767,9 @@ should appear</string>
</connections>
</popUpButton>
<button toolTip="Aerial includes community location information for some of the videos that lacks them" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="1e6-Z5-uo6">
<rect key="frame" x="48" y="245" width="313" height="18"/>
<rect key="frame" x="48" y="245" width="204" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Use community information when available" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="6kr-NQ-0Qs">
<buttonCell key="cell" type="check" title="Use community information " bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="6kr-NQ-0Qs">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
Expand Down Expand Up @@ -912,6 +913,39 @@ should appear</string>
<action selector="openExtraMessagePanelClick:" target="-2" id="wbb-xx-rwF"/>
</connections>
</button>
<popUpButton verticalHuggingPriority="750" fixedFrame="YES" verifyAmbiguity="off" translatesAutoresizingMaskIntoConstraints="NO" id="Thy-6K-bQe">
<rect key="frame" x="266" y="241" width="114" height="25"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<popUpButtonCell key="cell" type="push" title="Preferred" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="xCg-g0-Bhx" id="nf2-lO-M2x">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="menu"/>
<menu key="menu" id="hcD-mb-d4o">
<items>
<menuItem title="Preferred" state="on" id="xCg-g0-Bhx"/>
<menuItem title="Arabic" identifier="ar" id="ff1-1V-Nvx"/>
<menuItem title="English" id="s5O-ET-pwQ"/>
<menuItem title="French" id="vbj-hw-EYv">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem title="German" id="G44-Tt-1ZX">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem title="Hebrew" id="QpG-d9-xro">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem title="Polish" id="zqo-Rm-Pz1">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem title="Spanish" id="QDZ-R9-uaF">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
</items>
</menu>
</popUpButtonCell>
<connections>
<action selector="communityLanguagePopupChange:" target="-2" id="LqZ-oy-tyk"/>
</connections>
</popUpButton>
</subviews>
</view>
</tabViewItem>
Expand Down

0 comments on commit 7cd4f36

Please sign in to comment.