I'm localizing my iPad/iPhone app by using genstrings Classes/*.m
to generate the Localizable.strings
file. Most strings work fine and I get the expected output, but with some strings genstrings
is adding 1$
or 1$
in the middle of my format specifiers, like this:
/* No comment provided by engineer. */
"%@%i" = "%1$@%2$i";
/* No comment provided by engineer. */
"%@: %i" = "%1$@: %2$i";
/* No comment provided by engineer. */
"%@" = "%@";
I've not had this issue with other apps, and as you can see it's not consistent. But it doesn't appear to be random either as when I run genstrings
on the same class files again the 1$
's etc are always in the same spot.
I can leave them in and the strings work with the correct formatting, but I have been manually removing them because I'm not sure what the $
will do. It's annoying to have to go through and manually update the strings (plus I'll likely miss one eventually).
I'm thinking it could be a text encoding issue? Or can I safely leave them in my strings and just ignore them?
N$
tells the printf
-style functions and methods the strict order of your format string's fields. That way, when localizing to a language where the order is different, you don't have to modify the code--just the format string:
printf("%s %s\n", "foo", "bar");
printf("%1$s %2$s\n", "foo", "bar");
printf("%2$s %1$s\n", "foo", "bar");
Output:
foo bar
foo bar
bar foo
Those numbers refer to the argument position of the replacement value. For instance, %2$i
means "replace this with the second argument, which should be an integer." This is useful when localizing to languages that use different word arrangements, because things can be replaced in an order different from that of English.
In other words, they're safe to leave in or remove, and they'll come in handy for natural-sounding translations to other languages.
You can turn off the generation of positional parameters if you don't like it by passing
-noPositionalParameters
to genstrings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With