-
Notifications
You must be signed in to change notification settings - Fork 0
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
Implemented overrideToFallbackLanguage flag and fallbackLanguage; #14
Conversation
The problem I see is that there is no way to determine for certain that there is no translation for a specific key, there are no constraint on key naming so it can easily be called the same as translation. I don't know if you all had some idea on how to resolve this issue, cause our translation tables after they are generated by polyglot already have filled empty translations with key values. |
@jabou |
Maybe we can check if the translation has |
@jabou && @Truba |
@Antonijo2307 This will break debugging; the main purpose of showing the key instead of the translation is for QA (and the client) to easily see what translations are missing on the screen. |
@jabou
so it will be the same result as you defined it in this task, if you set overrideToFallbackLanguage = false then you will see keys in places that do not have translations... |
@jabou I don't see how it can break someones implementation, if someone defined his own block than this one will just not be called anyways. The solution with predefined localizationPerformingBlockWithFallbackLanguage block does the same thing, if I define block "localizationPerformingBlockWithFallbackLanguage" on manager and I set that one from my project than I can't use my custom block if I used one before or if I use my custom block than I can't use localizationPerformingBlockWithFallbackLanguage block, right?. So it doesn't really solve the problem. As @Truba said, the problem can be resolved locally per project, and anyone who has custom block implemented will have to deal with it by updating code in their custom localisation block, we can make some instructions on how to do it. But I think most users use this predefined localisation block, and if they did not define documentation language it will behave the same as before, so again no broken implementation. So I can ditch the lazy part by declaring fallbackLanguage as static var, manager is singletone with private constructor after all, and do something like this:
What do you think? Do you have some usecase to demonstrate breaking of functionality that I didn't account for? |
@jabou @Truba @Antonijo2307 what's the status of this PR? |
@Antonijo2307 I checked the proposed implementation, and it still breaks the logic. As long as Have you checked maybe if something like this will work: public var localizationPerformingBlock: (_ key: String, _ language: String)->(String) = { (key, language) in
return NSLocalizedString(key, tableName: language, comment: "")
} and then move your logic into the func localizedString(forKey key: String) -> String {
let translation = localizationPerformingBlock(key, language)
guard translation == key else {
return translation
}
guard let fallbackLanguage else {
return translation
}
return localizationPerformingBlock(key, fallbackLanguage)
} In this case, if the user sets If they have some custom logic within If you go with the proposed approach, please update readme and document |
Ok I have updated the code. Now the block is free for implementation and internally LocText doesn't call it directly. This solves most of the problems from above. |
I would agree, but that should not be part of this lib. We can write that limitation when fallback translation is used in the readme (documentation) with the proposed solution. |
Co-authored-by: Jasmin Abou Aldan <[email protected]>
60a7c16
into
feature/translation-fallback/fallback_language
Add functionality that enables user to configure Swiftl18n to use fallback language in case there is no translation for searched key.
Productive task:
https://app.productive.io/1-infinum/task/8092739