Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the localization #537

Merged
merged 20 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions App/App_macOS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ struct Kiwix: App {
}.commands {
SidebarCommands()
CommandGroup(replacing: .importExport) {
OpenFileButton(context: .command) { Text("Open...") }
OpenFileButton(context: .command) { Text("Open...".localized) }
}
CommandGroup(replacing: .newItem) {
Button("New Tab") {
Button("New Tab".localized) {
guard let currentWindow = NSApp.keyWindow,
let controller = currentWindow.windowController else { return }
controller.newWindowForTab(nil)
Expand Down Expand Up @@ -91,11 +91,11 @@ struct RootView: View {
NavigationView {
List(selection: $navigation.currentItem) {
ForEach(primaryItems, id: \.self) { navigationItem in
Label(navigationItem.name, systemImage: navigationItem.icon)
Label(navigationItem.name.localized, systemImage: navigationItem.icon)
}
Section("Library") {
Section("Library".localized) {
ForEach(libraryItems, id: \.self) { navigationItem in
Label(navigationItem.name, systemImage: navigationItem.icon)
Label(navigationItem.name.localized, systemImage: navigationItem.icon)
}
}
}
Expand All @@ -106,7 +106,7 @@ struct RootView: View {
responder.tryToPerform(#selector(NSSplitViewController.toggleSidebar(_:)), with: nil)
} label: {
Image(systemName: "sidebar.leading")
}.help("Show sidebar")
}.help("Show sidebar".localized)
}
switch navigation.currentItem {
case .reading:
Expand Down
10 changes: 5 additions & 5 deletions App/SidebarViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class SidebarViewController: UICollectionViewController, NSFetchedResultsControl
},
menu: UIMenu(children: [
UIAction(
title: "Close This Tab",
title: "Close This Tab".localized,
image: UIImage(systemName: "xmark.square"),
attributes: .destructive
) { [unowned self] _ in
Expand All @@ -95,7 +95,7 @@ class SidebarViewController: UICollectionViewController, NSFetchedResultsControl
splitViewController.navigationViewModel.deleteTab(tabID: tabID)
},
UIAction(
title: "Close All Tabs",
title: "Close All Tabs".localized,
image: UIImage(systemName: "xmark.square.fill"),
attributes: .destructive
) { [unowned self] _ in
Expand Down Expand Up @@ -188,11 +188,11 @@ class SidebarViewController: UICollectionViewController, NSFetchedResultsControl
switch section {
case .tabs:
var config = UIListContentConfiguration.sidebarHeader()
config.text = "Tabs"
config.text = "Tabs".localized
headerView.contentConfiguration = config
case .library:
var config = UIListContentConfiguration.sidebarHeader()
config.text = "Library"
config.text = "Library".localized
headerView.contentConfiguration = config
default:
headerView.contentConfiguration = nil
Expand All @@ -203,7 +203,7 @@ class SidebarViewController: UICollectionViewController, NSFetchedResultsControl
guard let splitViewController = splitViewController as? SplitViewController,
let item = dataSource.itemIdentifier(for: indexPath),
case let .tab(tabID) = item else { return nil }
let action = UIContextualAction(style: .destructive, title: "Close") { _, _, _ in
let action = UIContextualAction(style: .destructive, title: "Close".localized) { _, _, _ in
splitViewController.navigationViewModel.deleteTab(tabID: tabID)
}
action.image = UIImage(systemName: "xmark")
Expand Down
2 changes: 1 addition & 1 deletion App/SplitViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class SplitViewController: UISplitViewController {
let controller = UIHostingController(rootView: Settings())
setViewController(UINavigationController(rootViewController: controller), for: .secondary)
default:
let controller = UIHostingController(rootView: Text("Not yet implemented"))
let controller = UIHostingController(rootView: Text("Not yet implemented".localized))
setViewController(UINavigationController(rootViewController: controller), for: .secondary)
}
}
Expand Down
33 changes: 30 additions & 3 deletions Kiwix.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
objects = {

/* Begin PBXBuildFile section */
8E4396462B02E455007F0BC4 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 8E4396492B02E455007F0BC4 /* Localizable.strings */; };
8E4396472B02E455007F0BC4 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 8E4396492B02E455007F0BC4 /* Localizable.strings */; };
8E43964C2B02E4C6007F0BC4 /* String+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E43964B2B02E4C6007F0BC4 /* String+Extension.swift */; };
8E43964D2B02E4C6007F0BC4 /* String+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E43964B2B02E4C6007F0BC4 /* String+Extension.swift */; };
97008ABD2974A5BF0076E60C /* OPDSParserTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97008ABC2974A5BF0076E60C /* OPDSParserTests.swift */; };
9709C0982A8E4C5700E4564C /* Commands.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9709C0972A8E4C5700E4564C /* Commands.swift */; };
97121EBE28849F0000371AEB /* ZimFileMissingIndicator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97121EBC28849F0000371AEB /* ZimFileMissingIndicator.swift */; };
Expand Down Expand Up @@ -124,6 +128,11 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
8E4396442B02E443007F0BC4 /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/Main.strings; sourceTree = "<group>"; };
8E4396452B02E443007F0BC4 /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/LaunchScreen.strings; sourceTree = "<group>"; };
8E4396482B02E455007F0BC4 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
8E43964A2B02E458007F0BC4 /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/Localizable.strings; sourceTree = "<group>"; };
8E43964B2B02E4C6007F0BC4 /* String+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+Extension.swift"; sourceTree = "<group>"; };
97008AB42974A5A70076E60C /* WikiMed.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = WikiMed.app; sourceTree = BUILT_PRODUCTS_DIR; };
97008ABA2974A5BF0076E60C /* Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
97008ABC2974A5BF0076E60C /* OPDSParserTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OPDSParserTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -293,6 +302,7 @@
9779A7E224567A5A00F6F6FF /* Log.swift */,
97B3BACD2736CE3500A23F49 /* URL.swift */,
9779A73A2456796B00F6F6FF /* WebKitHandler.swift */,
8E43964B2B02E4C6007F0BC4 /* String+Extension.swift */,
);
path = Utilities;
sourceTree = "<group>";
Expand Down Expand Up @@ -386,8 +396,8 @@
974E7EE22930201500BDF59C /* ZimFileService */ = {
isa = PBXGroup;
children = (
974E7EE32930201500BDF59C /* ZimFileService.mm */,
974E7EE42930201500BDF59C /* ZimFileService.h */,
974E7EE32930201500BDF59C /* ZimFileService.mm */,
974E7EE52930201500BDF59C /* ZimFileService.swift */,
);
path = ZimFileService;
Expand Down Expand Up @@ -549,6 +559,7 @@
97E94B22271EF250005B0295 /* Kiwix.entitlements */,
9779A5D02456796A00F6F6FF /* Kiwix-Bridging-Header.h */,
970885D0271339A300C5795C /* wikipedia_dark.css */,
8E4396492B02E455007F0BC4 /* Localizable.strings */,
);
path = Support;
sourceTree = "<group>";
Expand Down Expand Up @@ -649,6 +660,7 @@
knownRegions = (
en,
Base,
es,
);
mainGroup = 97A2AB7F1C1B80FF00052E74;
packageReferences = (
Expand Down Expand Up @@ -681,6 +693,7 @@
buildActionMask = 2147483647;
files = (
973A0DF72830929C00B41E71 /* Assets.xcassets in Resources */,
8E4396462B02E455007F0BC4 /* Localizable.strings in Resources */,
979D3A7C284159BF00E396B8 /* injection.js in Resources */,
97DE2BAD283B133700C63D9B /* wikipedia_dark.css in Resources */,
);
Expand All @@ -691,6 +704,7 @@
buildActionMask = 2147483647;
files = (
97B448A1210FBC2E0004B056 /* LaunchScreen.storyboard in Resources */,
8E4396472B02E455007F0BC4 /* Localizable.strings in Resources */,
97B4489E210FBC2E0004B056 /* Assets.xcassets in Resources */,
97B4489C210FBC2C0004B056 /* Main.storyboard in Resources */,
);
Expand Down Expand Up @@ -753,6 +767,7 @@
buildActionMask = 2147483647;
files = (
972DE4BB2814A5A4004FD9B9 /* Errors.swift in Sources */,
8E43964C2B02E4C6007F0BC4 /* String+Extension.swift in Sources */,
9790CA5A28A05EBB00D39FC6 /* ZimFilesCategories.swift in Sources */,
97486D08284A42B90096E4DD /* SearchResultRow.swift in Sources */,
9753D949285B55F100A626CC /* DefaultKeys.swift in Sources */,
Expand Down Expand Up @@ -836,6 +851,7 @@
buildActionMask = 2147483647;
files = (
97B44899210FBC2C0004B056 /* ViewController.swift in Sources */,
8E43964D2B02E4C6007F0BC4 /* String+Extension.swift in Sources */,
97B44897210FBC2C0004B056 /* AppDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -851,10 +867,20 @@
/* End PBXTargetDependency section */

/* Begin PBXVariantGroup section */
8E4396492B02E455007F0BC4 /* Localizable.strings */ = {
isa = PBXVariantGroup;
children = (
8E4396482B02E455007F0BC4 /* en */,
8E43964A2B02E458007F0BC4 /* es */,
);
name = Localizable.strings;
sourceTree = "<group>";
};
97B4489A210FBC2C0004B056 /* Main.storyboard */ = {
isa = PBXVariantGroup;
children = (
97B4489B210FBC2C0004B056 /* Base */,
8E4396442B02E443007F0BC4 /* es */,
);
name = Main.storyboard;
sourceTree = "<group>";
Expand All @@ -863,6 +889,7 @@
isa = PBXVariantGroup;
children = (
97B448A0210FBC2E0004B056 /* Base */,
8E4396452B02E443007F0BC4 /* es */,
);
name = LaunchScreen.storyboard;
sourceTree = "<group>";
Expand Down Expand Up @@ -943,7 +970,7 @@
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 119;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = L7HWM3SP3L;
DEVELOPMENT_TEAM = "";
"ENABLE_HARDENED_RUNTIME[sdk=macosx*]" = YES;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand Down Expand Up @@ -989,7 +1016,7 @@
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 119;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = L7HWM3SP3L;
DEVELOPMENT_TEAM = "";
"ENABLE_HARDENED_RUNTIME[sdk=macosx*]" = YES;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand Down
4 changes: 2 additions & 2 deletions Model/DownloadService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,10 @@ class DownloadService: NSObject, URLSessionDelegate, URLSessionTaskDelegate, URL
Database.shared.container.performBackgroundTask { context in
// configure notification content
let content = UNMutableNotificationContent()
content.title = "Download Completed"
content.title = "Download Completed".localized
content.sound = .default
if let zimFile = try? context.fetch(ZimFile.fetchRequest(fileID: zimFileID)).first {
content.body = "\(zimFile.name) has been downloaded successfully."
content.body = "%@ has been downloaded successfully.".localizedWithFormat(withArgs: zimFile.name)
}

// schedule notification
Expand Down
6 changes: 3 additions & 3 deletions Model/Entities/Errors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ public enum LibraryRefreshError: LocalizedError {
public var errorDescription: String? {
switch self {
case .retrieve(let description):
let prefix = NSLocalizedString("Error retrieving library data.", comment: "Library Refresh Error")
let prefix = "Error retrieving library data.".localized(withComment: "Library Refresh Error")
return [prefix, description].compactMap({ $0 }).joined(separator: " ")
case .parse:
return NSLocalizedString("Error parsing library data.", comment: "Library Refresh Error")
return "Error parsing library data.".localized(withComment: "Library Refresh Error")
case .process:
return NSLocalizedString("Error processing library data.", comment: "Library Refresh Error")
return "Error processing library data.".localized(withComment: "Library Refresh Error")
}
}
}
31 changes: 31 additions & 0 deletions Model/Utilities/String+Extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// String+Extension.swift
// Kiwix
//
// Created by tvision251 on 11/13/23.
// Copyright © 2023 Chris Li. All rights reserved.
//

import Foundation

extension String {

var localized: String {
return NSLocalizedString(self, tableName: nil, bundle: Bundle.main, value: "", comment: "")
}

func localized(withComment: String) -> String {
return NSLocalizedString(self, tableName: nil, bundle: Bundle.main, value: "", comment: withComment)
}

func localizedWithFormat(withArgs: CVarArg...) -> String {
let format = NSLocalizedString(self, tableName: nil, bundle: Bundle.main, value: "", comment: "")

switch withArgs.count {
case 1: return String.localizedStringWithFormat(format, withArgs[0])
case 2: return String.localizedStringWithFormat(format, withArgs[0], withArgs[1])
default: return String.localizedStringWithFormat(format, withArgs)
}
}

}
Loading
Loading