توطين في إشعارات iOS؟
-
25-09-2019 - |
سؤال
لديّ تطبيقي يعمل بشكل جيد ويستخدم الإخطارات المحلية.
لقد قررت تدويل التطبيق الآن وجعل كل شيء يعمل بشكل جيد باستثناء الإخطارات التي تم تعيينها على لغة قبل تغيير اللغة على الجهاز.
أقوم بملء الرسائل في الإشعار من صفيف يحتوي على سلاسل محلية ، لذلك اعتقدت أنه عندما يغير المستخدم لغة الجهاز ، ستتغير السلسلة في الإشعار أيضًا لكنني كنت مخطئًا.
كيف أفضل لمعالجة هذه القضية؟ هل يجب أن يكون نص NSString الخاص بي هو nslocalizationstring؟
رمز الإخطار الخاص بي:
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
return;
localNotif.fireDate = [alertTimes objectAtIndex:i];
localNotif.timeZone = [NSTimeZone defaultTimeZone];
NSString *text = [alertText objectAtIndex:i];
// Notification details
localNotif.alertBody = text;
// Set the action button
localNotif.alertAction = @"View";
localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.applicationIconBadgeNumber = 1;
// Specify custom data for the notification
NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"someValue" forKey:@"someKey"];
localNotif.userInfo = infoDict;
// Schedule the notification
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
[localNotif release];
المحلول
هل يجب أن يكون نص NSString الخاص بي هو nslocalizationstring؟
نعم ، سأفعل ذلك.
يحل محل [alertTimes objectAtIndex:i]
مع NSLocalizedString(@"alertTimes",[alertTimes objectAtIndex:i])
. أفترض أنك تخزين الأوتار في alertTimes
صفيف يتطابق مع السلسلة المترجمة.
لا تنتمي إلى StackOverflow