iOS更改应用程序语言不';不生效

iOS更改应用程序语言不';不生效,ios,localization,nsbundle,Ios,Localization,Nsbundle,我正在使用此设置动态更改iOS应用程序首选语言: [[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObject:@"ar"] forKey:@"AppleLanguages"]; 然后我从主NSBundle对象加载一个本地化的资源文件,但加载的文件不是新语言,而是以默认英语加载的,直到我完全重新启动应用程序,然后加载阿拉伯语本地化 我想强制NSBundle以新语言@“ar”加载资源文件,而不是应用程序启动时设

我正在使用此设置动态更改iOS应用程序首选语言:

[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObject:@"ar"] forKey:@"AppleLanguages"];
然后我从主NSBundle对象加载一个本地化的资源文件,但加载的文件不是新语言,而是以默认英语加载的,直到我完全重新启动应用程序,然后加载阿拉伯语本地化


我想强制NSBundle以新语言@“ar”加载资源文件,而不是应用程序启动时设置的语言。怎么做

您的方法是一种获取所需内容的黑客方法,需要重新启动应用程序才能生效

最好使用
NSLocalizedStringFromTableInBundle
而不是
nsLocalizedStrings
,并为该语言提供捆绑包

NSString* path = [[NSBundle mainBundle] pathForResource:@"ar" ofType:@"lproj"];
NSBundle* ar_bundle = [NSBundle bundleWithPath:path];

NSLocalizedStringFromTableInBundle(@"str", nil, ar_bundle, @"comment");
如果将捆绑包放在全局范围内,则可以轻松创建宏:

#define ARLocalizedString(str, cmt) NSLocalizedStringFromTableInBundle(str, nil, ar_bundle, cmt)

您的方法是一种获取所需内容的黑客方法,需要重新启动应用程序才能生效

最好使用
NSLocalizedStringFromTableInBundle
而不是
nsLocalizedStrings
,并为该语言提供捆绑包

NSString* path = [[NSBundle mainBundle] pathForResource:@"ar" ofType:@"lproj"];
NSBundle* ar_bundle = [NSBundle bundleWithPath:path];

NSLocalizedStringFromTableInBundle(@"str", nil, ar_bundle, @"comment");
如果将捆绑包放在全局范围内,则可以轻松创建宏:

#define ARLocalizedString(str, cmt) NSLocalizedStringFromTableInBundle(str, nil, ar_bundle, cmt)

您的方法是一种获取所需内容的黑客方法,需要重新启动应用程序才能生效

最好使用
NSLocalizedStringFromTableInBundle
而不是
nsLocalizedStrings
,并为该语言提供捆绑包

NSString* path = [[NSBundle mainBundle] pathForResource:@"ar" ofType:@"lproj"];
NSBundle* ar_bundle = [NSBundle bundleWithPath:path];

NSLocalizedStringFromTableInBundle(@"str", nil, ar_bundle, @"comment");
如果将捆绑包放在全局范围内,则可以轻松创建宏:

#define ARLocalizedString(str, cmt) NSLocalizedStringFromTableInBundle(str, nil, ar_bundle, cmt)

您的方法是一种获取所需内容的黑客方法,需要重新启动应用程序才能生效

最好使用
NSLocalizedStringFromTableInBundle
而不是
nsLocalizedStrings
,并为该语言提供捆绑包

NSString* path = [[NSBundle mainBundle] pathForResource:@"ar" ofType:@"lproj"];
NSBundle* ar_bundle = [NSBundle bundleWithPath:path];

NSLocalizedStringFromTableInBundle(@"str", nil, ar_bundle, @"comment");
如果将捆绑包放在全局范围内,则可以轻松创建宏:

#define ARLocalizedString(str, cmt) NSLocalizedStringFromTableInBundle(str, nil, ar_bundle, cmt)

我已尝试过此功能,并且在不重新启动应用程序的情况下工作正常:

//Use this in constants
#ifdef NSLocalizedString
#undef NSLocalizedString
#endif
#define NSLocalizedString(str, cmt) NSLocalizedStringFromTableInBundle(str, nil, newLangbundle, cmt)
newLangbundle-->在.pch中定义一个全局变量,并根据语言选择使用此

 NSString* path = [[NSBundle mainBundle] pathForResource:@"th" ofType:@"lproj"];
 newLangbundle = [NSBundle bundleWithPath:path];

我已尝试过此功能,并且在不重新启动应用程序的情况下工作正常:

//Use this in constants
#ifdef NSLocalizedString
#undef NSLocalizedString
#endif
#define NSLocalizedString(str, cmt) NSLocalizedStringFromTableInBundle(str, nil, newLangbundle, cmt)
newLangbundle-->在.pch中定义一个全局变量,并根据语言选择使用此

 NSString* path = [[NSBundle mainBundle] pathForResource:@"th" ofType:@"lproj"];
 newLangbundle = [NSBundle bundleWithPath:path];

我已尝试过此功能,并且在不重新启动应用程序的情况下工作正常:

//Use this in constants
#ifdef NSLocalizedString
#undef NSLocalizedString
#endif
#define NSLocalizedString(str, cmt) NSLocalizedStringFromTableInBundle(str, nil, newLangbundle, cmt)
newLangbundle-->在.pch中定义一个全局变量,并根据语言选择使用此

 NSString* path = [[NSBundle mainBundle] pathForResource:@"th" ofType:@"lproj"];
 newLangbundle = [NSBundle bundleWithPath:path];

我已尝试过此功能,并且在不重新启动应用程序的情况下工作正常:

//Use this in constants
#ifdef NSLocalizedString
#undef NSLocalizedString
#endif
#define NSLocalizedString(str, cmt) NSLocalizedStringFromTableInBundle(str, nil, newLangbundle, cmt)
newLangbundle-->在.pch中定义一个全局变量,并根据语言选择使用此

 NSString* path = [[NSBundle mainBundle] pathForResource:@"th" ofType:@"lproj"];
 newLangbundle = [NSBundle bundleWithPath:path];

更改语言后,您需要同步用户默认值:
[[NSUserDefaults standardUserDefaults]默认同步]

更改语言后需要同步用户默认值:
[[NSUserDefaults standardUserDefaults]默认同步]

更改语言后需要同步用户默认值:
[[NSUserDefaults standardUserDefaults]默认同步]

更改语言后需要同步用户默认值:

[[NSUserDefaults standardUserDefaults]默认同步]

此方法仅在你重新启动应用程序时有效。有没有立即有效的方法?@Ahmedsay查看我的答案。此方法仅在你重新启动应用程序时有效。有没有立即有效的方法?@Ahmedsay查看我的答案。此方法仅在你重新启动应用程序时有效。有没有立即有效的方法?@Ahmedsay查看我的答案。此方法只有在重新启动应用程序时才有效。是否有一种方法可以立即工作?@Ahmedsayd请参阅我的答案。这不需要重新启动应用程序?谢谢。那么,在加载nib文件时,我也会使用此方法而不是[NSBundle mainBundle]吗?@Ahmed说是的,在加载nib时使用
ar\u bundle
。这不需要重新启动应用程序?谢谢。那么,在加载nib文件时,我也会使用此方法而不是[NSBundle mainBundle]吗?@Ahmed说是的,在加载nib时使用
ar\u bundle
。这不需要重新启动应用程序?谢谢。那么,在加载nib文件时,我也会使用此方法而不是[NSBundle mainBundle]吗?@Ahmed说是的,在加载nib时使用
ar\u bundle
。这不需要重新启动应用程序?谢谢。那么,在加载nib文件时,我是否也会使用此方法而不是[NSBundle mainBundle]呢?@Ahmed说是的,在加载nib文件时使用
ar_bundle