iOS: How to Get the Device Current Language Setting?

后端 未结 10 1254
北荒
北荒 2021-02-01 05:10

There are some features within my application that are supposed to be based on the language settings of the device where it\'s running.

I want to get the actual language

10条回答
  •  情歌与酒
    2021-02-01 05:35

    To know the current language selected within your localizations use

    [[NSBundle mainBundle] preferredLocalizations]
    

    Example:

    NSString *language = [[[NSBundle mainBundle] preferredLocalizations] objectAtIndex:0];
    

    To get two letter word

    NSString *language = [[[[NSBundle mainBundle] preferredLocalizations] objectAtIndex:0] substringToIndex:2];
    

    Swift:

    let language = NSBundle.mainBundle().preferredLocalizations.first as NSString
    

提交回复
热议问题