How to Get the ISO 639-2 country Code on iOS using Swift
文章推薦指數: 80 %
An Objective C solution is provided at https://github.com/almerlucke/NSLocale-ISO639_2. This won't be to hard to create load your own using ... Home Public Questions Tags Users Collectives ExploreCollectives FindaJob Jobs Companies Teams StackOverflowforTeams –Collaborateandshareknowledgewithaprivategroup. CreateafreeTeam WhatisTeams? Teams CreatefreeTeam CollectivesonStackOverflow Findcentralized,trustedcontentandcollaboratearoundthetechnologiesyouusemost. Learnmore Teams Q&Aforwork Connectandshareknowledgewithinasinglelocationthatisstructuredandeasytosearch. Learnmore HowtoGettheISO639-2countryCodeoniOSusingSwift AskQuestion Asked 3years,5monthsago Active 2years,9monthsago Viewed 4ktimes 4 CurrentlyIusedthefollowingcode,butitwillreturnonlytwodigitcode ifletcountryCode=(Locale.currentasNSLocale).object(forKey:.countryCode)as?String{ print("Code=>\(countryCode)")//FR } butIneedthethreedigitcode(FRA),KindlyanyonesuggestmetogettheISO 639-2code AlsoIhavecheckedtheAppledoc,butIdon'tknowhowtogettheexactcode https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPInternational/LanguageandLocaleIDs/LanguageandLocaleIDs.html#//apple_ref/doc/uid/10000171i-CH15 Thankyou. iosiphoneswiftswift3swift2 Share Improvethisquestion Follow askedJul26'18at10:16 NandhakumarNandhakumar 6422silverbadges1111bronzebadges Addacomment | 2Answers 2 Active Oldest Votes 4 AnObjectiveCsolutionisprovidedathttps://github.com/almerlucke/NSLocale-ISO639_2. Thiswon'tbetohardtocreateloadyourownusinghttps://github.com/almerlucke/NSLocale-ISO639_2/blob/master/Resources/iso639_2.bundle/iso639_1_to_iso639_2.plist publicextensionLocale{ privatestaticletallIso639_2LanguageIdentifiers:[String:String]={ guardletpath=Bundle.main.path(forResource:"iso639_1_to_iso639_2",ofType:"plist")else{return[:]} guardletresult=NSDictionary(contentsOfFile:path)as?[String:String]else{return[:]} returnresult }() publicvariso639_2LanguageCode:String?{ guardletlanguageCode=languageCodeelse{returnnil} returnLocale.allIso639_2LanguageIdentifiers[languageCode] } } Share Improvethisanswer Follow answeredJul26'18at10:44 JefferyThomasJefferyThomas 41k88goldbadges9090silverbadges115115bronzebadges 2 canyoucheckmyscreenshotTableB-1Languagedesignator,appleprovidesomeinforegardingtheISO639_2,isthereanyspecificmethodorkeywordavailableforgettingthecodes? – Nandhakumar Jul26'18at11:15 @NandhaKumarNo.NonethatIhavefound.Basedonotherpeople'swork,thereisnonethatanyoneelsehasfound.IfyouwantamethodtogettheISO639-2code,youwillneedtofindsomethird-partycode,orcreateyourownimplementation. – JefferyThomas Jul27'18at9:45 Addacomment | 0 Noyoucan'tgettheISOcodedirectly,Localedoesn'tprovidecodedirectly,youhaveextractcodeanotherway https://github.com/lukes/ISO-3166-Countries-with-Regional-Codes/blob/master/all/all.json DownloadjsonfromaboveURL,itwillprovideyouaallCountrywithdetails,alsocontainISOcodewithalpha-2code. SoyoucangettheISO(alpha-3)codeasperyourlocalecode. Share Improvethisanswer Follow answeredJul26'18at10:19 JaydeepVoraJaydeepVora 5,79311goldbadge2020silverbadges4040bronzebadges 2 1 @NandhaKumarIsworkedforyou?thenaccpettheanswerplease – JaydeepVora Jul26'18at10:32 1 @NandhaKumarSoyouneedthisanswer? – JaydeepVora Jul26'18at11:22 Addacomment | YourAnswer ThanksforcontributingananswertoStackOverflow!Pleasebesuretoanswerthequestion.Providedetailsandshareyourresearch!Butavoid…Askingforhelp,clarification,orrespondingtootheranswers.Makingstatementsbasedonopinion;backthemupwithreferencesorpersonalexperience.Tolearnmore,seeourtipsonwritinggreatanswers. Draftsaved Draftdiscarded Signuporlogin SignupusingGoogle SignupusingFacebook SignupusingEmailandPassword Submit Postasaguest Name Email Required,butnevershown PostYourAnswer Discard Byclicking“PostYourAnswer”,youagreetoourtermsofservice,privacypolicyandcookiepolicy Nottheansweryou'relookingfor?Browseotherquestionstaggediosiphoneswiftswift3swift2oraskyourownquestion. TheOverflowBlog Bestpracticescanslowyourapplicationdown Bestpracticesforwritingcodecomments FeaturedonMeta ProvidingaJavaScriptAPIforuserscripts Congratulationstothe59sitesthatjustleftBeta A/BtestingontheAskpage Related 1070 HowtochangethenameofaniOSapp? 3 Whereis"ViewingLocalizableStrings"inXcode4.2 0 ThirdpartyframeworkiniOS 1068 HowdoIcallObjective-CcodefromSwift? 458 CloseiOSKeyboardbytouchinganywhereusingSwift 0 HowtoshareoropenthepdffileusingwhatsappiniOS? 477 HowdoIgettheAppversionandbuildnumberusingSwift? 518 HowtoaddconstraintsprogrammaticallyusingSwift 0 HowtoaddanactiontonotificationsinSwift2iOS9 6 ExplicitoldfashionederrorhandlinginSwift2 HotNetworkQuestions Gettingonlyrealsolutions Doesplayingwithoutaclock,andthearbiterwilladdtheclockwhenthegamegoestoolongiswithinFIDErules? Postdocroommatewithstudent Windowscopycommandcopiesseveralfilesinnon-numericalorder Whatwouldtheweatherbelikeonainfinitegentleslope? Whydoesthelightpassingthroughaprismgetsbentinthesamedirectiontwice? Co-signertakingoverasprimarywhenborrowercannolongerdrive PurposeofZenerdiodeinbutton Plural:Focas-leopardo,Focas-leopardosoufocasleopardos? Whyaren'tKripkesemantics"syntaxindisguise"? Whyisthe5GrolloutaproblemintheUSAbutapparentlynowhereelse? HowdoIconnectacommandprompttoaseriallineinMS-DOS6.22? Myheatpumpisfreezingover,andit'sdippingintothe20°F-snextweek.HowcanIprotectmyheatpumpwhileIwaitforservice? ClassABpoweramplifierfrom"ElectronicDevices"byThomasL.Floyd WithFTLtechnologyisitpossibletoleaveafteranotherandyetarrivebeforeit? Whatmaterialpropertiesareunpredictable(notreproducible)butcanbemeasuredconsistentlyandatalowcost? Scifinoveltakingplaceinmultipletimeperiods:Atlantisdestroyedinnuclearexchange,moderndaynavyreplacedbyUSAFRockets Differentoccurencesoftheword'period'inalgebraicgeometry Whosaidthisquoteaboutassimilation? IsthereapointinpursuingaPhDoutsideoftopuniversities? Isthereanalgorithmwhosetimecomplexityisbetweenpolynomialtimeandexponentialtime? Whatdoes"super"intitleoforganpiecesmean? Convertthedecimaldigitsofastring'sUnicodecodepointstobinary,reinterpretasdecimal,andtakethesum WheredidAS-206gobetween1967and1973? morehotquestions Questionfeed SubscribetoRSS Questionfeed TosubscribetothisRSSfeed,copyandpastethisURLintoyourRSSreader. lang-swift Yourprivacy Byclicking“Acceptallcookies”,youagreeStackExchangecanstorecookiesonyourdeviceanddiscloseinformationinaccordancewithourCookiePolicy. Acceptallcookies Customizesettings
延伸文章資訊
- 1Learn iOS 7 App Development - 第 672 頁 - Google 圖書結果
See http://www.loc.gov/standards/iso639-2/php/English_list.php. iOS uses ISO 639-2 for those lang...
- 2ISO 639 Code Tables | ISO 639-3
- 3如何使用Swift 在iOS 上获取ISO 639-2 国家/地区代码 - IT工具网
ios - 如何使用Swift 在iOS 上获取ISO 639-2 国家/地区代码. 原文 标签 ios iphone swift swift3 swift2. 目前我使用了以下代码,但它只会返...
- 4List of ISO 639-1 codes - Wikipedia
ISO 639 is a standardized nomenclature used to classify languages. Each language is assigned a tw...
- 5How to Get the ISO 639-2 country Code on iOS using Swift
An Objective C solution is provided at https://github.com/almerlucke/NSLocale-ISO639_2. This won'...