Giter Site home page Giter Site logo

Comments (3)

jakobmygind avatar jakobmygind commented on August 14, 2024

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.

mariusc avatar mariusc commented on August 14, 2024

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.

jakobmygind avatar jakobmygind commented on August 14, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.