Skip to content

Commit 42a29b2

Browse files
authored
Merge pull request #1089 from kiwix/safe-translations-applied
Safe translations applied
2 parents d2cda4f + e39238a commit 42a29b2

File tree

97 files changed

+612
-459
lines changed

Some content is hidden

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

97 files changed

+612
-459
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ jobs:
3333
# /!\ important: this checks out code from the HEAD of the PR instead of the main branch (for pull_request_target)
3434
ref: ${{ github.event.pull_request.head.sha || github.ref }}
3535

36+
- name: Validate localizations
37+
run: python localizations.py validate
38+
3639
- name: Add Apple Store Key
3740
run: echo "${{ secrets.APPLE_STORE_AUTH_KEY }}" | base64 --decode -o ${{ env.APPLE_STORE_AUTH_KEY_PATH}}
3841

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,7 @@ Brewfile.lock.json
8181

8282
# this is CI specific
8383
Brewfile_CI
84-
Brewfile_CI.lock.json
84+
Brewfile_CI.lock.json
85+
86+
# Generated localization swift file:
87+
Support/LocalString.swift

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ default_install_hook_types: [post-merge, post-checkout, post-rewrite]
33
repos:
44
- repo: local
55
hooks:
6+
- id: generate_localizations
7+
name: "Generate localization swift file"
8+
entry: python localizations.py generate
9+
language: python
10+
always_run: true
11+
stages: [post-checkout, post-merge, post-rewrite]
612
- id: xcodegen
713
name: Generate project files for Xcode
814
description: "Generate project file for Xcode"

.swiftlint.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
disabled_rules:
22
- trailing_whitespace
33
included:
4-
- Views/Settings/
4+
- Views/Settings/
5+
excluded:
6+
- Support/LocalString.swift

App/App_macOS.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ struct Kiwix: App {
5252
}.commands {
5353
SidebarCommands()
5454
CommandGroup(replacing: .importExport) {
55-
OpenFileButton(context: .command) { Text("app_macos_commands.open_file".localized) }
55+
OpenFileButton(context: .command) { Text(LocalString.app_macos_commands_open_file) }
5656
}
5757
CommandGroup(replacing: .newItem) {
58-
Button("app_macos_commands.new".localized) {
58+
Button(LocalString.app_macos_commands_new) {
5959
guard let currentWindow = NSApp.keyWindow,
6060
let controller = currentWindow.windowController else { return }
6161
controller.newWindowForTab(nil)
@@ -85,7 +85,7 @@ struct Kiwix: App {
8585
}
8686
.frame(width: 550, height: 400)
8787
}
88-
Window("payment.donate.title".localized, id: "donation") {
88+
Window(LocalString.payment_donate_title, id: "donation") {
8989
Group {
9090
if let selectedAmount {
9191
PaymentSummary(selectedAmount: selectedAmount, onComplete: {
@@ -187,7 +187,7 @@ struct RootView: View {
187187
Label(navigationItem.name, systemImage: navigationItem.icon)
188188
}
189189
if FeatureFlags.hasLibrary {
190-
Section("app_macos_navigation.button.library".localized) {
190+
Section(LocalString.app_macos_navigation_button_library) {
191191
ForEach(libraryItems, id: \.self) { navigationItem in
192192
Label(navigationItem.name, systemImage: navigationItem.icon)
193193
}

App/CompactViewController.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ final class CompactViewController: UIHostingController<AnyView>, UISearchControl
8484
searchController.delegate = self
8585
searchController.hidesNavigationBarDuringPresentation = false
8686
searchController.showsSearchResultsController = true
87-
searchController.searchBar.searchTextField.placeholder = "common.search".localized
87+
searchController.searchBar.searchTextField.placeholder = LocalString.common_search
8888

8989
searchTextObserver = searchViewModel.$searchText.sink { [weak self] searchText in
9090
guard self?.searchController.searchBar.text != searchText else { return }
@@ -107,7 +107,7 @@ final class CompactViewController: UIHostingController<AnyView>, UISearchControl
107107
trailingNavItemGroups = navigationItem.trailingItemGroups
108108
navigationItem.setRightBarButton(
109109
UIBarButtonItem(
110-
title: "common.button.cancel".localized,
110+
title: LocalString.common_button_cancel,
111111
style: .done,
112112
target: self,
113113
action: #selector(onSearchCancelled)
@@ -185,14 +185,14 @@ private struct CompactView: View {
185185
Button {
186186
presentedSheet = .library
187187
} label: {
188-
Label("common.tab.menu.library".localized, systemImage: "folder")
188+
Label(LocalString.common_tab_menu_library, systemImage: "folder")
189189
}
190190
Spacer()
191191
}
192192
Button {
193193
presentedSheet = .settings
194194
} label: {
195-
Label("common.tab.menu.settings".localized, systemImage: "gear")
195+
Label(LocalString.common_tab_menu_settings, systemImage: "gear")
196196
}
197197
Spacer()
198198
}
@@ -209,7 +209,7 @@ private struct CompactView: View {
209209
Button {
210210
self.presentedSheet = nil
211211
} label: {
212-
Text("common.button.done".localized).fontWeight(.semibold)
212+
Text(LocalString.common_button_done).fontWeight(.semibold)
213213
}
214214
}
215215
}
@@ -285,7 +285,7 @@ private struct Content<LaunchModel>: View where LaunchModel: LaunchProtocol {
285285
}
286286
.toolbar {
287287
ToolbarItemGroup(placement: .primaryAction) {
288-
Button("article_shortcut.random.button.title.ios".localized,
288+
Button(LocalString.article_shortcut_random_button_title_ios,
289289
systemImage: "die.face.5",
290290
action: { browser.loadRandomArticle() })
291291
.disabled(zimFiles.isEmpty)

App/SidebarViewController.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class SidebarViewController: UICollectionViewController, NSFetchedResultsControl
105105
},
106106
menu: UIMenu(children: [
107107
UIAction(
108-
title: "sidebar_view.navigation.button.close".localized,
108+
title: LocalString.sidebar_view_navigation_button_close,
109109
image: UIImage(systemName: "xmark.square"),
110110
attributes: .destructive
111111
) { [unowned self] _ in
@@ -114,7 +114,7 @@ class SidebarViewController: UICollectionViewController, NSFetchedResultsControl
114114
navigationViewModel.deleteTab(tabID: tabID)
115115
},
116116
UIAction(
117-
title: "sidebar_view.navigation.button.close_all".localized,
117+
title: LocalString.sidebar_view_navigation_button_close_all,
118118
image: UIImage(systemName: "xmark.square.fill"),
119119
attributes: .destructive
120120
) { [unowned self] _ in
@@ -196,7 +196,7 @@ class SidebarViewController: UICollectionViewController, NSFetchedResultsControl
196196
if case let .tab(objectID) = item,
197197
let tab = try? Database.shared.viewContext.existingObject(with: objectID) as? Tab {
198198
var config = cell.defaultContentConfiguration()
199-
config.text = tab.title ?? "common.tab.menu.new_tab".localized
199+
config.text = tab.title ?? LocalString.common_tab_menu_new_tab
200200
if let zimFile = tab.zimFile, let category = Category(rawValue: zimFile.category) {
201201
config.textProperties.numberOfLines = 1
202202
if let imgData = zimFile.faviconData {
@@ -224,11 +224,11 @@ class SidebarViewController: UICollectionViewController, NSFetchedResultsControl
224224
switch section {
225225
case .tabs:
226226
var config = UIListContentConfiguration.sidebarHeader()
227-
config.text = "common.tab.navigation.title".localized
227+
config.text = LocalString.common_tab_navigation_title
228228
headerView.contentConfiguration = config
229229
case .library:
230230
var config = UIListContentConfiguration.sidebarHeader()
231-
config.text = "common.tab.menu.library".localized
231+
config.text = LocalString.common_tab_menu_library
232232
headerView.contentConfiguration = config
233233
default:
234234
headerView.contentConfiguration = nil
@@ -239,7 +239,7 @@ class SidebarViewController: UICollectionViewController, NSFetchedResultsControl
239239
guard let navigationViewModel,
240240
let item = dataSource.itemIdentifier(for: indexPath),
241241
case let .tab(tabID) = item else { return nil }
242-
let title = "sidebar_view.navigation.button.close".localized
242+
let title = LocalString.sidebar_view_navigation_button_close
243243
let action = UIContextualAction(style: .destructive,
244244
title: title) { [weak navigationViewModel] _, _, _ in
245245
navigationViewModel?.deleteTab(tabID: tabID)

Brewfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ at_exit do
99
system "cp Support/CoreKiwix.modulemap CoreKiwix.xcframework/ios-arm64/Headers/module.modulemap"
1010
system "cp Support/CoreKiwix.modulemap CoreKiwix.xcframework/ios-arm64_x86_64-simulator/Headers/module.modulemap"
1111
system "cp Support/CoreKiwix.modulemap CoreKiwix.xcframework/macos-arm64_x86_64/Headers/module.modulemap"
12+
system "python localizations.py generate"
1213
system "xcodegen"
1314
end

Model/Brand.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ enum Brand {
4949
static let loadingLogoImage: String = "welcomeLogo"
5050
static var loadingLogoSize: CGSize = ImageInfo.sizeOf(imageName: loadingLogoImage)!
5151

52-
static let aboutText: String = Config.value(for: .aboutText) ?? "settings.about.description".localized
52+
static let aboutText: String = Config.value(for: .aboutText) ?? LocalString.settings_about_description
5353
static let aboutWebsite: String = Config.value(for: .aboutWebsite) ?? "https://www.kiwix.org"
5454
// currently only used under the Kiwix brand
5555
// if this is set to true in Support/Info.plist the support/donation button is hidden (for macOS FTP)

Model/DownloadService.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,10 @@ final class DownloadService: NSObject, URLSessionDelegate, URLSessionTaskDelegat
254254
Database.shared.performBackgroundTask { context in
255255
// configure notification content
256256
let content = UNMutableNotificationContent()
257-
content.title = "download_service.complete.title".localized
257+
content.title = LocalString.download_service_complete_title
258258
content.sound = .default
259259
if let zimFile = try? context.fetch(ZimFile.fetchRequest(fileID: zimFileID)).first {
260-
content.body = "download_service.complete.description".localizedWithFormat(withArgs: zimFile.name)
260+
content.body = LocalString.download_service_complete_description(withArgs: zimFile.name)
261261
}
262262

263263
// schedule notification

0 commit comments

Comments
 (0)