我有設置NSUserDefaults根據英文版播放歌曲的方法。我目前正在將其全部翻譯成其他語言,但由於警報基於NSUserDefaults對象。這應該使更多的意義:獲取本地化字符串的英文版
- (void)applySoundNameAndSaveSoundToNSUserDefaults {
[self.audioPlayer stop];
NSString *soundName = self.soundNameLabel.text;
[[NSUserDefaults standardUserDefaults] setObject:soundName forKey:@"AlarmSound"];
}
所以你可以看到,如果電池標籤是局部的,它將把該名稱的語言版本NSUserDefaults的中,如果我去做了這種方式,我不想至。
這是我怎麼玩:
self.alarmSound = [[NSUserDefaults standardUserDefaults] stringForKey:@"AlarmSound"];
- (void) fireLocalNotification {
NSString *notificationSound;
notificationSound = [NSString stringWithFormat:@"%@", self.alarmSound];
notificationSound = [notificationSound stringByAppendingString:@".caf"];
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.soundName = [NSString stringWithFormat:@"%@", notificationSound];
}
這個擁有一種問題,因爲在主束我sound.caf文件中的英文格式命名。那麼如何在本地化時獲得英文版本的'self.soundNameLabel.text'?
編輯我發現這個在docs:initWithFormat:locale:
這正是我要找的。但我讀過它不是autoreleased,所以我不知道這是我應該使用的東西。此外,使用它
你做錯了。不要將程序行爲基於顯示給用戶的字符串。我確信你可以保留必要的信息,而不是本地化的文本。 – Sulthan