In this article, we will learn a step by step process to create a multilingual webform application using Asp.net. Multilingual means we can implement the website in multiple languages.
In today's world to grow customer ineraction, everyone needs to implement this procedure in their applications.
Here in the dropdown list we added a value that is very important for translating langulages. It must satisfy the ISO Language Code extension. For example: To make a Hindi translation we added value "hi-IN" code.
- <div style="text-align:right;">
- <asp:DropDownList ID="ddLang" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddLang_SelectedIndexChanged">
- <asp:ListItem Value="en-US" Text="English" />
- <asp:ListItem Value="fr-FR" Text="français" />
- <asp:ListItem Value="hi-IN" Text="เคนเคฟเคเคฆเฅ" />
- <asp:ListItem Value="or-IN" Text="เฌเฌกเฌฟเฌ" />
- </asp:DropDownList>
- </div>
Language
| ISO Code 2
| ISO Code 3
|
Abkhazian |
ab |
abk |
Afar |
aa |
aar |
Afrikaans |
af |
afr |
Albanian |
sq |
alb/sqi* |
Amharic |
am |
amh |
Arabic |
ar |
ara |
Aragonese |
an |
arg |
Armenian |
hy |
arm/hye* |
Assamese |
as |
asm |
Avestan |
ae |
ave |
Aymara |
ay |
aym |
Azerbaijani |
az |
aze |
Bashkir |
ba |
bak |
Basque |
eu |
baq/eus* |
Belarusian |
be |
bel |
Bengali |
bn |
ben |
Bihari |
bh |
bih |
Bislama |
bi |
bis |
Bosnian |
bs |
bos |
Breton |
br |
bre |
Bulgarian |
bg |
bul |
Burmese |
my |
bur/mya* |
Catalan |
ca |
cat |
Chamorro |
ch |
cha |
Chechen |
ce |
che |
Chinese |
zh |
chi/zho* |
Church Slavic; Slavonic; Old Bulgarian |
cu |
chu |
Chuvash |
cv |
chv |
Cornish |
kw |
cor |
Corsican |
co |
cos |
Croatian |
hr |
scr/hrv* |
Czech |
cs |
cze/ces* |
Danish |
da |
dan |
Divehi; Dhivehi; Maldivian |
dv |
div |
Dutch |
nl |
dut/nld* |
Dzongkha |
dz |
dzo |
English |
en |
eng |
Esperanto |
eo |
epo |
Estonian |
et |
est |
Faroese |
fo |
fao |
Fijian |
fj |
fij |
Finnish |
fi |
fin |
French |
fr |
fre/fra* |
Gaelic; Scottish Gaelic |
gd |
gla |
Galician |
gl |
glg |
Georgian |
ka |
geo/kat* |
German |
de |
ger/deu* |
Greek, Modern (1453-) |
el |
gre/ell* |
Guarani |
gn |
grn |
Gujarati |
gu |
guj |
Haitian; Haitian Creole |
ht |
hat |
Hausa |
ha |
hau |
Hebrew |
he |
heb |
Herero |
hz |
her |
Hindi |
hi |
hin |
Hiri Motu |
ho |
hmo |
Hungarian |
hu |
hun |
Icelandic |
is |
ice/isl* |
Ido |
io |
ido |
Indonesian |
id |
ind |
Interlingua (International Auxiliary Language Association) |
ia |
ina |
Interlingue |
ie |
ile |
Inuktitut |
iu |
iku |
Inupiaq |
ik |
ipk |
Irish |
ga |
gle |
Italian |
it |
ita |
Japanese |
ja |
jpn |
Javanese |
jv |
jav |
Kalaallisut |
kl |
kal |
Kannada |
kn |
kan |
Kashmiri |
ks |
kas |
Kazakh |
kk |
kaz |
Khmer |
km |
khm |
Kikuyu; Gikuyu |
ki |
kik |
Kinyarwanda |
rw |
kin |
Kirghiz |
ky |
kir |
Komi |
kv |
kom |
Korean |
ko |
kor |
Kuanyama; Kwanyama |
kj |
kua |
Kurdish |
ku |
kur |
Lao |
lo |
lao |
Latin |
la |
lat |
Latvian |
lv |
lav |
Limburgan; Limburger; Limburgish |
li |
lim |
Lingala |
ln |
lin |
Lithuanian |
lt |
lit |
Luxembourgish; Letzeburgesch |
lb |
ltz |
Macedonian |
mk |
mac/mkd* |
Malagasy |
mg |
mlg |
Malay |
ms |
may/msa* |
Malayalam |
ml |
mal |
Maltese |
mt |
mlt |
Manx |
gv |
glv |
Maori |
mi |
mao/mri* |
Marathi |
mr |
mar |
Marshallese |
mh |
mah |
Moldavian |
mo |
mol |
Mongolian |
mn |
mon |
Nauru |
na |
nau |
Navaho, Navajo |
nv |
nav |
Ndebele, North |
nd |
nde |
Ndebele, South |
nr |
nbl |
Ndonga |
ng |
ndo |
Nepali |
ne |
nep |
Northern Sami |
se |
sme |
Norwegian |
no |
nor |
Norwegian Bokmal |
nb |
nob |
Norwegian Nynorsk |
nn |
nno |
Nyanja; Chichewa; Chewa |
ny |
nya |
Occitan (post 1500); Provencal |
oc |
oci |
Oriya |
or |
ori |
Oromo |
om |
orm |
Ossetian; Ossetic |
os |
oss |
Pali |
pi |
pli |
Panjabi |
pa |
pan |
Persian |
fa |
per/fas* |
Polish |
pl |
pol |
Portuguese |
pt |
por |
Pushto |
ps |
pus |
Quechua |
qu |
que |
Raeto-Romance |
rm |
roh |
Romanian |
ro |
rum/ron* |
Rundi |
rn |
run |
Russian |
ru |
rus |
Samoan |
sm |
smo |
Sango |
sg |
sag |
Sanskrit |
sa |
san |
Sardinian |
sc |
srd |
Serbian |
sr |
scc/srp* |
Shona |
sn |
sna |
Sichuan Yi |
ii |
iii |
Sindhi |
sd |
snd |
Sinhala; Sinhalese |
si |
sin |
Slovak |
sk |
slo/slk* |
Slovenian |
sl |
slv |
Somali |
so |
som |
Sotho, Southern |
st |
sot |
Spanish; Castilian |
es |
spa |
Sundanese |
su |
sun |
Swahili |
sw |
swa |
Swati |
ss |
ssw |
Swedish |
sv |
swe |
Tagalog |
tl |
tgl |
Tahitian |
ty |
tah |
Tajik |
tg |
tgk |
Tamil |
ta |
tam |
Tatar |
tt |
tat |
Telugu |
te |
tel |
Thai |
th |
tha |
Tibetan |
bo |
tib/bod* |
Tigrinya |
ti |
tir |
Tonga (Tonga Islands) |
to |
ton |
Tsonga |
ts |
tso |
Tswana |
tn |
tsn |
Turkish |
tr |
tur |
Turkmen |
tk |
tuk |
Twi |
tw |
twi |
Uighur |
ug |
uig |
Ukrainian |
uk |
ukr |
Urdu |
ur |
urd |
Uzbek |
uz |
uzb |
Vietnamese |
vi |
vie |
Volapuk |
vo |
vol |
Walloon |
wa |
wln |
Welsh |
cy |
wel/cym* |
Western Frisian |
fy |
fry |
Wolof |
wo |
wol |
Xhosa |
xh |
xho |
Yiddish |
yi |
yid |
Yoruba |
yo |
yor |
Zhuang; Chuang |
za |
zha |
Zulu |
zu |
zul |
Step 2
In this step, we add a ASP.NET Folder "App_GlobalResources" for saving language resource file.
Go to Solution Explorer > Right Click on Project name form Solution Explorer > Add > Add ASP.NET Folder > App_GlobalResources.
Step 3
In this step, we add Resources file for saving different languages under "App_GlobalResources" Folder.
Right Click on "App_GlobalResources" Folder form Solution Explorer > Add > New Item > Select "Resources File" under Visual C# > Enter Name (Like "Lang.or-IN.resx") > Add
By using the same process we need to add 3 different resource files as mentioned below.
Language
| File Name
|
English |
Lang.en-US.resx |
French |
Lang.fr-FR.resx |
Hindi |
Lang.hi-IN.resx |
Then we need to configure resouce files as mentioned beow. For example: for Lang.or-IN.resx,
Here name means the string name passed in resource manager and value means the string name against this resource manager, whatever value in any language that is translated into the language as mentioned. Here in web pabe page Name is shown in English language but after selection of Oriya language the Name is translated into "เฌจเฌพเฌฎ".
Then change Build Action to "Embedded Resource" of added resource files. To do so, Select Resource file > Right Click go to Property> Change Build Action to Embedded Resource.
Step 4
In this step, we need to add code in code behind file for translating languages based on selected languaged with ISO language code.
Code Ref
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Resources;
- using System.Globalization;
- using System.Threading;
- using System.Reflection;
-
- namespace multilingualAsp
- {
- public partial class UserSignUp : System.Web.UI.Page
- {
- ResourceManager rm;
- CultureInfo ci;
-
- protected void Page_Load(object sender, EventArgs e)
- {
- if (Session["Lang"] == null)
- {
- Session["Lang"] = Request.UserLanguages[0];
- }
-
- if (!IsPostBack)
- {
- LoadString();
- }
- }
-
- private void LoadString()
- {
- Thread.CurrentThread.CurrentCulture = new CultureInfo(Session["Lang"].ToString());
- rm = new ResourceManager("multilingualAsp.App_GlobalResources.Lang", Assembly.GetExecutingAssembly());
- ci = Thread.CurrentThread.CurrentCulture;
-
- lblName.Text = rm.GetString("Name", ci);
- lblAddress.Text = rm.GetString("Address", ci);
- lblState.Text = rm.GetString("State", ci);
- lblCountry.Text = rm.GetString("Country", ci);
- btnSave.Text = rm.GetString("Save", ci);
- btnCancel.Text = rm.GetString("Cancel", ci);
- lblMyName.Text = rm.GetString("Application", ci);
-
- lblh1.Text = rm.GetString("headerone", ci);
- lblh2.Text = rm.GetString("headertwo", ci);
- lblp1.Text = rm.GetString("paraone", ci);
- lblp2.Text = rm.GetString("paratwo", ci);
- }
-
- protected void ddLang_SelectedIndexChanged(object sender, EventArgs e)
- {
- Session["Lang"] = ddLang.SelectedValue;
- LoadString();
- }
- }
- }
Code Description
Here I added code with description in green comment mark "//" at one place for better and faster understanding.
OUTPUT
The language selection is shown as below:
The content is translated into English.
The content is translated into French.
The content is translated into Hindi.
The content is translated into Odia (The Mother language of the Odisha state, India).
Link To Source Code,
In this article, we have learned,
- Introduction to multilingual Asp.net Web Application
- Configure resource files in Asp.net Global resource folder
- Way to set-up ISO Language code for translating content
- Setup resource manager in code behind(C#) based on resource files