Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Explicit Localization Syntax - One Works, Other Does Not

Reply
Thread Tools

Explicit Localization Syntax - One Works, Other Does Not

 
 
Chris Walls
Guest
Posts: n/a
 
      07-19-2007
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?


 
Reply With Quote
 
 
 
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      07-20-2007
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/subscripti...ult.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/subscripti...t/default.aspx.

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


This posting is provided "AS IS" with no warranties, and confers no rights.



 
Reply With Quote
 
 
 
 
Chris Walls
Guest
Posts: n/a
 
      07-20-2007
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

"Steven Cheng[MSFT]" <(E-Mail Removed)> wrote in message
news:c%(E-Mail Removed)...
> 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/subscripti...ult.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/subscripti...t/default.aspx.
>
> ==================================================
>
>
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Explicit Localization Syntax - One Works, Other Does Not =?Utf-8?B?Q2hyaXMgVw==?= ASP .Net 1 07-16-2007 10:25 PM
implicit vs explicit localization David Thielen ASP .Net Web Controls 5 10-20-2006 09:25 AM
explicit localization, sample testing approach not work kelmen@hotmail.com ASP .Net 1 02-27-2006 07:02 AM
ASP.NET 2.0 : Explicit localization expression Olivier Matrot ASP .Net 1 08-26-2005 09:37 AM
Is explicit template qualification required for explicit delete? J.T. Conklin C++ 1 08-11-2004 02:06 AM



Advertisments