p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 2.0 Basics (http://p2p.wrox.com/forumdisplay.php?f=136)
-   -   Multi-language website: almost there (http://p2p.wrox.com/showthread.php?t=60615)

electricspace July 28th, 2007 06:21 PM

Multi-language website: almost there
 
Hi all,

First a little introduction since this is my first post: I'm Wouter Bos (The Netherlands), but I use the alias Electricspace online. I'm learning ASP.NET for almost a year now and I'm finally getting somewhere. Didn't need to do a forum post before, but I'm stuck with a specific problem.

The problem: I'm trying to make a multi-langual website with .resx-files. Everything looks great, but I want a language switcher in order to give the user a chance to switch to another language. I can't make the switch permanent. The language switch is made after the RESX-variables are loaded and since the language switch isn't stored the next page load will still have the default language. There are a lot of examples out there for multi-langual sites, but I can't seem to fit it into what I want to have. Can anyone tell me what I am missing here?

the .asx file:
Code:

<%@ Control Language="C#" CodeFile="MenuLanguage.ascx.cs" Inherits="UserControlCode" meta:resourcekey="default" EnableViewState="false" %>

<asp:LinkButton runat="server" ID="Link_nl" Text="Nederlands" OnCommand="MenuLanguageButtonSwitch" CommandName="nl" />
<asp:LinkButton runat="server" ID="Link_en" Text="English" OnCommand="MenuLanguageButtonSwitch" CommandName="en" />

<asp:Label ID="LanguageFeedback" runat="server" Text="<%$ Resources: default, LanguageFeedback %>" />

the .ascx.cs file
Code:

using System;
using System.Collections;
using System.Configuration;
using System.Globalization;
using System.Threading;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class UserControlCode : System.Web.UI.UserControl {


    void Page_Load(Object sender, EventArgs args)
    {
        Response.Write("lan: "+ Thread.CurrentThread.CurrentCulture.ToString());
    }


    protected void MenuLanguageButtonSwitch(object sender, CommandEventArgs e)
    {
        Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(e.CommandName.ToString());
        Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(e.CommandName.ToString());

        Response.Write(Thread.CurrentThread.CurrentUICulture.ToString()); // debug

    }
}





All times are GMT -4. The time now is 02:14 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.