Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix support for Frameworks #15

Closed
ed-mejia opened this issue Jan 4, 2016 · 3 comments
Closed

Fix support for Frameworks #15

ed-mejia opened this issue Jan 4, 2016 · 3 comments
Assignees
Labels

Comments

@ed-mejia
Copy link

ed-mejia commented Jan 4, 2016

Hi,

Actually the code does not support frameworks properly, the generated String extension:

private extension String {

    var localized: String {
        return NSLocalizedString(self, tableName: nil, bundle: NSBundle.mainBundle(), value: "", comment: "")
    }
    func localizedWithComment(comment:String) -> String {
        return NSLocalizedString(self, tableName: nil, bundle: NSBundle.mainBundle(), value: "", comment: comment)
    }
}

It's using _NSBundle.mainBundle()_, as a result if you call a localized var from the App target, the system will load the localized string from the localization file of that target and not from the framework.

I'm testing a little hack:

private extension String {

    var localized: String {
        return NSLocalizedString(self, tableName: nil, bundle: NSBundle(forClass: LocalizationsBundleClass.self), value: "", comment: "")
    }
    func localizedWithComment(comment:String) -> String {
        return NSLocalizedString(self, tableName: nil, bundle: NSBundle(forClass: LocalizationsBundleClass.self), value: "", comment: comment)
    }
}
internal class LocalizationsBundleClass {}

I created an internal dummy class in order to fetch the correct bundle via:

NSBundle(forClass: LocalizationsBundleClass.self)

The name of this dummy class should be based on the values in the script e.g:
OUTPUT_PATH="$BASE_PATH/Path_To_Output/_Localizations_.swift"

Although I'm not sure if this is the more optimal solution.

@ed-mejia
Copy link
Author

ed-mejia commented Jan 5, 2016

I'm thinking if this is the best way or not, For example a solution could be to create different Localizations files per target something like:

LocalizationsApp.swift
LocalizationsKit.swift <- Framework
LocalizationsWatch.swift
LocalizationsWidget.swift

This way every target has only the set of translations required by the target but leads to duplication if the same strings are needed in different targets, on the other hand if I create a single unique Localizations file within the framework to be shared by all targets seems to be more clean, what do you think?

Best regards!

@JiriTrecak
Copy link
Owner

Hello Ed!

Sorry it took me so long - I've been unavailable for few weeks, but I am back in business!

I will make sure to figure out how to do it the best way ; While your idea is solid and definitely one way to go, I still believe it should be ready for everything by just downloading - I don't want to force some new conventions etc. I am still open to suggestions, but I should be able to code it sometime next week once I put some serious thinking about it.

For now, thanks for trying it and I will let you know here once this is done.

Sincerely
JT

@JiriTrecak JiriTrecak added the bug label Jul 6, 2016
@JiriTrecak JiriTrecak added this to the 0.5 milestone Jul 6, 2016
@JiriTrecak JiriTrecak self-assigned this Jul 6, 2016
@JiriTrecak JiriTrecak removed this from the 0.5 milestone Jun 10, 2017
@JiriTrecak
Copy link
Owner

This will be fixed in upcoming Laurine 2.0. Please refer to #52 for any further comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants