Fix localization issues, add tests, import translations, and add zh-CN and zh-TW
Closes: #689
This commit is contained in:
19
damus/Util/LocalizationUtil.swift
Normal file
19
damus/Util/LocalizationUtil.swift
Normal file
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// LocalizationUtil.swift
|
||||
// damus
|
||||
//
|
||||
// Created by Terry Yiu on 2/24/23.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
func bundleForLocale(locale: Locale) -> Bundle {
|
||||
let path = Bundle.main.path(forResource: locale.identifier, ofType: "lproj")
|
||||
return path != nil ? (Bundle(path: path!) ?? Bundle.main) : Bundle.main
|
||||
}
|
||||
|
||||
func formatInt(_ int: Int) -> String {
|
||||
let numberFormatter = NumberFormatter()
|
||||
numberFormatter.numberStyle = .decimal
|
||||
return numberFormatter.string(from: NSNumber(integerLiteral: int)) ?? "\(int)"
|
||||
}
|
||||
@@ -50,5 +50,6 @@ public func time_ago_since(_ date: Date, _ calendar: Calendar = Calendar.current
|
||||
return formatter.string(from: DateComponents(calendar: calendar, second: second))!
|
||||
}
|
||||
|
||||
return NSLocalizedString("now", comment: "String indicating that a given timestamp just occurred")
|
||||
let bundle = bundleForLocale(locale: calendar.locale ?? Locale.current)
|
||||
return NSLocalizedString("now", bundle: bundle, comment: "String indicating that a given timestamp just occurred")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user