开发者

Problem with changing culture

I did Override InitializeCulture in base page.

Protected Overrides Sub InitializeCulture()
    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("Fa-IR")
    Thread.CurrentThread.CurrentUICulture = New CultureInfo("Fa-IR")
    MyBase.InitializeCulture()
End Sub

but still my culture is english united state . and texts are english yet and are not pers开发者_高级运维ian.


I want to change it programmatically. I have local and global English and persian resources. i want to switch between them. How can i fix it?

when i put Protected Overrides Sub InitializeCulture() in main page it works great! but else when i put it in basepage not. what is the problem?


I found it uncommon that you initialize the base class method with the last line. My first bet was, that this overrides your culture initialization. But I tested it - This isn’t the problem. Your code should work anyway.

Are you sure there is no other place with a culture initialization in your code? CurrentThread is a global variable and if you change it somewhere else (in a web control? in the data layer?) this will influence your page.

Here is my sample code, working for german/english. It should work for persian/english too.

Partial Public Class _Default
    Inherits BasePage
End Class

Public Class BasePage
    Inherits System.Web.UI.Page

    Protected Overrides Sub InitializeCulture()
        MyBase.InitializeCulture()
        Dim cultureInfo = New CultureInfo("de-DE")
        Thread.CurrentThread.CurrentCulture = cultureInfo
        Thread.CurrentThread.CurrentUICulture = cultureInfo
    End Sub
End Class


If you want to set the culture for your entire ASP.NET site then you can do that in the web.config file:

<globalization uiCulture="Fa-IR" culture="Fa-IR" />

See Localization Made Easy article.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜