c# - Multi language, using Resources on server always gives server language -


tl;tr: using multi language resources, class library keeps using server language instead if user decided language (url parameter).

environment: asp.net 4.5.2, visual studio 2015 rc.

so have pretty big website setup in multi language, using resources. have separate project in solution contains .resx files 2 languages. default language dutch, second english, resource files named: resources.resx , resources-en.resx.

i determine language url, have localization attribute, added in filterconfig , used in mvc routing. (link below)

so website example.com/ give dutch, example.com/en give english.

there 2 more projects in solution. 1 class library, 1 mvc application , previous mentioned language project.

this works pretty well, can call resources.resources.xx every point want. models inside class library , have multi language dataannotations work correctly in both languages, can throw exceptions multi language error message comes in correct language.

yet have 1 issue (else wasn't here, right?).

based on selecting products, additional costs added shopping cart. these dynamically added shopping cart , saved in database. description , title these additional costs use these resources, yet come in english (not selected language!). happens inside class library, , depending on server language, uses resource language.

same goes generating invoices, uses resources project, use server language determine text get. when test locally (on computer language set dutch) gives additional costs description in dutch , invoice description in dutch well, when choosing english language, still gives in dutch, keeps server language.

so want code?

used this blog post localization setup (not advertising here, not mine)

so on every request, code executed:

            cultureinfo info = new cultureinfo(lang);//nl-nl or en-en             info.numberformat = numberinfo;             info.datetimeformat.dateseparator = "/";             info.datetimeformat.shortdatepattern = "dd/mm/yyyy";                 thread.currentthread.currentuiculture = info;             thread.currentthread.currentculture = info; 

little bit of code:

additionalcost adcost = new additionalcost() {     //unrelated stuff here     title = resources.resources.additionalcostsdeposittitle,     description = resources.resources.additionalcostsdepositdescription,     //unrelated stuff here }; 

when cultureinfo.currentculture nl-nl though entire website in english (because current url example.com/en).

hope got experience setting class libraries use multi language (for setting database attributes). have shared hosting, cannot control server, has multi language depending on users choice anyway. thanks!


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -