asp.net core ABP模板本地化设置

ABP的语言本地化设置非常方便,甚至地区图标ABP框架都已经有了。

先看看结果吧。

 

英文的界面

 

中文的界面

 

配置流程如下:

首先在Localization目录下新建一个对应的json文件,里面存放对应变量的本地化字符串,命名规则就是 应用名-本地化简称.json

比如我的应用名叫做SimpTaskApp(没错,就是abp的入门教程的工程),然后中文的简写是zh,所以我的json文件就是SimpleTaskApp-zh.json。

 

然后来看看内容

json里主要是两个属性culture和texts。

culture对应文化的简称。中文zh   英文en 土耳其文tr

texts对应字符串变量。

 

这里配置好以后就在XXXLocalizationConfigurer.cs里添加语言。XXX是应用名

位置在这里。

 

localizationConfiguration.Languages集合里添加一个LanguageInfo对象,参数3个,第一个是语言简写,如中文是zh,第二个是显示的名称,第三个是图标,一般是国家或地区的标志,规则是famfamfam-flags XX,XX是国家或地区的简写,如中国 cn

 这段就是那个下拉选择语言的前端代码,遍历Model里的Language集合,加入下拉菜单。

 1 @model Acme.SimpleTaskApp.Web.Views.Shared.Components.LanguageSelection.LanguageSelectionViewModel
 2 <li class="dropdown">
 3     <a href="#" class="dropdown-toggle" data-toggle="dropdown">
 4         <div class="@Model.CurrentLanguage.Icon"></div>
 5         <span>@Model.CurrentLanguage.DisplayName</span>
 6         <b class="caret"></b>
 7     </a>
 8     <ul class="dropdown-menu">
 9         @foreach (var language in Model.Languages)
10         {
11             if (language.Name != Model.CurrentLanguage.Name)
12             {
13                 <li><a href="@Url.Action("ChangeCulture", "AbpLocalization")?cultureName=@(language.Name)&returnUrl=@(Model.CurrentUrl)"><div class="@language.Icon"></div> @language.DisplayName</a></li>
14             }
15         }
16     </ul>
17 </li>

 

 

最后的效果就如下

 

 

 

 

附录,famfamfam的国旗标志及对应的代码。图标icon包下载连接

国家或地区代码是ISO 3166-1 alpha-2

 

CodeCountry nameYearccTLDISO 3166-2Notes
Andorra1974.adISO 3166-2:AD 
AEUnited Arab Emirates1974.aeISO 3166-2:AE 
AFAfghanistan1974.afISO 3166-2:AF 
AGAntigua and Barbuda1974.agISO 3166-2:AG 
AIAnguilla1985.aiISO 3166-2:AIAI previously represented French Afar and Issas
ALAlbania1974.alISO 3166-2:AL 
AMArmenia1992.amISO 3166-2:AM 
AOAngola .aoISO 3166-2:AO 
AQAntarctica1974.aqISO 3166-2:AQCovers the territories south of 60° south latitude
Code taken from name in French: Antarctique
ARArgentina1974.arISO 3166-2:AR 
ASAmerican Samoa1974.asISO 3166-2:AS 
ATAustria1974.atISO 3166-2:AT 
AUAustralia1974.auISO 3166-2:AUIncludes the Ashmore and Cartier Islands and the Coral Sea Islands
AWAruba1986.awISO 3166-2:AW 
AXAland Islands !Åland Islands2004.axISO 3166-2:AXAn autonomous province of Finland
AZAzerbaijan1992.azISO 3166-2:AZ 
BABosnia and Herzegovina1992.baISO 3166-2:BA 
BBBarbados1974.bbISO 3166-2:BB 
BDBangladesh1974.bdISO 3166-2:BD 
BEBelgium1974.beISO 3166-2:BE 
BFBurkina Faso1984.bfISO 3166-2:BFName changed from Upper Volta (HV)
BGBulgaria1974.bgISO 3166-2:BG 
BHBahrain1974.bhISO 3166-2:BH 
BIBurundi1974.biISO 3166-2:BI 
BJBenin1977.bjISO 3166-2:BJName changed from Dahomey (DY)
BLSaint Barthélemy2007.blISO 3166-2:BL 
BMBermuda1974.bmISO 3166-2:BM 
BNBrunei Darussalam1974.bnISO 3166-2:BNISO country name follows UN designation (common name: Brunei)
BOBolivia, Plurinational State of1974.boISO 3166-2:BOISO country name follows UN designation (common name and previous ISO country name: Bolivia)
BQBonaire, Sint Eustatius and Saba2010.bqISO 3166-2:BQConsists of three Caribbean "special municipalities", which are part of the Netherlands proper: Bonaire, Sint Eustatius, and Saba (the BES Islands)
Previous ISO country name: Bonaire, Saint Eustatius and Saba
BQ previously represented British Antarctic Territory
BRBrazil1974.brISO 3166-2:BR 
BSBahamas1974.bsISO 3166-2:BS 
BTBhutan1974.btISO 3166-2:BT 
BVBouvet Island1974.bvISO 3166-2:BVBelongs to Norway
BWBotswana1974.bwISO 3166-2:BW 
BYBelarus1974.byISO 3166-2:BYCode taken from previous ISO country name: Byelorussian SSR (now assigned ISO 3166-3 code BYAA)
Code assigned as the country was already a UN member since 1945[16]
BZBelize1974.bzISO 3166-2:BZ 
CACanada1974.caISO 3166-2:CA 
CCCocos (Keeling) Islands1974.ccISO 3166-2:CC 
CDCongo, the Democratic Republic of the1997.cdISO 3166-2:CDName changed from Zaire (ZR)
CFCentral African Republic1974.cfISO 3166-2:CF 
CGCongo1974.cgISO 3166-2:CG 
CHSwitzerland1974.chISO 3166-2:CHCode taken from name in Latin: Confoederatio Helvetica
CICote d'Ivoire !Côte d'Ivoire1974.ciISO 3166-2:CIISO country name follows UN designation (common name: Ivory Coast)
CKCook Islands1974.ckISO 3166-2:CK 
CLChile1974.clISO 3166-2:CL 
CMCameroon1974.cmISO 3166-2:CM 
CNChina1974.cnISO 3166-2:CN 
COColombia1974.coISO 3166-2:CO 
CRCosta Rica1974.crISO 3166-2:CR 
CUCuba1974.cuISO 3166-2:CU 
CVCabo Verde1974.cvISO 3166-2:CV 
CWCuraçao2010.cwISO 3166-2:CW 
CXChristmas Island1974.cxISO 3166-2:CX 
CYCyprus1974.cyISO 3166-2:CY 
CZCzechia1993.czISO 3166-2:CZPrevious ISO country name: Czech Republic
DEGermany1974.deISO 3166-2:DECode taken from name in German: Deutschland
Code used for West Germany before 1990 (previous ISO country name: Germany, Federal Republic of)
DJDjibouti1977.djISO 3166-2:DJName changed from French Afar and Issas (AI)
DKDenmark1974.dkISO 3166-2:DK 
DMDominica1974.dmISO 3166-2:DM 
DODominican Republic1974.doISO 3166-2:DO 
DZAlgeria1974.dzISO 3166-2:DZCode taken from name in Kabyle: Dzayer
ECEcuador1974.ecISO 3166-2:EC 
EEEstonia1992.eeISO 3166-2:EECode taken from name in Estonian: Eesti
EGEgypt1974.egISO 3166-2:EG 
EHWestern Sahara1974.ehISO 3166-2:EHPrevious ISO country name: Spanish Sahara (code taken from name in Spanish: Sahara español)
EREritrea1993.erISO 3166-2:ER 
ESSpain1974.esISO 3166-2:ESCode taken from name in Spanish: España
ETEthiopia1974.etISO 3166-2:ET 
FIFinland1974.fiISO 3166-2:FI 
FJFiji1974.fjISO 3166-2:FJ 
FKFalkland Islands (Malvinas)1974.fkISO 3166-2:FKISO country name follows UN designation due to the Falkland Islands sovereignty dispute (local common name: Falkland Islands)[17]
FMMicronesia, Federated States of1986.fmISO 3166-2:FMPrevious ISO country name: Micronesia
FOFaroe Islands1974.foISO 3166-2:FOCode taken from name in Faroese: Føroyar
FRFrance1974.frISO 3166-2:FRIncludes Clipperton Island
GAGabon1974.gaISO 3166-2:GA 
GBUnited Kingdom of Great Britain and Northern Ireland1974.gb
(.uk)
ISO 3166-2:GBCode taken from Great Britain (from official name: United Kingdom of Great Britain and Northern Ireland)[18]
.uk is the primary ccTLD of the United Kingdom instead of .gb (see code UK, which is exceptionally reserved)
GDGrenada1974.gdISO 3166-2:GD 
GEGeorgia1992.geISO 3166-2:GEGE previously represented Gilbert and Ellice Islands
GFFrench Guiana1974.gfISO 3166-2:GFCode taken from name in French: Guyane française
GGGuernsey2006.ggISO 3166-2:GGa British Crown dependency
GHGhana1974.ghISO 3166-2:GH 
GIGibraltar1974.giISO 3166-2:GI 
GLGreenland1974.glISO 3166-2:GL 
GMGambia1974.gmISO 3166-2:GM 
GNGuinea1974.gnISO 3166-2:GN 
GPGuadeloupe1974.gpISO 3166-2:GP 
GQEquatorial Guinea1974.gqISO 3166-2:GQCode taken from name in French: Guinée équatoriale
GRGreece1974.grISO 3166-2:GR 
GSSouth Georgia and the South Sandwich Islands1993.gsISO 3166-2:GS 
GTGuatemala1974.gtISO 3166-2:GT 
GUGuam1974.guISO 3166-2:GU 
GWGuinea-Bissau1974.gwISO 3166-2:GW 
GYGuyana1974.gyISO 3166-2:GY 
HKHong Kong1974.hkISO 3166-2:HK 
HMHeard Island and McDonald Islands1974.hmISO 3166-2:HM 
HNHonduras1974.hnISO 3166-2:HN 
HRCroatia1992.hrISO 3166-2:HRCode taken from name in Croatian: Hrvatska
HTHaiti1974.htISO 3166-2:HT 
HUHungary1974.huISO 3166-2:HU 
IDIndonesia1974.idISO 3166-2:ID 
IEIreland1974.ieISO 3166-2:IE 
ILIsrael1974.ilISO 3166-2:IL 
IMIsle of Man2006.imISO 3166-2:IMa British Crown dependency
INIndia1974.inISO 3166-2:IN 
IOBritish Indian Ocean Territory1974.ioISO 3166-2:IO 
IQIraq1974.iqISO 3166-2:IQ 
IRIran, Islamic Republic of1974.irISO 3166-2:IRISO country name follows UN designation (common name: Iran)
ISIceland1974.isISO 3166-2:ISCode taken from name in Icelandic: Ísland
ITItaly1974.itISO 3166-2:IT 
JEJersey2006.jeISO 3166-2:JEa British Crown dependency
JMJamaica1974.jmISO 3166-2:JM 
JOJordan1974.joISO 3166-2:JO 
JPJapan1974.jpISO 3166-2:JP 
KEKenya1974.keISO 3166-2:KE 
KGKyrgyzstan1992.kgISO 3166-2:KG 
KHCambodia1974.khISO 3166-2:KHCode taken from former name: Khmer Republic
Previous ISO country name: Kampuchea
KIKiribati1979.kiISO 3166-2:KI 
KMComoros1974.kmISO 3166-2:KMCode taken from name in Comorian: Komori
KNSaint Kitts and Nevis1974.knISO 3166-2:KNPrevious ISO country name: Saint Kitts-Nevis-Anguilla
KPKorea, Democratic People's Republic of1974.kpISO 3166-2:KPISO country name follows UN designation (common name: North Korea)
KRKorea, Republic of1974.krISO 3166-2:KRISO country name follows UN designation (common name: South Korea)
KWKuwait1974.kwISO 3166-2:KW 
KYCayman Islands1974.kyISO 3166-2:KY 
KZKazakhstan1992.kzISO 3166-2:KZPrevious ISO country name: Kazakstan
LALao People's Democratic Republic1974.laISO 3166-2:LAISO country name follows UN designation (common name: Laos)
LBLebanon1974.lbISO 3166-2:LB 
LCSaint Lucia1974.lcISO 3166-2:LC 
LILiechtenstein1974.liISO 3166-2:LI 
LKSri Lanka1974.lkISO 3166-2:LK 
LRLiberia1974.lrISO 3166-2:LR 
LSLesotho1974.lsISO 3166-2:LS 
LTLithuania1992.ltISO 3166-2:LT 
LULuxembourg1974.luISO 3166-2:LU 
LVLatvia1992.lvISO 3166-2:LV 
LYLibya1974.lyISO 3166-2:LYPrevious ISO country name: Libyan Arab Jamahiriya
MAMorocco1974.maISO 3166-2:MACode taken from name in French: Maroc
MCMonaco1974.mcISO 3166-2:MC 
MDMoldova, Republic of1992.mdISO 3166-2:MDISO country name follows UN designation (common name and previous ISO country name: Moldova)
MEMontenegro2006.meISO 3166-2:ME 
MFSaint Martin (French part)2007.mfISO 3166-2:MFThe Dutch part of Saint Martin island is assigned code SX
MGMadagascar1974.mgISO 3166-2:MG 
MHMarshall Islands1986.mhISO 3166-2:MH 
MKMacedonia, the former Yugoslav Republic of1993.mkISO 3166-2:MKISO country name follows UN designation (due to Macedonia naming dispute; official name used by country itself: Republic of Macedonia)
Code taken from name in Macedonian: Makedonija
MLMali1974.mlISO 3166-2:ML 
MMMyanmar1989.mmISO 3166-2:MMName changed from Burma (BU)
MNMongolia1974.mnISO 3166-2:MN 
MOMacao1974.moISO 3166-2:MOPrevious ISO country name: Macau
MPNorthern Mariana Islands1986.mpISO 3166-2:MP 
MQMartinique1974.mqISO 3166-2:MQ 
MRMauritania1974.mrISO 3166-2:MR 
MSMontserrat1974.msISO 3166-2:MS 
MTMalta1974.mtISO 3166-2:MT 
MUMauritius1974.muISO 3166-2:MU 
MVMaldives1974.mvISO 3166-2:MV 
MWMalawi1974.mwISO 3166-2:MW 
MXMexico1974.mxISO 3166-2:MX 
MYMalaysia1974.myISO 3166-2:MY 
MZMozambique1974.mzISO 3166-2:MZ 
NANamibia1974.naISO 3166-2:NA 
NCNew Caledonia1974.ncISO 3166-2:NC 
NENiger1974.neISO 3166-2:NE 
NFNorfolk Island1974.nfISO 3166-2:NF 
NGNigeria1974.ngISO 3166-2:NG 
NINicaragua1974.niISO 3166-2:NI 
NLNetherlands1974.nlISO 3166-2:NL 
NONorway1974.noISO 3166-2:NO 
NPNepal1974.npISO 3166-2:NP 
NRNauru1974.nrISO 3166-2:NR 
NUNiue1974.nuISO 3166-2:NU 
NZNew Zealand1974.nzISO 3166-2:NZ 
OMOman1974.omISO 3166-2:OM 
PAPanama1974.paISO 3166-2:PA 
PEPeru1974.peISO 3166-2:PE 
PFFrench Polynesia1974.pfISO 3166-2:PFCode taken from name in French: Polynésie française
PGPapua New Guinea1974.pgISO 3166-2:PG 
PHPhilippines1974.phISO 3166-2:PH 
PKPakistan1974.pkISO 3166-2:PK 
PLPoland1974.plISO 3166-2:PL 
PMSaint Pierre and Miquelon1974.pmISO 3166-2:PM 
PNPitcairn1974.pnISO 3166-2:PN 
PRPuerto Rico1974.prISO 3166-2:PR 
PSPalestine, State of1999.psISO 3166-2:PSPrevious ISO country name: Palestinian Territory, Occupied
Consists of the West Bank and the Gaza Strip
PTPortugal1974.ptISO 3166-2:PT 
PWPalau1986.pwISO 3166-2:PW 
PYParaguay1974.pyISO 3166-2:PY 
QAQatar1974.qaISO 3166-2:QA 
REReunion !Réunion1974.reISO 3166-2:RE 
RORomania1974.roISO 3166-2:RO 
RSSerbia2006.rsISO 3166-2:RS 
RURussian Federation1992.ruISO 3166-2:RUISO country name follows UN designation (common name: Russia)
RWRwanda1974.rwISO 3166-2:RW 
SASaudi Arabia1974.saISO 3166-2:SA 
SBSolomon Islands1974.sbISO 3166-2:SBCode taken from former name: British Solomon Islands
SCSeychelles1974.scISO 3166-2:SC 
SDSudan1974.sdISO 3166-2:SD 
SESweden1974.seISO 3166-2:SE 
SGSingapore1974.sgISO 3166-2:SG 
SHSaint Helena, Ascension and Tristan da Cunha1974.shISO 3166-2:SHPrevious ISO country name: Saint Helena
SISlovenia1992.siISO 3166-2:SI 
SJSvalbard and Jan Mayen1974.sjISO 3166-2:SJConsists of two arctic territories of Norway: Svalbard and Jan Mayen
SKSlovakia1993.skISO 3166-2:SKSK previously represented Sikkim
SLSierra Leone1974.slISO 3166-2:SL 
SMSan Marino1974.smISO 3166-2:SM 
SNSenegal1974.snISO 3166-2:SN 
SOSomalia1974.soISO 3166-2:SO 
SRSuriname1974.srISO 3166-2:SR 
SSSouth Sudan2011.ssISO 3166-2:SS 
STSao Tome and Principe1974.stISO 3166-2:ST 
SVEl Salvador1974.svISO 3166-2:SV 
SXSint Maarten (Dutch part)2010.sxISO 3166-2:SXThe French part of Saint Martin island is assigned code MF
SYSyrian Arab Republic1974.syISO 3166-2:SYISO country name follows UN designation (common name: Syria)
SZSwaziland1974.szISO 3166-2:SZ 
TCTurks and Caicos Islands1974.tcISO 3166-2:TC 
TDChad1974.tdISO 3166-2:TDCode taken from name in French: Tchad
TFFrench Southern Territories1979.tfISO 3166-2:TFCovers the French Southern and Antarctic Lands except Adélie Land
Code taken from name in French: Terres australes françaises
TGTogo1974.tgISO 3166-2:TG 
THThailand1974.thISO 3166-2:TH 
TJTajikistan1992.tjISO 3166-2:TJ 
TKTokelau1974.tkISO 3166-2:TK 
TLTimor-Leste2002.tlISO 3166-2:TLName changed from East Timor (TP)
TMTurkmenistan1992.tmISO 3166-2:TM 
TNTunisia1974.tnISO 3166-2:TN 
TOTonga1974.toISO 3166-2:TO 
TRTurkey1974.trISO 3166-2:TR 
TTTrinidad and Tobago1974.ttISO 3166-2:TT 
TVTuvalu1977.tvISO 3166-2:TV 
TWTaiwan, Province of China1974.twISO 3166-2:TWCovers the current jurisdiction of the Republic of China
ISO country name follows UN designation (due to political status of Taiwan within the UN)[18] (common name: Taiwan)
TZTanzania, United Republic of1974.tzISO 3166-2:TZISO country name follows UN designation (common name: Tanzania)
UAUkraine1974.uaISO 3166-2:UAPrevious ISO country name: Ukrainian SSR
Code assigned as the country was already a UN member since 1945[16]
UGUganda1974.ugISO 3166-2:UG 
UMUnited States Minor Outlying Islands1986.umISO 3166-2:UMConsists of nine minor insular areas of the United States: Baker Island, Howland Island, Jarvis Island, Johnston Atoll, Kingman Reef, Midway Islands, Navassa Island, Palmyra Atoll, and Wake Island
USUnited States of America1974.usISO 3166-2:US 
UYUruguay1974.uyISO 3166-2:UY 
UZUzbekistan1992.uzISO 3166-2:UZ 
VAHoly See1974.vaISO 3166-2:VACovers Vatican City, territory of the Holy See
Previous ISO country name: Vatican City State (Holy See)
VCSaint Vincent and the Grenadines1974.vcISO 3166-2:VC 
VEVenezuela, Bolivarian Republic of1974.veISO 3166-2:VEISO country name follows UN designation (common name and previous ISO country name: Venezuela)
VGVirgin Islands, British1974.vgISO 3166-2:VG 
VIVirgin Islands, U.S.1974.viISO 3166-2:VI 
VNViet Nam1974.vnISO 3166-2:VNISO country name follows UN designation (common name: Vietnam) Code used for Republic of Viet Nam (Common Name:South Vietnam) before 1977
VUVanuatu1980.vuISO 3166-2:VUName changed from New Hebrides (NH)
WFWallis and Futuna1974.wfISO 3166-2:WF 
WSSamoa1974.wsISO 3166-2:WSCode taken from former name: Western Samoa
YEYemen1974.yeISO 3166-2:YEPrevious ISO country name: Yemen, Republic of
Code used for North Yemen before 1990
YTMayotte1993.ytISO 3166-2:YT 
ZASouth Africa1974.zaISO 3166-2:ZACode taken from name in Dutch: Zuid-Afrika
ZMZambia1974.zmISO 3166-2:ZM 
ZWZimbabwe1980.zwISO 3166-2:ZWName changed from Southern Rhodesia (RH)

此段摘自http://www.famfamfam.com/lab/icons/flags/和维基百科

 

转载于:https://www.cnblogs.com/turingguo/p/8391490.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值