ASP.Net Usercontrol (Resource files) localization with umbraco
Hi Everyone!
Now I try to describe my problem... Hope somebody can help me!
I need to localize asp.net user control, which used on one of umbraco
pages. I have almost no experience in development for umbraco, so I
tried to localize it in .NET way.
protectedvoidPage_Load(object sender,EventArgs e) { var language = page.Request.QueryString.Get(GeneralResources.LanguageParam);
// if no 'lang' param in request then try to get it from session if(String.IsNullOrEmpty(language)) { language =(string)page.Session[GeneralResources.LanguageParam]; }
There are files MyControl.ascx.resx, MyControl.ascx.de-DE.resx,
MyControl.ascx.en-US.resx MyControl.ascx.da-DK.resx in
App_LocalResources folder.
LanguageLabel on page shows right culture, but localized values load from MyControl.ascx.resx.
If I delete MyControl.ascx.resx then no text is showing on page at all!
Can anybodysuggest how to localize usercontrol with umbraco? I believe this question was posted previously, but i couldnt get the solution.
But let me put my question in more detail. i have an user control, named OrderingControl.ascx. I need to use resource files to have all the text's coming from the respective resource files. What I would need is, at runtime My site will get the culture info. Which I need to set to the user control so that appropriate resx file is referred and appropriate language text is shown.
So this can be achieved with the following line of code in .Net aspx page,
protectedoverridevoid InitializeCulture() {
CultureInfo cultureInfo = null; if (Request.UserLanguages == null) return; if (Request.UserLanguages.GetLength(0) <1) return;
foreach(string userLanguage in Request.UserLanguages) {
but here in umbraco we dont have the aspx page. And how would I set at runtime to the usercontrol, so that the appropriate resx(resource) file is used. Also I would need to know how these .resx files are deployed in umbraco?
i'm new to umbraco, any help would be appreciated.
I found the answer here from the below video from Umbraco. Thanks Everyone for the Inputs. It was quite simple to achieve Globalization/Localization using .Net User controls + Resource Files(.resx)
ASP.Net Usercontrol (Resource files) localization with umbraco
Hi Everyone!
Now I try to describe my problem... Hope somebody can help me!
I need to localize asp.net user control, which used on one of umbraco pages. I have almost no experience in development for umbraco, so I tried to localize it in .NET way.
In MyControl.ascx markup:
And in behind code:
There are files MyControl.ascx.resx, MyControl.ascx.de-DE.resx, MyControl.ascx.en-US.resx MyControl.ascx.da-DK.resx in App_LocalResources folder.
LanguageLabel on page shows right culture, but localized values load from MyControl.ascx.resx. If I delete MyControl.ascx.resx then no text is showing on page at all!
Can anybodysuggest how to localize usercontrol with umbraco? I believe this question was posted previously, but i couldnt get the solution.
Thanks in Advance
Regards,
Santhosh
i use dictionaryitems for this,
quickly (not foulproof-version):
Kows, Thanks for a quick reply.
But let me put my question in more detail. i have an user control, named OrderingControl.ascx. I need to use resource files to have all the text's coming from the respective resource files. What I would need is, at runtime My site will get the culture info. Which I need to set to the user control so that appropriate resx file is referred and appropriate language text is shown.
So this can be achieved with the following line of code in .Net aspx page,
protected override void InitializeCulture()
{
CultureInfo cultureInfo = null;
if (Request.UserLanguages == null) return;
if (Request.UserLanguages.GetLength(0) <1) return;
foreach(string userLanguage in Request.UserLanguages)
{
cultureInfo = GetCultureInfo(userLanguage,true);
if (cultureInfo != null)
{
Thread.CurrentThread.CurrentUICulture = cultureInfo;
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(cultureInfo.Name);
break;
}
}
}
protected virtual CultureInfo GetCultureInfo(string userLanguage,bool useUserOverride)
{
int semiColonIndex = userLanguage.IndexOf(";");
try
{
if (semiColonIndex != -1)
{
userLanguage = userLanguage.Substring(0,semiColonIndex);
}
return new CultureInfo(userLanguage,useUserOverride);
}
catch (ArgumentException) { return null; }
}
but here in umbraco we dont have the aspx page. And how would I set at runtime to the usercontrol, so that the appropriate resx(resource) file is used. Also I would need to know how these .resx files are deployed in umbraco?
i'm new to umbraco, any help would be appreciated.
Thanks in Advance,
Regards
Santhosh
Hi Santhosh,
If you want to use the .Net resources, you can also set the culture in the global.asax file, in the Application_BeginRequest method.
Cheers,
Michael.
I found the answer here from the below video from Umbraco. Thanks Everyone for the Inputs. It was quite simple to achieve Globalization/Localization using .Net User controls + Resource Files(.resx)
Please Look at the below video (Pls look till the end).
http://umbraco.com/help-and-support/video-tutorials/introduction-to-umbraco/developer-introduction/using-net-user-controls
is working on a reply...