Comments (3)
An alternative to supporting this could be an option for the generator to not generate the accessor tr/lo variable or to keep it internal instead of public to allow for more control over how Localizations is accessed when used in a module.
Edit: I just found out there's a -standalone
flag for the generator which prevents the addition of the static tr/lo, which eases wrapping of Localizations in client code, however built in support would still be nice
from nstack-ios-sdk.
Hi Jakob; we haven't had problems with this yet, but we see how this can be an issue; we'll look into this soon π
from nstack-ios-sdk.
Hi @mariusc Thanks!
I solved it for now using the -standalone flag along with this code that enables control over the tr
instance
import NStackSDK
internal var lo: Localizations {
guard let manager = NStack.sharedInstance.localizationManager else {
return Localizations()
}
return try! manager.localization()
}
public internal (set) var tr: Localizations = { lo }()
#if DEBUG
public func setTranslations(_ localizations: Localizations) {
tr = localizations
}
public func loadTranslationsFromJSON(_ filename: String, in bundle: Bundle) -> Localizations {
let path = bundle.path(forResource: filename, ofType: "json")!
let data = try! String(contentsOfFile: path).data(using: .utf8)!
let dict = try! JSONSerialization.jsonObject(with: data, options: .allowFragments) as! [String: Any]
let translationsData = try! JSONSerialization.data(withJSONObject: dict["data"]!, options: .fragmentsAllowed)
let result = try! JSONDecoder().decode(Localizations.self, from: translationsData)
return result
}
#endif
and then in my Test class
class override func setUp() {
super.setUp()
let staticLocalizations = Shared.loadTranslationsFromJSON("Localizations_da-DK", in: Bundle(for: self))
Shared.setTranslations(staticLocalizations)
}
from nstack-ios-sdk.
Related Issues (20)
- Alerts are not presented when using the SwiftUI `App` protocol.
- Using a dependency that includes NStack can cause a crash
- Nstack does not have support in Xcode 14.3 via cocoapods, can not configure Nstack. HOT 2
- NStack crash in responses feature
- Shake to give feedback HOT 1
- Demo project HOT 3
- Send SDK version in header
- Release latest version with CocoaPods
- Using SKLocalizations type instead of Localizations as LocalizationModel crashes the SDK HOT 2
- Spaces in coding keys not being trimmed HOT 1
- Please give SPM support some attention HOT 2
- The SDK doesn't return Geography's Languages
- Alert manager's showAlertBlock with url crashes after first open HOT 1
- Find a way to make the whole NStack suite more easy to work with
- Localize doesn't update in production HOT 2
- NStack SDK crashes when instantiating localizations using Xcode 12.5 Beta1 HOT 3
- \n or html
- Link to Feature overview in readme links to non-existing page
- watchOS support
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nstack-ios-sdk.