Skip to content

Commit a3f0c50

Browse files
loutskiyloutskiy
authored andcommitted
Dynamic localization from config
1 parent 3284432 commit a3f0c50

47 files changed

Lines changed: 137 additions & 62 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Installer.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
A757F2C021022D0E0049AE99 /* License.html in Resources */ = {isa = PBXBuildFile; fileRef = A757F2BF21022D0D0049AE99 /* License.html */; };
2525
A79A15DD212C1649002BD735 /* Localizable.stringsdict in Resources */ = {isa = PBXBuildFile; fileRef = A79A15DF212C1649002BD735 /* Localizable.stringsdict */; };
2626
A79A15E2212C1724002BD735 /* String+extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = A79A15E1212C1724002BD735 /* String+extension.swift */; };
27+
A79A15E7212C356E002BD735 /* Language.swift in Sources */ = {isa = PBXBuildFile; fileRef = A79A15E6212C356E002BD735 /* Language.swift */; };
28+
A79A15E9212C3984002BD735 /* FirstVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = A79A15E8212C3984002BD735 /* FirstVC.swift */; };
2729
A7AE17DA2105EADA0086343D /* Script.sh in Resources */ = {isa = PBXBuildFile; fileRef = A7AE17D92105EADA0086343D /* Script.sh */; };
2830
A7AE17FC210B50DE0086343D /* LanguageManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7AE17FB210B50DE0086343D /* LanguageManager.swift */; };
2931
A7DE66B220F8D25200746EE0 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7DE66B120F8D25200746EE0 /* AppDelegate.swift */; };
@@ -59,6 +61,8 @@
5961
A79A15E1212C1724002BD735 /* String+extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+extension.swift"; sourceTree = "<group>"; };
6062
A79A15E4212C1AF6002BD735 /* Base */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = Base; path = Base.lproj/Localizable.stringsdict; sourceTree = "<group>"; };
6163
A79A15E5212C1AF8002BD735 /* ru */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = ru; path = ru.lproj/Localizable.stringsdict; sourceTree = "<group>"; };
64+
A79A15E6212C356E002BD735 /* Language.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Language.swift; sourceTree = "<group>"; };
65+
A79A15E8212C3984002BD735 /* FirstVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirstVC.swift; sourceTree = "<group>"; };
6266
A7AE17D92105EADA0086343D /* Script.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = Script.sh; sourceTree = "<group>"; };
6367
A7AE17FB210B50DE0086343D /* LanguageManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LanguageManager.swift; sourceTree = "<group>"; };
6468
A7DE66AE20F8D25200746EE0 /* Installer.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Installer.app; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -123,6 +127,7 @@
123127
A716D12220FCA641001998D7 /* WindowController.swift */,
124128
A716D12420FCA68D001998D7 /* Loader.swift */,
125129
A7F96ED321186DCD002D9078 /* NameStorage.swift */,
130+
A79A15E8212C3984002BD735 /* FirstVC.swift */,
126131
A716D10A20FC9C41001998D7 /* LicenseVC.swift */,
127132
A716D11420FCA0C7001998D7 /* ProgressVC.swift */,
128133
A75637A32119CFF000FDB9D6 /* FinalVC.swift */,
@@ -132,6 +137,7 @@
132137
A757F2B2210092F60049AE99 /* Array+Extension.swift */,
133138
A7AE17FB210B50DE0086343D /* LanguageManager.swift */,
134139
A79A15E1212C1724002BD735 /* String+extension.swift */,
140+
A79A15E6212C356E002BD735 /* Language.swift */,
135141
A757F2BF21022D0D0049AE99 /* License.html */,
136142
A716D10E20FC9E8F001998D7 /* config.json */,
137143
A757F2B82100B3B10049AE99 /* key.asc */,
@@ -294,8 +300,10 @@
294300
A75637AA211B033C00FDB9D6 /* NotificationExtension.swift in Sources */,
295301
A75637A42119CFF000FDB9D6 /* FinalVC.swift in Sources */,
296302
A757F2BE2100D6350049AE99 /* VerifySigning.m in Sources */,
303+
A79A15E7212C356E002BD735 /* Language.swift in Sources */,
297304
A7DE66C220F8DCC800746EE0 /* ContainerVC.swift in Sources */,
298305
A716D10B20FC9C41001998D7 /* LicenseVC.swift in Sources */,
306+
A79A15E9212C3984002BD735 /* FirstVC.swift in Sources */,
299307
A7AE17FC210B50DE0086343D /* LanguageManager.swift in Sources */,
300308
A7F96ED421186DCD002D9078 /* NameStorage.swift in Sources */,
301309
A7DE66B220F8D25200746EE0 /* AppDelegate.swift in Sources */,

Installer/Base.lproj/Main.storyboard

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -428,11 +428,11 @@
428428
</objects>
429429
<point key="canvasLocation" x="75.5" y="230.5"/>
430430
</scene>
431-
<!--View Controller-->
431+
<!--FirstVC-->
432432
<scene sceneID="hIz-AP-VOD">
433433
<objects>
434434
<customObject id="rPt-NT-nkU" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
435-
<viewController storyboardIdentifier="WelcomeVC" id="XfG-lQ-9wD" sceneMemberID="viewController">
435+
<viewController storyboardIdentifier="FirstVC" id="XfG-lQ-9wD" customClass="FirstVC" customModule="Installer" customModuleProvider="target" sceneMemberID="viewController">
436436
<view key="view" wantsLayer="YES" id="m2S-Jp-Qdl">
437437
<rect key="frame" x="0.0" y="0.0" width="782" height="507"/>
438438
<autoresizingMask key="autoresizingMask"/>
@@ -465,11 +465,11 @@
465465
</objects>
466466
<point key="canvasLocation" x="914" y="231"/>
467467
</scene>
468-
<!--View Controller-->
468+
<!--FirstVC-->
469469
<scene sceneID="Vrg-Fr-daR">
470470
<objects>
471471
<customObject id="vKn-hC-cQB" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
472-
<viewController storyboardIdentifier="WelcomeVC" id="YYl-0L-SSK" sceneMemberID="viewController">
472+
<viewController storyboardIdentifier="FirstVC" id="YYl-0L-SSK" customClass="FirstVC" customModule="Installer" customModuleProvider="target" sceneMemberID="viewController">
473473
<view key="view" wantsLayer="YES" id="LkJ-ip-9UW">
474474
<rect key="frame" x="0.0" y="0.0" width="782" height="507"/>
475475
<autoresizingMask key="autoresizingMask"/>
@@ -483,8 +483,11 @@
483483
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" image="Array_logo_dark_bg_p" id="EaM-7y-HoB"/>
484484
</imageView>
485485
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="TmJ-lC-18u">
486-
<rect key="frame" x="207" y="108" width="368" height="18"/>
487-
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="To install Array.io 1.0.0 on your computer, click Continue." id="kuA-zK-hW6">
486+
<rect key="frame" x="18" y="108" width="746" height="18"/>
487+
<constraints>
488+
<constraint firstAttribute="width" constant="742" id="Kx1-RM-e1C"/>
489+
</constraints>
490+
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="center" title="To install Array.io 1.0.0 on your computer, click Continue." id="kuA-zK-hW6">
488491
<font key="font" metaFont="system" size="14"/>
489492
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
490493
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
@@ -498,6 +501,9 @@
498501
<constraint firstItem="FsS-ST-n7z" firstAttribute="centerX" secondItem="LkJ-ip-9UW" secondAttribute="centerX" id="sep-P2-mNN"/>
499502
</constraints>
500503
</view>
504+
<connections>
505+
<outlet property="descrField" destination="TmJ-lC-18u" id="4Jb-59-Dc9"/>
506+
</connections>
501507
</viewController>
502508
</objects>
503509
<point key="canvasLocation" x="914" y="230.5"/>

Installer/Config.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ class Config: Mappable {
1616
var icon: String?
1717
var script: String?
1818
var gpgKey: String?
19-
var title: l18n?
20-
var descr: l18n?
21-
var license: l18n?
19+
var title: [String : String]?
20+
var descr: [String : String]?
21+
var license: [String : String]?
2222
var downloadLinks: [String]?
2323

2424
required init?(map: Map) {

Installer/ContainerVC.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class ContainerVC: NSPageController, NSPageControllerDelegate {
2929
override func viewDidAppear() {
3030
super.viewDidAppear()
3131
Loader.shared.loadConfig()
32-
self.view.window?.title = (Loader.shared.config.title?.en)!
32+
self.view.window?.title = Language().getString(array: Loader.shared.config.title ?? [String : String]())
3333
}
3434

3535
override func scrollWheel(with event: NSEvent) {
@@ -40,7 +40,7 @@ class ContainerVC: NSPageController, NSPageControllerDelegate {
4040
print(identifier.rawValue)
4141
switch identifier.rawValue {
4242
case "one":
43-
return self.storyboard?.instantiateController(withIdentifier: NSStoryboard.SceneIdentifier(rawValue: "WelcomeVC")) as! NSViewController
43+
return self.storyboard?.instantiateController(withIdentifier: NSStoryboard.SceneIdentifier(rawValue: "FirstVC")) as! FirstVC
4444
case "two":
4545
return self.storyboard?.instantiateController(withIdentifier: NSStoryboard.SceneIdentifier(rawValue: "LicenseVC")) as! LicenseVC
4646
case "three":

Installer/FirstVC.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// FirstVC.swift
3+
// Installer
4+
//
5+
// Created by Mikhail Lutskiy on 21.08.2018.
6+
// Copyright © 2018 Mikhail Lutskii. All rights reserved.
7+
//
8+
9+
import Cocoa
10+
11+
class FirstVC: NSViewController {
12+
13+
@IBOutlet weak var descrField: NSTextField!
14+
override func viewDidLoad() {
15+
super.viewDidLoad()
16+
Loader.shared.loadConfig()
17+
self.descrField.stringValue = Language().getString(array: Loader.shared.config.descr ?? [String : String]())
18+
}
19+
20+
}

Installer/Language.swift

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//
2+
// LanguageString.swift
3+
// Installer
4+
//
5+
// Created by Mikhail Lutskiy on 21.08.2018.
6+
// Copyright © 2018 Mikhail Lutskii. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
class Language {
12+
13+
func getString(array: [String : String]) -> String {
14+
var lang = Locale.preferredLanguages[0]
15+
var (string, isFind) = foreach(array: array, langPrefix: lang)
16+
if isFind {
17+
return string
18+
} else {
19+
lang = lang.components(separatedBy: "-").first!
20+
(string, isFind) = foreach(array: array, langPrefix: lang)
21+
if isFind {
22+
return string
23+
} else {
24+
(string, isFind) = foreach(array: array, langPrefix: "en")
25+
if isFind {
26+
return string
27+
}
28+
}
29+
}
30+
return ""
31+
}
32+
33+
func foreach (array: [String : String], langPrefix: String) -> (String, Bool) {
34+
for element in array {
35+
if element.key == langPrefix {
36+
return (element.value, true)
37+
}
38+
}
39+
return ("", false)
40+
}
41+
}

Installer/LicenseVC.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class LicenseVC: NSViewController {
1919
super.viewDidLoad()
2020
let bundle = Bundle.main
2121
Loader.shared.loadConfig()
22-
let filePath = bundle.path(forResource: Loader.shared.config.license?.en, ofType: nil)
22+
let filePath = bundle.path(forResource: Language().getString(array: Loader.shared.config.license ?? [String : String]()), ofType: nil)
2323
licenseWebView.mainFrameURL = filePath
2424
}
2525

Installer/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"name": "Array.io",
44
"image": "./image.png",
55
"icon": "./icon.png",
6-
"title": {"en": "Install Array.io"},
6+
"title": {"en": "Install Array.io", "ru": "Установщик Array.io", "ru-RU": "Установшик Array.io ru"},
77
"description": {"en": "Array.io is the best software created by human ever"},
88
"licenseFile": {"en": "License.html"},
99
"script": "postinstall.js",
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)