mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 19:44:05 +00:00
Localizations Setup (#6)
* Move assets into ElementX folder * Add first version of localizer script * Add generated strings & tests & fallback mechanism * Rename strings file to Localizable * Rename Assets to Resources * Calculate preferred languages only when needed, remove share extension check * Add comments in the localizer script * Add GH workflow to push issues to the [ElementX board](https://github.com/orgs/vector-im/projects/43) * Closes #16 - Add license file * New version of localizer script, handle pluralization * Move assets into ElementX folder * Add first version of localizer script * Add generated strings & tests & fallback mechanism * Rename strings file to Localizable * Rename Assets to Resources * Calculate preferred languages only when needed, remove share extension check * Add comments in the localizer script * New version of localizer script, handle pluralization * Revert login button text * Add multiple dialect pluralization, fix string formatting Co-authored-by: manuroe <manu@matrix.org> Co-authored-by: Stefan Ceriu <stefanc@matrix.org>
This commit is contained in:
@@ -11,6 +11,15 @@ import UIKit
|
||||
class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
|
||||
private var appCoordinator: AppCoordinator!
|
||||
|
||||
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
|
||||
|
||||
// fixme: Use `Bundle.elementLanguage = ".."` when we have the functionality
|
||||
// use `en` as fallback language
|
||||
Bundle.elementFallbackLanguage = "en"
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
|
||||
if isRunningUnitTests {
|
||||
|
||||
@@ -26,7 +26,7 @@ internal enum Asset {
|
||||
internal static let elementGreen = ColorAsset(name: "Colors/ElementGreen")
|
||||
}
|
||||
internal enum Images {
|
||||
internal static let appLogo = ImageAsset(name: "Images/appLogo")
|
||||
internal static let appLogo = ImageAsset(name: "Images/app-logo")
|
||||
internal static let timelineComposerSendMessage = ImageAsset(name: "Images/timelineComposerSendMessage")
|
||||
internal static let timelineScrollToBottom = ImageAsset(name: "Images/timelineScrollToBottom")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
// swiftlint:disable all
|
||||
// Generated using SwiftGen — https://github.com/SwiftGen/SwiftGen
|
||||
|
||||
import Foundation
|
||||
|
||||
// swiftlint:disable superfluous_disable_command file_length implicit_return
|
||||
|
||||
// MARK: - Strings
|
||||
|
||||
// swiftlint:disable explicit_type_interface function_parameter_count identifier_name line_length
|
||||
// swiftlint:disable nesting type_body_length type_name vertical_whitespace_opening_braces
|
||||
extension ElementL10n {
|
||||
/// Untranslated
|
||||
public static let untranslated = ElementL10n.tr("Untranslated", "untranslated")
|
||||
/// Plural format key: "%#@VARIABLE@"
|
||||
public static func untranslatedPlural(_ p1: Int) -> String {
|
||||
return ElementL10n.tr("Untranslated", "untranslated_plural", p1)
|
||||
}
|
||||
}
|
||||
// swiftlint:enable explicit_type_interface function_parameter_count identifier_name line_length
|
||||
// swiftlint:enable nesting type_body_length type_name vertical_whitespace_opening_braces
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,64 @@
|
||||
//
|
||||
// Bundle.swift
|
||||
// ElementX
|
||||
//
|
||||
// Created by Ismail on 15.04.2022.
|
||||
// Copyright © 2022 element.io. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public extension Bundle {
|
||||
|
||||
/// Returns the real app bundle.
|
||||
/// Can also be used in app extensions.
|
||||
static let app: Bundle = {
|
||||
let bundle = main
|
||||
if bundle.bundleURL.pathExtension == "appex" {
|
||||
// Peel off two directory levels - MY_APP.app/PlugIns/MY_APP_EXTENSION.appex
|
||||
let url = bundle.bundleURL.deletingLastPathComponent().deletingLastPathComponent()
|
||||
if let otherBundle = Bundle(url: url) {
|
||||
return otherBundle
|
||||
}
|
||||
}
|
||||
return bundle
|
||||
}()
|
||||
|
||||
/// Get an lproj language bundle from the main app bundle.
|
||||
/// - Parameter language: The language to try to load.
|
||||
/// - Returns: The lproj bundle if found otherwise nil.
|
||||
@objc static func lprojBundle(for language: String) -> Bundle? {
|
||||
guard let lprojURL = Bundle.app.url(forResource: language, withExtension: "lproj") else { return nil }
|
||||
return Bundle(url: lprojURL)
|
||||
}
|
||||
|
||||
/// Preferred app language for translations. Takes the highest priority in translations. The priority list for translations:
|
||||
/// - `Bundle.elementLanguage`
|
||||
/// - `Locale.preferredLanguages`
|
||||
/// - `Bundle.elementFallbackLanguage`
|
||||
static var elementLanguage: String? {
|
||||
didSet {
|
||||
preferredLanguages = calculatePreferredLanguages()
|
||||
}
|
||||
}
|
||||
|
||||
/// Preferred fallback language for translations. Only used for strings not translated neither to `elementLanguage` nor to one of the user's preferred languages.
|
||||
static var elementFallbackLanguage: String? {
|
||||
didSet {
|
||||
preferredLanguages = calculatePreferredLanguages()
|
||||
}
|
||||
}
|
||||
|
||||
/// Preferred languages in the priority order.
|
||||
static private(set) var preferredLanguages: [String] = calculatePreferredLanguages()
|
||||
|
||||
private static func calculatePreferredLanguages() -> [String] {
|
||||
var set = Set<String>()
|
||||
return ([Bundle.elementLanguage] +
|
||||
Locale.preferredLanguages +
|
||||
[Bundle.elementFallbackLanguage])
|
||||
.compactMap { $0 }
|
||||
.filter { set.insert($0).inserted }
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user