0

Hmmm, I'm not so clever as I thought I was. Struggling all day with a few lines of code.

char latChar = (actLat > 0) ? 'N' : 'S';
NSString *latString = [NSString stringWithFormat:@"%c" , latChar];    
NSString *latStringLocal = [NSString stringWithFormat:NSLocalizedString(@"%c",nil), latString];

In the first line: wich character is the correct one. Latitude > 0 degrees it's N, < 0 it is a S. This works. In the second line I'm converting the char to a string. Works OK too. In the third line all of it went wrong. When running the app all kind of symbol and normal characters are shown. Every second a new one. That last part is understandable because the locationmanager is constant updating.

But why those characters? What am I doiing wrong here? See both localizable.strings files

en.lproj

"N" = "N";
"S" = "S";
"W" = "W"; 
"E" = "E";

nl.proj

"N" = "N";
"S" = "Z";
"W" = "W";
"E" = "O";

The app displayname works fine so the .strings file is found en "read". Please advice. Thank you in advance.

4

3 に答える 3

0

あなたが何をしているのかわかりませんNSLocalizedString(); 最初の引数は であり@"N"、では@"S"ありません@"%c"

于 2013-02-27T16:34:31.330 に答える
0

私は次のように書きます:

NSString *latStringLocal = actLat > 0 ? NSLocalizedString(@"N", @"North abbreviation") : NSLocalizedString(@"S", @"South abbreviation"); 

次に、英語の文字列を再生成します。

find . -name \*.m | xargs genstrings

en.lproj/Localizable.strings には以下が含まれます。

/* North abbreviation */
"N" = "N";

/* South abbreviation */
"S" = "S";

…そして nl.lproj/Localizable.strings には以下が含まれている必要があります:

/* North abbreviation */
"N" = "N";

/* South abbreviation */
"S" = "Z";

genstringsユーティリティは、NSLocalizedString に対する変数パラメーターを好まないことに注意してください (キーを生成しません) 。しかし、実行時に - キーが存在する場合[NSBundle.mainBundle localizedStringForKey:(key) value:@"" table:nil]- すべてが機能するはずです。

于 2013-02-27T23:52:54.643 に答える
-1
NSString *latStringLocal =  NSLocalizedString((actLat > 0) ? @"N" : @"Y", @"");
于 2013-02-27T16:34:21.600 に答える