一旦与.resx文件本地化,如何让客户在他们的语言来查看整个网站? [英] Once localized with .resx files, how to enable client to view entire website in their language?

查看:212
本文介绍了一旦与.resx文件本地化,如何让客户在他们的语言来查看整个网站?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的大部分.resx文件都在App_GlobalResources文件(明确的),和母版页都在App_LocalResources文件放在他们的目录(隐含的)。我要在我所有的页面设置为第一行的文化/的UICulture - 汽车

Most of my .resx files are in App_GlobalResources (explicit), and the master pages are in the App_LocalResources in their directories (implicit). I have to top line in all my pages set to culture / uiculture - auto.

现在,我的语言设置, Nuux 向我解释如何创建一个下拉框,并把所特定页面,这是伟大的 - 比我多很多。

Now that my languages are set up, Nuux explained to me how to create a drop-down box and translate that particular page, and this is great -- a lot more than I had.

但如果我想最终用户看到的标志在首页的数组,因此也可以手动选择来查看该语言的整个网站?这是很多比我已经做了更复杂的,还是仅仅是复制和粘贴?这是否涉及创建为每种语言的目录?任何建议或指导,将大大AP preciated!

But what if I want the end-user to see an array of flags on the homepage, so they can manually opt to view the entire site in that language? Is this a LOT more intricate than what I've already done, or is it just copying and pasting? Is it going to involve creating a directory for each language? Any suggestions or guidance would be greatly appreciated!

推荐答案

在这个code看一看的与母版和本地化开发​​一个ASP.NET页面。使它适合您的需要。如果你不能自定义。我会尽力帮助你。

Take a look at this code Developing an ASP.NET page with MasterPage and Localization. Make it fit your need. If you couldn't customize it. I'll try to help you.

更新:好吧,让我们试试这个:
新类添加到项目:和覆盖其与此内容

Update: Ok, let us try this: Add new class to your project: and overwrite its content with this

 Imports Microsoft.VisualBasic
 Imports System.Globalization
 Imports System.Threading

Public Class BasePage
    Inherits System.Web.UI.Page
    Protected Overrides Sub InitializeCulture()
    'MyBase.InitializeCulture()
    If Session("culture") Is Nothing Then
        Session("culture") = "en-US" 'Set default language
    End If
    Dim cult As String = Session("culture")
    Culture = cult
    UICulture = cult

    MyBase.InitializeCulture()
 End Sub
End Class

现在去你必须在每一页的codebehind和更改继承子句:

Now go to the codebehind of every page you have and change the Inherits clause :

 Partial Class _Default
          Inherits BasePage

这一点后,您需要实现一个母版页的语言界面

After this point you need to implement the language interface in a master page

  <asp:DropDownList ID="ddlCulture" DataTextField="Name" DataValueField="Name"
         runat="server" >
        <asp:ListItem Value="es-MX">Spanish</asp:ListItem>
        <asp:ListItem Value="en-US">English</asp:ListItem>
    </asp:DropDownList>
    <asp:Button ID="btnSelect" Text="Select" runat="server" OnClick="btnSelect_Click" />
    <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">        
    </asp:ContentPlaceHolder>

在母版$ ​​C $ cbehind文件中的事件仍然是:

The event in the masterpage codebehind file remains:

Protected Sub btnSelect_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSelect.Click
    Session("culture") = ddlCulture.SelectedValue
    Response.Redirect(Request.Path)
End Sub

现在您的网站俱备只定制我用你的preference控制。

Now your website is ready only customize the control I used to your preference.

在剩下的事情是,我们使用的会话存储用户的选择,然而,当会话过期的用户是默认语言psented所以你可能有一个永久性的Cookie更换会议$ P $。首先让这一设想,希望更改为cookie将不会是一个问题。我只是想你把这个概念在脑海。

On thing remaining is that we used Session to store the user selection, however, when the session expires the user is presented with the default language so you may replace the Session with a persistent cookie. First let this idea work, I hope changing to cookie won't be a problem. I just wanted you keep this concept in mind.

这篇关于一旦与.resx文件本地化,如何让客户在他们的语言来查看整个网站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆