iOS 多国语言判断


iOS的各个国家的语言的简称又有些不一样了,在这里共享一下。这有18国语言,直接上代码。

typedef enum : NSUInteger {

   chineseLanguage = 0,      //中文

   englishLanguage = 1,      //非中文(显示英文,超出范围)

   traditionalLanguage = 2,   //繁体

   hindiLanguage = 3,        //印地语

   spanishLanguage = 4,      //西班牙语

   arabicLanguage = 5,        //阿拉伯语

   russianLanguage = 6,      //俄罗斯语

   bengaliLanguage = 7,      //孟加拉语

   portugueseLanguage = 8,     //葡萄牙语

   italianLanguage = 9,      //意大利语

   germanLanguage = 10,      //德语

   frenchLanguage = 11,      //法语

   japaneseLanguage = 12,     //日语

   persianLanguage = 13,      //波斯语

   turkishLanguage = 14,      //土耳其语

   javaneseLanguage = 15,     //爪哇语

   vietnameseLanguage = 16,   //越南语

   koreanLanguage = 17,      //韩语

} varietyLanguage;//各国语言枚举 add by jiang  2017年07月25日17:42:59

   

+ (NSString *)getLocalLanguage{

   NSString * language = [NSLocale preferredLanguages].firstObject;

   return language;

 

+ (NSInteger)checkLocalLanguage

  NSString *language = [self getLocalLanguage];

  NSInteger languageInt = englishLanguage;//1 默认是英文

   if ([language hasPrefix:@"zh-Hans"])

   {

      languageInt = chineseLanguage;//0中文

   }

   else if ([language hasPrefix:@"zh-Hant"])

   {

      languageInt = traditionalLanguage;//2繁体

   }

   else if ([language hasPrefix:@"hi"])

   {

      languageInt = hindiLanguage;//3印地语

   }

   else if ([language hasPrefix:@"es"])

   {

      languageInt = spanishLanguage;//4西班牙语

   }

   else if ([language hasPrefix:@"ar"])

   {

      languageInt = arabicLanguage;//5阿拉伯语

   }

   else if ([language hasPrefix:@"ru"])

   {

      languageInt = russianLanguage;//6俄罗斯语

   }

   else if ([language hasPrefix:@"bn"])

   {

      languageInt = bengaliLanguage;//7孟加拉语

   }

   else if ([language hasPrefix:@"pt"])

   {

      languageInt = portugueseLanguage;//8葡萄牙语

   }

   else if ([language hasPrefix:@"it"])

   {

      languageInt = italianLanguage;//9意大利语

   }

   else if ([language hasPrefix:@"de"])

   {

      languageInt = germanLanguage;//10德语

   }

   else if ([language hasPrefix:@"fr"])

   {

      languageInt = frenchLanguage;//11法语

   }

   else if ([language hasPrefix:@"ja"])

   {

      languageInt = japaneseLanguage;//12日语

   }

   else if ([language hasPrefix:@"fa"])

   {

      languageInt = persianLanguage;//13波斯语

   }

   else if ([language hasPrefix:@"tr"])

   {

      languageInt = turkishLanguage;//14土耳其语

   }

   else if ([language hasPrefix:@"jv"])

   {

      languageInt = ;">爪哇语

   }

   else if ([language hasPrefix:@"vi"])

   {

      languageInt = vietnameseLanguage;//16越南语

   }

   else if ([language hasPrefix:@"ko"])

   {

      languageInt = koreanLanguage;//17韩语

   }

   //   else if ([language hasPrefix:@"zh-Hant"])

   //   {

   //      languageInt = 2;//18

   //

   //   }

   return languageInt;