Skip to content

Commit f696558

Browse files
Localisation and internationalisation (#10)
* Add French, Spanish and German translations * Clear defaults preferences before running UI tests, and improve preference restoration afterwards * Make window resizable and have minimum size * Add undo and redo capability With thanks to Alex Nicol, Ted Byrne and Andreas Scheriau for reviewing and updating the French, Spanish and German translations! Co-authored-by: Alexandre Nicol <nicol.alexandre1@gmail.com>
1 parent 4462c39 commit f696558

File tree

18 files changed

+895
-589
lines changed

18 files changed

+895
-589
lines changed

Big Sur Font Smoothing Toggler.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Big Sur Font Smoothing Toggler/Base.lproj/MainMenu.xib

Lines changed: 7 additions & 541 deletions
Large diffs are not rendered by default.

Big Sur Font Smoothing Toggler/MainWindowController.xib renamed to Big Sur Font Smoothing Toggler/Base.lproj/MainWindowController.xib

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
77
</dependencies>
88
<objects>
9-
<customObject id="-2" userLabel="File's Owner" customClass="MainWindowController" customModule="Big_Sur_Font_Smoothing_Toggler" customModuleProvider="target">
9+
<customObject id="-2" userLabel="File's Owner" customClass="MainWindowController" customModule="Font_Smoothing_Adjuster" customModuleProvider="target">
1010
<connections>
1111
<outlet property="disabledFontSmoothingRadioButton" destination="yAH-xX-66R" id="B7B-Yy-ouv"/>
1212
<outlet property="heavyFontSmoothingRadioButton" destination="bnW-ud-KsD" id="mBs-QY-5dx"/>
@@ -18,12 +18,12 @@
1818
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
1919
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
2020
<window title="Font Smoothing Adjuster" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" animationBehavior="default" titlebarAppearsTransparent="YES" id="F0z-JX-Cv5">
21-
<windowStyleMask key="styleMask" titled="YES" closable="YES"/>
21+
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
2222
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
2323
<rect key="contentRect" x="196" y="240" width="417" height="203"/>
2424
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="875"/>
2525
<view key="contentView" id="se5-gp-TjO">
26-
<rect key="frame" x="0.0" y="0.0" width="417" height="203"/>
26+
<rect key="frame" x="0.0" y="0.0" width="417" height="204"/>
2727
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
2828
<subviews>
2929
<stackView distribution="fill" orientation="horizontal" alignment="top" spacing="6" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="xCM-7O-UeI">
@@ -106,8 +106,12 @@
106106
</stackView>
107107
</subviews>
108108
<constraints>
109+
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="xCM-7O-UeI" secondAttribute="trailing" constant="92" id="0Jz-50-Mad"/>
110+
<constraint firstItem="xCM-7O-UeI" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="se5-gp-TjO" secondAttribute="leading" constant="92" id="9kz-Eu-azC"/>
109111
<constraint firstItem="xCM-7O-UeI" firstAttribute="centerY" secondItem="se5-gp-TjO" secondAttribute="centerY" id="RAD-Wn-FKq"/>
110112
<constraint firstItem="xCM-7O-UeI" firstAttribute="centerX" secondItem="se5-gp-TjO" secondAttribute="centerX" id="hWk-9A-986"/>
113+
<constraint firstItem="xCM-7O-UeI" firstAttribute="top" relation="greaterThanOrEqual" secondItem="se5-gp-TjO" secondAttribute="top" constant="61" id="lqp-IG-hK7"/>
114+
<constraint firstAttribute="bottom" relation="greaterThanOrEqual" secondItem="xCM-7O-UeI" secondAttribute="bottom" constant="61" id="uty-4G-18H"/>
111115
</constraints>
112116
</view>
113117
<connections>

Big Sur Font Smoothing Toggler/MainWindowController.swift

Lines changed: 54 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ class MainWindowController: NSWindowController {
1515
@IBOutlet weak var mediumFontSmoothingRadioButton: NSButton!
1616
@IBOutlet weak var heavyFontSmoothingRadioButton: NSButton!
1717

18-
let fontSmoothingDefaults = FontSmoothingDefaults()
18+
private let fontSmoothingDefaults = FontSmoothingDefaults()
19+
private typealias FontSmoothingOption = FontSmoothingDefaults.FontSmoothingOptions
1920

2021
override var windowNibName: NSNib.Name? {
2122
return NSNib.Name.mainWindowController
@@ -27,48 +28,53 @@ class MainWindowController: NSWindowController {
2728
setRadioButtonsToCurrentDefaultsState()
2829
}
2930

30-
func setRadioButtonsToCurrentDefaultsState() {
31+
private func setRadioButtonsToCurrentDefaultsState() {
3132
do {
32-
let fontSmoothingState = try fontSmoothingDefaults.getFontSmoothingState()
33-
switch fontSmoothingState {
34-
case .noFontSmoothing:
35-
disabledFontSmoothingRadioButton.state = .on
36-
case .lightFontSmoothing:
37-
lightFontSmoothingRadioButton.state = .on
38-
case .mediumFontSmoothing:
39-
mediumFontSmoothingRadioButton.state = .on
40-
case .heavyFontSmoothing:
41-
heavyFontSmoothingRadioButton.state = .on
42-
}
33+
let currentFontSmoothingState = try fontSmoothingDefaults.getFontSmoothingState()
34+
updateUIWithState(fontSmoothingState: currentFontSmoothingState)
4335
} catch {
4436
os_log(.error, "Error getting font smoothing defaults: %s", error.localizedDescription)
4537
Analytics.trackEvent("Error getting font smoothing defaults: \(error.localizedDescription)")
4638
presentErrorSheet(error)
4739
}
48-
40+
}
41+
42+
private func updateUIWithState(fontSmoothingState: FontSmoothingOption) {
43+
switch fontSmoothingState {
44+
case .noFontSmoothing:
45+
disabledFontSmoothingRadioButton.state = .on
46+
case .lightFontSmoothing:
47+
lightFontSmoothingRadioButton.state = .on
48+
case .mediumFontSmoothing:
49+
mediumFontSmoothingRadioButton.state = .on
50+
case .heavyFontSmoothing:
51+
heavyFontSmoothingRadioButton.state = .on
52+
}
4953
}
5054

5155
@IBAction func toggleFontSmoothing(_ sender: NSButton) {
52-
let fontSmoothingOption: FontSmoothingDefaults.FontSmoothingOptions
56+
let newFontSmoothingState: FontSmoothingOption
5357
switch sender {
5458
case disabledFontSmoothingRadioButton:
55-
fontSmoothingOption = .noFontSmoothing
59+
newFontSmoothingState = .noFontSmoothing
5660
case lightFontSmoothingRadioButton:
57-
fontSmoothingOption = .lightFontSmoothing
61+
newFontSmoothingState = .lightFontSmoothing
5862
case mediumFontSmoothingRadioButton:
59-
fontSmoothingOption = .mediumFontSmoothing
63+
newFontSmoothingState = .mediumFontSmoothing
6064
case heavyFontSmoothingRadioButton:
61-
fontSmoothingOption = .heavyFontSmoothing
65+
newFontSmoothingState = .heavyFontSmoothing
6266
default:
6367
Analytics.trackEvent("Unsupported font smoothing radio button option selected")
6468
fatalError("Unsupported font smoothing radio button option selected.")
6569
}
6670
do {
67-
let fontSmoothingState = try fontSmoothingDefaults.getFontSmoothingState()
68-
guard fontSmoothingOption != fontSmoothingState else {
71+
let currentFontSmoothingState = try fontSmoothingDefaults.getFontSmoothingState()
72+
guard newFontSmoothingState != currentFontSmoothingState else {
6973
return
7074
}
71-
try fontSmoothingDefaults.setFontSmoothing(option: fontSmoothingOption)
75+
76+
try updateFontSmoothingPreferences(newState: newFontSmoothingState, oldState: currentFontSmoothingState)
77+
7278
Analytics.trackEvent("Font smoothing preferences updated")
7379
presentSuccessSheet()
7480
} catch {
@@ -80,13 +86,31 @@ class MainWindowController: NSWindowController {
8086
}
8187
}
8288

83-
func presentSuccessSheet() {
89+
private func updateFontSmoothingPreferences(newState: FontSmoothingOption, oldState: FontSmoothingOption) throws {
90+
try fontSmoothingDefaults.setFontSmoothing(option: newState)
91+
setRadioButtonsToCurrentDefaultsState()
92+
window?.undoManager?.registerUndo(withTarget: self, handler: { target in
93+
try? target.undoUpdateFontSmoothingPreferences(oldState: oldState, newState: newState)
94+
target.setRadioButtonsToCurrentDefaultsState()
95+
})
96+
}
97+
98+
private func undoUpdateFontSmoothingPreferences(oldState: FontSmoothingOption, newState: FontSmoothingOption) throws {
99+
try fontSmoothingDefaults.setFontSmoothing(option: oldState)
100+
setRadioButtonsToCurrentDefaultsState()
101+
window?.undoManager?.registerUndo(withTarget: self, handler: { target in
102+
try? target.updateFontSmoothingPreferences(newState: newState, oldState: oldState)
103+
target.setRadioButtonsToCurrentDefaultsState()
104+
})
105+
}
106+
107+
private func presentSuccessSheet() {
84108
guard let window = self.window else { return }
85109
let alert = NSAlert()
86-
alert.messageText = "Font smoothing preferences successfully updated"
87-
alert.informativeText = "Log off or restart your computer for the changes to take effect."
88-
alert.addButton(withTitle: "Log out now")
89-
alert.addButton(withTitle: "Log out later")
110+
alert.messageText = NSLocalizedString("Font smoothing preferences successfully updated", comment: "Title for preferences update success sheet modal")
111+
alert.informativeText = NSLocalizedString("Log out or restart your Mac for the changes to take effect.", comment: "Informative text for preferences update success sheet modal")
112+
alert.addButton(withTitle: NSLocalizedString("Log out now", comment: "Log out now button text"))
113+
alert.addButton(withTitle: NSLocalizedString("Log out later", comment: "Log out later button text"))
90114
alert.alertStyle = .informational
91115
alert.beginSheetModal(for: window) { (response) in
92116
switch response {
@@ -116,11 +140,11 @@ class MainWindowController: NSWindowController {
116140
}
117141
}
118142

119-
func presentErrorSheet(_ error: Error) {
143+
private func presentErrorSheet(_ error: Error) {
120144
guard let window = self.window else { return }
121145
let alert = NSAlert(error: error)
122-
alert.messageText = "The operation couldn't be completed"
123-
alert.informativeText = "An unexpected error occurred. Please view the logs in the Console app for details."
146+
alert.messageText = NSLocalizedString("The operation couldn't be completed", comment: "Title for error sheet")
147+
alert.informativeText = NSLocalizedString("An unexpected error occurred. Please view the logs in the Console app for details.", comment: "Informative text for error sheet")
124148
alert.alertStyle = .critical
125149
alert.beginSheetModal(for: window)
126150
}
1.78 KB
Binary file not shown.
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
2+
/* Class = "NSMenuItem"; title = "Font Smoothing Adjuster"; ObjectID = "1Xt-HY-uBw"; */
3+
"1Xt-HY-uBw.title" = "Font Smoothing Adjuster";
4+
5+
/* Class = "NSMenuItem"; title = "Enter Full Screen"; ObjectID = "4J7-dP-txa"; */
6+
"4J7-dP-txa.title" = "Vollbildmodus";
7+
8+
/* Class = "NSMenuItem"; title = "Quit Font Smoothing Adjuster"; ObjectID = "4sb-4s-VLi"; */
9+
"4sb-4s-VLi.title" = "Font Smoothing Adjuster beenden";
10+
11+
/* Class = "NSMenuItem"; title = "Edit"; ObjectID = "5QF-Oa-p0T"; */
12+
"5QF-Oa-p0T.title" = "Bearbeiten";
13+
14+
/* Class = "NSMenuItem"; title = "About Font Smoothing Adjuster"; ObjectID = "5kV-Vb-QxS"; */
15+
"5kV-Vb-QxS.title" = "Über Font Smoothing Adjuster";
16+
17+
/* Class = "NSMenuItem"; title = "Redo"; ObjectID = "6dh-zS-Vam"; */
18+
"6dh-zS-Vam.title" = "Wiederholen";
19+
20+
/* Class = "NSMenu"; title = "Main Menu"; ObjectID = "AYu-sK-qS6"; */
21+
"AYu-sK-qS6.title" = "Hauptmenü";
22+
23+
/* Class = "NSMenuItem"; title = "Preferences…"; ObjectID = "BOF-NM-1cW"; */
24+
"BOF-NM-1cW.title" = "Einstellungen…";
25+
26+
/* Class = "NSMenuItem"; title = "Close"; ObjectID = "DVo-aG-piG"; */
27+
"DVo-aG-piG.title" = "Schließen";
28+
29+
/* Class = "NSMenu"; title = "Help"; ObjectID = "F2S-fz-NVQ"; */
30+
"F2S-fz-NVQ.title" = "Hilfe";
31+
32+
/* Class = "NSMenuItem"; title = "Font Smoothing Adjuster Help"; ObjectID = "FKE-Sm-Kum"; */
33+
"FKE-Sm-Kum.title" = "Font Smoothing Adjuster-Hilfe";
34+
35+
/* Class = "NSMenuItem"; title = "View"; ObjectID = "H8h-7b-M4v"; */
36+
"H8h-7b-M4v.title" = "Darstellung";
37+
38+
/* Class = "NSMenu"; title = "View"; ObjectID = "HyV-fh-RgO"; */
39+
"HyV-fh-RgO.title" = "Darstellung";
40+
41+
/* Class = "NSMenuItem"; title = "Show All"; ObjectID = "Kd2-mp-pUS"; */
42+
"Kd2-mp-pUS.title" = "Alle einblenden";
43+
44+
/* Class = "NSMenuItem"; title = "Bring All to Front"; ObjectID = "LE2-aR-0XJ"; */
45+
"LE2-aR-0XJ.title" = "Alle nach vorne bringen";
46+
47+
/* Class = "NSMenuItem"; title = "Services"; ObjectID = "NMo-om-nkz"; */
48+
"NMo-om-nkz.title" = "Dienste";
49+
50+
/* Class = "NSMenuItem"; title = "Minimize"; ObjectID = "OY7-WF-poV"; */
51+
"OY7-WF-poV.title" = "Im Dock ablegen";
52+
53+
/* Class = "NSMenuItem"; title = "Hide Font Smoothing Adjuster"; ObjectID = "Olw-nP-bQN"; */
54+
"Olw-nP-bQN.title" = "Font Smoothing Adjuster ausblenden";
55+
56+
/* Class = "NSMenuItem"; title = "Check For Updates..."; ObjectID = "Pqk-XC-P99"; */
57+
"Pqk-XC-P99.title" = "Nach Updates suchen...";
58+
59+
/* Class = "NSMenuItem"; title = "Zoom"; ObjectID = "R4o-n2-Eq4"; */
60+
"R4o-n2-Eq4.title" = "Zoomen";
61+
62+
/* Class = "NSMenu"; title = "Window"; ObjectID = "Td7-aD-5lo"; */
63+
"Td7-aD-5lo.title" = "Fenster";
64+
65+
/* Class = "NSMenuItem"; title = "Hide Others"; ObjectID = "Vdr-fp-XzO"; */
66+
"Vdr-fp-XzO.title" = "Andere ausblenden";
67+
68+
/* Class = "NSMenu"; title = "Edit"; ObjectID = "W48-6f-4Dl"; */
69+
"W48-6f-4Dl.title" = "Bearbeiten";
70+
71+
/* Class = "NSMenuItem"; title = "Window"; ObjectID = "aUF-d1-5bR"; */
72+
"aUF-d1-5bR.title" = "Fenster";
73+
74+
/* Class = "NSMenu"; title = "File"; ObjectID = "bib-Uj-vzu"; */
75+
"bib-Uj-vzu.title" = "Ablage";
76+
77+
/* Class = "NSMenuItem"; title = "File"; ObjectID = "dMs-cI-mzQ"; */
78+
"dMs-cI-mzQ.title" = "Ablage";
79+
80+
/* Class = "NSMenuItem"; title = "Undo"; ObjectID = "dRJ-4n-Yzg"; */
81+
"dRJ-4n-Yzg.title" = "Widerrufen";
82+
83+
/* Class = "NSMenu"; title = "Services"; ObjectID = "hz9-B4-Xy5"; */
84+
"hz9-B4-Xy5.title" = "Dienste";
85+
86+
/* Class = "NSMenu"; title = "Font Smoothing Adjuster"; ObjectID = "uQy-DD-JDr"; */
87+
"uQy-DD-JDr.title" = "Font Smoothing Adjuster";
88+
89+
/* Class = "NSMenuItem"; title = "Help"; ObjectID = "wpr-3q-Mcd"; */
90+
"wpr-3q-Mcd.title" = "Hilfe";
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
/* Class = "NSTextFieldCell"; title = "Font smoothing:"; ObjectID = "3bW-X9-caa"; */
3+
"3bW-X9-caa.title" = "Schriftglättung:";
4+
5+
/* Class = "NSWindow"; title = "Font Smoothing Adjuster"; ObjectID = "F0z-JX-Cv5"; */
6+
"F0z-JX-Cv5.title" = "Font Smoothing Adjuster";
7+
8+
/* Class = "NSButtonCell"; title = "Light"; ObjectID = "Qbv-If-yJ0"; */
9+
"Qbv-If-yJ0.title" = "Dünn";
10+
11+
/* Class = "NSButtonCell"; title = "Medium (default)"; ObjectID = "Uan-kw-Wxq"; */
12+
"Uan-kw-Wxq.title" = "Mittel (standard)";
13+
14+
/* Class = "NSButtonCell"; title = "Heavy"; ObjectID = "cd3-89-pg3"; */
15+
"cd3-89-pg3.title" = "Fett";
16+
17+
/* Class = "NSButtonCell"; title = "Disabled"; ObjectID = "ym3-OR-J9l"; */
18+
"ym3-OR-J9l.title" = "Deaktiviert";

0 commit comments

Comments
 (0)