PDA

View Full Version : Resource files Asp.net Can not find


sebastijanp
09-26-2005, 12:13 PM
Hi!

I read the article:

http://msdn.microsoft.com/asp.net/community/authors/mlb/default.aspx?pull=/library/en-us/dnaspp/html/aspnet-globalarchi.asp

I have teh following structure of web app. myWebApp:
Inetpub
wwwroot [Folder]
myWebApp [Folder]
Cbp [Folder]
CbpDocumentsTree.aspx
CbpDocumentsTree.en-US.resx
CbpDocumentsTree.sr-SP-Latn.resx
Img [Folder]
Default.aspx

and created by the above article two resource embeded files:
CbpDocumentsTree.en-US.resx
CbpDocumentsTree.sr-SP-Latn.resx

In web.config I set:

<object id="basePage" abstract="true">
<property name="Master">
<ref object="masterPage"/>
</property>
<property name="LocaleResolver">
<object type="Spring.Web.Localization.Resolvers.CookieLocaleReso lver, Spring.Web"/>
</property>
</object>
<object type="~/Cbp/CbpDocumentsTree.aspx" parent="basePage">

</object>


Then I set on a button click on CbpDocumentsTree.aspx page:
protected override void OnInit(EventArgs e)
{
InitializeComponent();

this.english.Command += new CommandEventHandler(this.SetLanguage);
this.serbian.Command += new CommandEventHandler(this.SetLanguage);

base.OnInit(e);
}

private void SetLanguage(object sender, CommandEventArgs e)
{
this.UserLocale = new CultureInfo((string) e.CommandArgument);
}

But then when I click on a button:
<asp:ImageButton id="english" Runat="server" CommandArgument="en-US" ImageUrl=""></asp:ImageButton>
<asp:ImageButton id="slovenian" Runat="server" CommandArgument="sl"></asp:ImageButton>

The SetLanguage gets executed but nothing happens. It is because .net can not find resources:
CbpDocumentsTree.en-US.resx
CbpDocumentsTree.sr-SP-Latn.resx


DO I HAVE TO SET ALSO SOMETHING ELSE?

Thank you for your help. This Spring Web is Best!!!

Lp
S

Rick Evans
09-26-2005, 01:24 PM
Hi

You need to define an object in your context file that will actually go and lookup these resources; to wit...

<object id="messageSource" type="Spring.Context.Support.ResourceSetMessageSource, Spring.Core">
<property name="ResourceManagers">
<list>
<value>YOUR_NAMESPACE_HERE.CbpDocumentsTree, MyApp.Web</value>
</list>
</property>
</object>

This object definition needs to go in the same file as the rest of your objects; putting it in the same place as your page definitions will work fine.

You need to replace the YOUR_NAMESPACE_HERE placeholder that I used with the default namespace of your web application. If you right click on your web project in VS.NET 2003, and click Properties on the resulting popup menu, you will see a field in the table in the displayed dialog called Default Namespace. You need to insert that value in place of YOUR_NAMESPACE_HERE.

Do ping me back on this forum if you have any further issues.

Be advised that we are working on the documentation... it will be substantially improved prior to the 1.1 release, and there will also be an example application demonstrating all of these features that will be available for cribbing off of.

Ciao
Rick

sebastijanp
09-26-2005, 02:20 PM
I set:
<object id="messageSource" type="Spring.Context.Support.ResourceSetMessageSource, Spring.Core">
<property name="ResourceManagers">
<list>
<value>CbpWebSite.Common.Resources.CbpStrings, CbpWebSite</value>
<value>CbpWebSite.Cbp.CbpDocumentsTree, CbpWebSite</value>
</list>
</property>
</object>

CbpStrings is like global resorce... and CbpDocumentsTree is specific for individual page...

But then in:

protected override void OnPreRender(EventArgs e)
{
if (dataBinder.IsDataBound)
{
Trace.Write(traceCategory, "Bind Controls to Data Model");
dataBinder.BindData();
OnDataBound(EventArgs.Empty);
}
if (localizer.IsLocalized)
{
Trace.Write(traceCategory, "Apply Localized Resources");
localizer.ApplyResources(UserLocale);
}
base.OnPreRender(e);
}
/// <summary>
/// Returns true if page is localized, false otherwise.
/// </summary>
public bool IsLocalized
{
get { return (target.SupportedFeatures & Features.Localization) != 0; }
set
{
if (value == false)
{
target.SupportedFeatures &= ~Features.Localization;
}
}
}

IsLocalized returns false and that is why localizer.ApplyResources(UserLocale); does not get executed.

Is there some other feature that must I implemement?

Lp
S

sebastijanp
09-26-2005, 05:10 PM
Hi

I found the solution, I must put the default resx into web.config:
You should put that on web documentaion:

<object id="messageSource" type="Spring.Context.Support.ResourceSetMessageSource, Spring.Core">
<property name="ResourceManagers">
<list>
<value>CbpWebSite.Common.Resources.CbpStrings, CbpWebSite</value>
<value>CbpWebSite.Cbp.CbpDocumentsTree.aspx.rex, CbpWebSite</value>
<value>CbpWebSite.Cbp.CbpDocumentsTree, CbpWebSite</value>
</list>
</property>
</object>


Thank you for your help!

Lp
S

Rick Evans
09-26-2005, 06:41 PM
Indeed. Looks like you helped yourself there though :)

Thorough Spring.Web documentation is a priority for me (and the rest of the Spring.NET team) right now. I'm also working on the ASP.NET Spring.Web reference application (SpringAir) this evening, so that in future there will be something to look at for reference purposes.

I realise that doesn't help you right now, so thanks for your patience.

Ciao
Rick

Aleks Seovic
10-03-2005, 03:21 PM
Actually, there should be no need to define any of the local resource files within message source definition -- only global resources should be listed there.

I will work on some new localization features today, and will doublecheck everything to make sure that it works as documented on the wiki.

Later,

Aleks