Skip to content

Commit

Permalink
[Bug] IOS Flutter SDK- Translation: English is not translated in the …
Browse files Browse the repository at this point in the history
…Subtitle section (#14)
  • Loading branch information
linjie-firework authored May 13, 2024
1 parent 34c6b68 commit f88acaf
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 28 deletions.
2 changes: 1 addition & 1 deletion FireworkVideoUI.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'FireworkVideoUI'
s.version = '0.1.0'
s.version = '0.1.1'
s.summary = 'An extension library meant to provide easier interfaces for the FireworkVideoSDK.'
s.homepage = 'https://github.com/loopsocial/firework_ios_sdk_ui_extensions'
s.license = 'Apache License, Version 2.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ public class AppLanguageManager {
UIViewController.swizzleViewControllerMethodsForAppLanguage()
Bundle.swizzleBundleMethodsForAppLanguage()
URLSession.swizzleURLSessionMethodsForAppLanguage()
NumberFormatter.swizzleNumberFormatterMethodsForAppLanguage()
UIImageView.swizzleImageViewMethodsForAppLanguage()
UILabel.swizzleLabelMethodsForAppLanguage()
UITextField.swizzleTextFieldMethodsForAppLanguage()
UITextView.swizzleTextViewMethodsForAppLanguage()
UIWindow.swizzleWindowMethodsForAppLanguage()
UIView.swizzleViewMethodsForAppLanguage()
NSLocale.swizzleNSLocaleMethodsForAppLanguage()
}

LayoutFlipManager.swizzelMethods()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// Locale+AppLanguage.swift
//
// Created by linjie jiang on 5/7/24.
//

import Foundation

extension NSLocale {
static func swizzleNSLocaleMethodsForAppLanguage() {
Swizzle.swizzleClassSelector(
cls: self,
originalSelector: #selector(getter: NSLocale.current),
customSelector: #selector(NSLocale.fw_current))
Swizzle.swizzleClassSelector(
cls: self,
originalSelector: #selector(getter: NSLocale.autoupdatingCurrent),
customSelector: #selector(NSLocale.fw_autoupdatingCurrent))
Swizzle.swizzleClassSelector(
cls: self,
originalSelector: #selector(getter: NSLocale.preferredLanguages),
customSelector: #selector(NSLocale.fw_preferredLanguages))
}

@objc class func fw_current() -> Locale {
if let language = AppLanguageManager.shared.appLanguage {
return Locale(identifier: language)
}

return fw_current()
}

@objc class func fw_autoupdatingCurrent() -> Locale {
if let language = AppLanguageManager.shared.appLanguage {
return Locale(identifier: language)
}

return fw_autoupdatingCurrent()
}

@objc class func fw_preferredLanguages() -> [String] {
let languages = fw_preferredLanguages()
if let language = AppLanguageManager.shared.appLanguage {
return [language] + languages
}

return languages
}
}

This file was deleted.

17 changes: 16 additions & 1 deletion Sources/FireworkVideoUI/Extensions/ObjCRuntime/Swizzle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ public class Swizzle {
guard let originalMethod = class_getClassMethod(cls, originalSelector) else { return }
guard let customMethod = class_getClassMethod(cls, customSelector) else { return }

method_exchangeImplementations(originalMethod, customMethod)
let clsType: AnyClass? = object_getClass(cls)
if class_addMethod(
clsType,
originalSelector,
method_getImplementation(customMethod),
method_getTypeEncoding(customMethod)
) {
class_replaceMethod(
clsType,
customSelector,
method_getImplementation(originalMethod),
method_getTypeEncoding(originalMethod)
)
} else {
method_exchangeImplementations(originalMethod, customMethod)
}
}
}

0 comments on commit f88acaf

Please sign in to comment.