-
-
Save Gernot/3ad5396053fc26b29b9cac4ae45f59ef to your computer and use it in GitHub Desktop.
/* Here is what I want to write, and what Xcode sees. */ | |
struct Loc { | |
struct someDomain { | |
/// Here is some description of what this string is doing. It's readable in the AutoComplete Description! | |
static let myStringName = "Woah, woah, this is the actual content of the String!" | |
} | |
} | |
/* And now some Parser/Code Generator comes in and generates this out of it*/ | |
/* This is what the localization tools and the compiler see, when the App actually gets compiled */ | |
struct Loc { | |
struct someDomain { | |
static let myStringName = NSLocalizedString( | |
"SomeDomain.MyStringName", | |
value:"Woah, woah, this is the actual content of the String!", | |
comment: "Here is some description of what this string is doing. It's readable in the AutoComplete Description!") | |
} | |
} | |
/* Is this possible? Does this exist? Does anybody what to build this with me? */ | |
how would you do the actual localization? Where would you put "Oh, pardauz, das ist der Inhalt der Zeichenkette!""
We use https://github.com/mac-cain13/R.swift/blob/master/Documentation/Examples.md#localized-strings for having compile time safety when using strings and other assets. Not sure if R.swift would parse comments in the strings file and adds them as comment in the generated code - can check that tomorrow at work
That would be no different from how it works now. The localization tools se the NSLocalizedStrings, do the import/export dance, etc.
I don't know why you mean with "compile time safety", but this approach guarantees that there is always a String
behind the symbol, and in the worst case, if the translation isn't available, the string is the original content in the base language, and never ever the localization key.
as we create the R files at each build we can be sure that there is a string behind R.string.localizable.myStringName
Usage in the code would be something like
label.text = Loc.someDomain.myStringName
of course, all with AutoComplete that also shows the comment.