locked
Localization RRS feed

  • Question

  • User-1267909644 posted

    Please help me.

    I want to localize my page. I have page named langpage.aspx in which user clicks on his nations flag, and main page which should change according to selected flag.

    I created two resource files named main.aspx.resx and main.aspx.en-GB.resx.

    Heres my main.aspx:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="main.aspx.cs" Inherits="main" Culture="auto:en-GB" UICulture="auto" %>

    <!DOCTYPE html>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div class="logo">
                <img src=""/>
            </div>
            <div class="mainmenu">
                <ul>
                    <li><asp:Label runat="server" ID="pica" meta:resourcekey="pica"></asp:Label>
                        <ul>
                            <li><asp:Label runat="server" ID="gazirana" meta:resourcekey="gazirana"></asp:Label></li>
                            <li><asp:Label runat="server" ID="negazirana" meta:resourcekey="negazirana"></asp:Label></li>
                        </ul>
                    </li>
                    <li><asp:Label runat="server" ID="predjela" meta:resourcekey="predjela"></asp:Label>
                        <ul>
                            <li><asp:Label runat="server" ID="salate" meta:resourcekey="salate"></asp:Label></li>
                            <li><asp:Label runat="server" ID="kruh" meta:resourcekey="kruh"></asp:Label></li>
                        </ul>
                    </li>
                    <li><asp:Label runat="server" ID="glavnajela" meta:resourcekey="glavnajela"></asp:Label>
                        <ul>
                            <li><asp:Label runat="server" ID="pizze" meta:resourcekey="pizze"></asp:Label></li>
                        </ul>
                    </li>
                    <li><asp:Label runat="server" ID="deserti" meta:resourcekey="deserti"></asp:Label>
                        <ul>
                            <li><asp:Label runat="server" ID="kolaci" meta:resourcekey="kolaci"></asp:Label></li>
                        </ul>
                    </li>    
                </ul>
            </div>
            <div class="text">

            </div>
        </form>
    </body>
    </html>

    Here is my lanpage.aspx:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="langpage.aspx.cs" Inherits="_Default" %>

    <!DOCTYPE html>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Restoran</title>
        <meta charset="utf-8" />
        <link rel="stylesheet" type="text/css" href="langpage.css" />
    </head>
    <body>
        <form id="form1" runat="server">
        <div class="header">
            <h1>Welcome to <asp:Label ID="restoran" runat="server" meta:resourcekey="restoran"></asp:Label></h1>
        </div>
        <div class="meni">
            <asp:ImageButton ID="uk" runat="server" ImageUrl="zastave/UK-button.png" PostBackUrl="~/main.aspx?Language=en-GB" />
            <asp:ImageButton ID="hr" runat="server" ImageUrl="zastave/France-button.png" PostBackUrl="~/main.aspx?Language=fr"/>
        </div>
        </form>
    </body>
    </html>

    And here is my main.aspx.cs:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Threading;
    using System.Globalization;
    using System.Resources;
    using System.Text;

    public partial class main : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
        protected override void InitializeCulture()
        {
            if (Request["Language"] != null)
            {
                Thread.CurrentThread.CurrentCulture = new CultureInfo(Request["Language"].ToString());
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(Request["Language"].ToString());
            }
            base.InitializeCulture();
        }
    }

    When I click on imagebutton it redirects me to main.aspx but Labels are empty, and when I directly open main.aspx Labels are empty.

    Please I tried 100 different tutorials and examples but none worked, I'm missing something.

    I'm using Visual Studio 2013 Web Express.

    Friday, April 25, 2014 3:27 PM

All replies

  • User-1025250470 posted

    I didnt seen any problem on your code, are you using .resx  file inside a folder?

    Thank You

    Saturday, April 26, 2014 2:20 AM
  • User-1267909644 posted

    My .resx are in App_LocalResources folder

    Saturday, April 26, 2014 4:04 AM
  • User-1025250470 posted

    Please check below.

    Your App_LocalResources file is located on same folder.

    Check label value is specified on both .resx files.

    Request["Language"] returns correct value.

    Thank You

    Saturday, April 26, 2014 4:21 AM
  • User-1267909644 posted

    Request["Language"] does return correct value.

    Label values are specified in both .resx

    But what do you mean by App_LocalResources FILE, I only have folder App_LocalResources with .resx in it.

    Saturday, April 26, 2014 4:30 AM