Closed schroepf closed 4 years ago
PR to fix this issue: #623
With an extension like:
extension String {
var cstring: UnsafePointer<CChar> {
(self as NSString).utf8String!
}
}
Usage of the generated function is even easier:
print(R.string.localizable.test_string("one".cstring, "two".cstring, "three".cstring))
For cross platform projects it is often important to have shared strings and translations for android and iOS. But using format strings which contain string placeholders cannot be done in a consistent way for both platforms, as swift cannot easily handle the c string placeholder
%s
.Using R.swift strings containing these kind of placeholders are generated to take arguments of type:
UnsafePointer<unichar>
, but I found no way to put a unichar pointer into the function and produce meaningful output. It seems thatunichar
is the wrong type to use forString(format: format, locale: locale, value1)
which seems to work with 8 bit chars, not 16 bit chars.So I think that changing the generated type for
%s
placeholder fromUnsafePointer<unichar>
toUnsafePointer<CChar>
would allow us to work with these kind of format string.I patched R.swift locally with this change and it seemed to work:
Following code in Localizable.strings:
produces now the following code in
R.generated.swift
:And this can now be used like so:
Output is: