Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2007

Tip: Looking for answers? Try searching our database.

Explicit Localization Syntax - One Works, Other Does Not

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Chris Walls - 19 Jul 2007 16:57 GMT
We have created two (2) global resource files in App_GlobalResouces:
    Global.resx
    Global.es-MX.resx

In an ASP.NET page, we use two different syntaxes to set text on the page,
depending upon the context.
    Syntax 1:  <% =Resources.Global.QuickSearch%>
    Syntax 2:  <%$Resources:Global, QuickSearch%>

When we set our Thread.CurrentThread.CurrentUICulture and
Thread.CurrentThread.CurrentCulture = new CultureInfo("es-MX"), those
controls using syntax 1 display Spanish, but those displaying syntax 2 still
display English.

To create the Global.es-MX.resx file, we copied the Global.resx and modified
the text.  All of the keys are present.  Also because of this, we thought if
it were a key issue, then how is the English text being found?

Any ideas on what we're doing wrong?
Steven Cheng[MSFT] - 20 Jul 2007 08:15 GMT
Hi Chris,

From your description, when you use the following two ways to display
localized Text in ASP.NET 2.0 web page(load from global resource), only the
<%= ...%> appraoch will work, correct?

    Syntax 1:  <% =Resources.Global.QuickSearch%>
    Syntax 2:  <%$Resources:Global, QuickSearch%>

As for this problem,I've performed some research and found the cause of the
problem. For the two kind of statements below:

    Syntax 1:  <% =Resources.Global.QuickSearch%>
====================
This is simple embeded inline code statement which is executeing at the end
of the page's lifecycle(rendering stage). So this code is the same as you
put some code in codebehind page event.

    Syntax 2:  <%$Resources:Global, QuickSearch%>
====================
This is a built-in ASP.NET 2.0 expression and this expression is determined
at earlier time, when the page is dynamically compiled and initialized.
Therefore, if you set the Thread.CurrentUICulture in page's codebehind
event, that's too late for this localization expression. If you want to
programmatically set the Thread's CultureInfo and want to make the
<%$Resources %> expression be wared of it, you  need to put the code in an
earlier time during the page request's server-side processing. One good
place is the "BeginRequest" event of ASP.NET server-side pipeline, you can
use Global.asax to register this event's handler. e.g.

>>>>>in global.asax>>>>>>>>>

<script runat="server">

   void Application_Start(object sender, EventArgs e)
   {
...............
   }

   void Application_BeginRequest(object sender, EventArgs e)
   {
       CultureInfo ci = new CultureInfo("zh-CN");

       Thread.CurrentThread.CurrentCulture = ci;
       Thread.CurrentThread.CurrentUICulture = ci;  
         
       Context.Response.Write("<br/>Application_BeginRequest.......");
   }
..................

<<<<<<<<<<<<<<

Thus, the <%$ REsources %> expression in Page can get awared of the
CultureInfo changing.

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================
   

This posting is provided "AS IS" with no warranties, and confers no rights.
Chris Walls - 20 Jul 2007 14:18 GMT
Thanks for the information.  I never ran across that in my searches and in
it seems that the far majority of the examples I found on this topic
reference Syntax #2, but don't mention the limitations below.

Thanks,
   Chris

> Hi Chris,
>
[quoted text clipped - 85 lines]
> This posting is provided "AS IS" with no warranties, and confers no
> rights.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.