-
-
Notifications
You must be signed in to change notification settings - Fork 120
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
Automate addition of LocalizedStringKeys to source locale #194
Comments
Just in case this helps someone out there until we have proper support for SwiftUI in SwiftGen and BartyCrouch: In my pure SwiftUI projects, I'm currently using SwiftGen with a custom
I also altered the // This file is required in order for the `transform` task of the translation helper tool BartyCrouch to work.
// See here for more details: https://github.com/Flinesoft/BartyCrouch
import Foundation
enum BartyCrouch {
enum SupportedLanguage: String {
case english = "en"
case french = "fr"
case german = "de"
case japanese = "ja"
case turkish = "tr"
}
static func translate(key: String, translations: [SupportedLanguage: String], comment: String? = nil) -> LocalizedString {
let typeName = String(describing: BartyCrouch.self)
let methodName = #function
print(
"Warning: [BartyCrouch]",
"Untransformed \(typeName).\(methodName) method call found with key '\(key)' and base translations '\(translations)'.",
"Please ensure that BartyCrouch is installed and configured correctly."
)
// fall back in case something goes wrong with BartyCrouch transformation
return LocalizedString(lookupKey: "BC: KEY NOT TRANSFORMED!")
}
} The public struct LocalizedString {
internal let lookupKey: String
var key: LocalizedStringKey {
LocalizedStringKey(lookupKey)
}
var text: String {
L10n.tr("Localizable", lookupKey)
}
} This works very well for me. |
Thank you very much for this workaround. Unfortunately I have a hard time understanding how to make all of this work. The same question came up with I've created the Sorry for my dumb questions. I have no idea how all of this works and had no luck finding tutorials or anything on Stackoverflow so far. |
@Patrick-Kladek You are right, the README of BartyCrouch doesn't include detailed step-by-step explanations for beginners, it's targeted towards somewhat experiences iOS developers who have already used similar tools, like SwiftGen. The most detailed tutorial is I think still my blog post which is also mentioned at the top of the README. Please read it, it should clarify how SwiftGen and BartyCrouch are interrelated (basically, they're not at all, BartyCrouch only supports generation of But let me also answer the more specific questions you asked:
Not at all. If anything, you tell SwiftGen how to use it. Of course the documentation of BartyCrouch doesn't mention how to use SwiftGen. The custom stencil is a feature of SwiftGen and needs to be specified in the
The
Please see the options of the
I think the blog post already answers this question (the README does so, too).
Those are not dumb questions. But I think if you've invested a little more time to read the README in more detail (especially if you also read the linked blog post), you could have found most of the answers. But I can understand that all the different existing options can be overwhelming if you're just getting started with BartyCrouch. I am working on a new version which is much easier to use, but it won't be released before 2022, I think. I hope this answer helps you get on the right track (in case you're still interested, sorry for the late answer). Good luck! |
Bump! @Flinesoft any progress on this? |
@Sam-Spencer Currently BartyCrouch is based on tools from Apple which don't support In the mean time, please note that there's 2 other options based on the Pro Localization Workflow:
I won't have the time to do the change no. 2 in the comings months, maybe beginning next year. But it's just a matter of adding it here and adding a So if someone is willing to take some time to implement as described above, I would be willing to review & merge. :) |
For Monal IM I'm using a combination of Xcodes xliff string extraction on compilation, bash, a python script and bartycrouch to get SwiftUI strings added to my strings file. Here is the commit Introducing this functionality, maybe this is useful to someone: monal-im/Monal@6fcdcb6 I had to temporarily turn off "SWIFT_EMIT_LOC_STRINGS" when extracting the xliff file because it could not compile the project. I don't know why this is necessary, but since in our CI our build script builds the app before our translation update script gets to run, this is fine (the SwiftUI string are already extracted at this point, even with SWIFT_EMIT_LOC_STRINGS turned off while extracting the xliff). |
@tmolitor-stud-tu Thank you for sharing your solution and experiences. Since my last comment on this thread, there's been a development that might be of interest to all SwiftUI users of BartyCrouch: I released a new Mac app called ReMafoX which basically is a successor to BartyCrouch with more features. Besides other things, it has native support for To learn more, see this short summary article: Give ReMafoX a try! Unlike BartyCrouch, which is more of a community project, I can provide proper support for it. |
As described in my article Safer Localization in SwiftUI, BartyCrouch can already be used for normalizing and linting localiation on SwiftUI-only applications. But the transformation from
NSLocalizedString
orBartyCrouch.translate
doesn't support the newLocalizedStringKey
type yet.We should consider adding an option to transform
BartyCrouch.translate
into a literal String and adding the key to the sourceLocalizable.strings
file automatically while doing that like before. Alternatively, we could also provide theSafeLocalizedStringKey
file from the article and convert into that instead. That way, whenever the key would be removed, there would be an error shown during development, providing even more safety.A more general approach could also include rewriting the entire BartyCrouch transformation logic for more flexibility, configurability, performance and therewhile drop the dependency
extractLocStrings
, at least for SwiftUI-only applications.The text was updated successfully, but these errors were encountered: