Getting current device language in iOS?

前端 未结 30 2343
星月不相逢
星月不相逢 2020-11-22 09:10

I\'d like to show the current language that the device UI is using. What code would I use?

I want this as an NSString in fully spelled out format. (Not

30条回答
  •  心在旅途
    2020-11-22 09:30

    If you want to get only language here is my suggested answer:

    NSString *langplusreg = [[NSLocale preferredLanguages] objectAtIndex:0];
    NSString * langonly = [[langplusreg componentsSeparatedByString:@"-"] 
    objectAtIndex:0];
    

    In my case i just wanted only Locale language not locale region.

    Output: If your Locale language is Japanese and locale region is Japan then:

    langplusreg = ja-JP

    langonly = ja

提交回复
热议问题