Explicit Localization Syntax - One Works, Other Does Not

Discussion in 'ASP .Net' started by Chris Walls, Jul 19, 2007.

  1. Chris Walls

    Chris Walls Guest

    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?
    Chris Walls, Jul 19, 2007
    #1
    1. Advertising

  2. 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.
    Steven Cheng[MSFT], Jul 20, 2007
    #2
    1. Advertising

  3. Chris Walls

    Chris Walls Guest

    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]" <> wrote in message
    news:c%...
    > 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, Jul 20, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Olivier Matrot

    ASP.NET 2.0 : Explicit localization expression

    Olivier Matrot, Aug 25, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    3,132
    Steven Cheng[MSFT]
    Aug 26, 2005
  2. Replies:
    1
    Views:
    379
  3. J.T. Conklin
    Replies:
    1
    Views:
    437
    David Hilsee
    Aug 11, 2004
  4. =?Utf-8?B?Q2hyaXMgVw==?=

    Explicit Localization Syntax - One Works, Other Does Not

    =?Utf-8?B?Q2hyaXMgVw==?=, Jul 10, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    388
    Chris Walls
    Jul 16, 2007
  5. David Thielen

    implicit vs explicit localization

    David Thielen, Oct 17, 2006, in forum: ASP .Net Web Controls
    Replies:
    5
    Views:
    620
    Steven Cheng[MSFT]
    Oct 20, 2006
Loading...

Share This Page