Chieng Sisovin
Member
- Joined
- Jan 12, 2007
- Messages
- 6
- Location
- I Live in Siem Reap, Cambodia
- Programming Experience
- Beginner
Hi, I have a problem on calling Custom Culture for Multiple-language Calendar Display, some have language culture build-in,
but my Khmer language does not have language culture built-in. So, I have to build my own language culture with the following:
Step1: Build VB Class with this name: KhmerCambodianCustomCulture.vb
Step2: Build the class name: PseudoTranslationCustomCulture.vb
Step3: ASP.NET Design Source: Default.aspx
Step4: Code behind Default.aspx Page
Result View: Error
As In view of IE7, in the combo box list I select: Khmer, then the error exit as follows:
Thank you
but my Khmer language does not have language culture built-in. So, I have to build my own language culture with the following:
Step1: Build VB Class with this name: KhmerCambodianCustomCulture.vb
VB.NET:
Imports Microsoft.VisualBasic
Imports System.Collections.Generic
Imports System.Text
Imports System.Globalization
Public Class KhmerCambodianCustomCulture
Public Shared Sub RegisterKhmerCambodianCulture()
CreateKhmerCambodianCultureAndRegionInfoBuilder.Register()
End Sub
Public Shared Function CreateKhmerCambodianCultureAndRegionInfoBuilder() As CultureAndRegionInfoBuilder
Dim builder As CultureAndRegionInfoBuilder = New CultureAndRegionInfoBuilder("km-KH", CultureAndRegionModifiers.None)
builder.Parent = CultureInfo.InvariantCulture
builder.CultureEnglishName = "Khmer (Cambodian)"
builder.CultureNativeName = "ខ្មែរ (កម្ពុជា)"
builder.ThreeLetterISOLanguageName = "KHM"
builder.ThreeLetterWindowsLanguageName = "KHM"
builder.TwoLetterISOLanguageName = "kh"
builder.RegionEnglishName = "Cambodia"
builder.RegionNativeName = "Kampuchea"
builder.ThreeLetterISORegionName = "KHM"
builder.ThreeLetterWindowsRegionName = "KHM"
builder.TwoLetterISORegionName = "KH"
builder.IetfLanguageTag = "km-kh"
builder.IsMetric = True
builder.KeyboardLayoutId = 1107
builder.GeoId = 32
builder.GregorianDateTimeFormat = CreateCambodianDateTimeFormatInfo()
builder.AvailableCalendars = New Calendar() {builder.GregorianDateTimeFormat.Calendar}
builder.NumberFormat = CreateCambodianNumberFormatInfo()
builder.CurrencyEnglishName = "Cambodian Riel"
builder.CurrencyNativeName = "Cambodian Riel"
builder.ISOCurrencySymbol = "៛"
builder.TextInfo = CultureInfo.InvariantCulture.TextInfo
builder.CompareInfo = CultureInfo.InvariantCulture.CompareInfo
Return builder
End Function
Private Shared Function CreateCambodianNumberFormatInfo() As NumberFormatInfo
Dim numberFormatInfo As NumberFormatInfo = New NumberFormatInfo
numberFormatInfo.CurrencyDecimalDigits = 2
numberFormatInfo.CurrencyDecimalSeparator = "."
numberFormatInfo.CurrencyGroupSeparator = ","
numberFormatInfo.CurrencyGroupSizes = New Integer() {3, 2}
numberFormatInfo.CurrencyNegativePattern = 12
numberFormatInfo.CurrencyPositivePattern = 2
numberFormatInfo.CurrencySymbol = "៛"
numberFormatInfo.DigitSubstitution = DigitShapes.None
numberFormatInfo.NaNSymbol = "NaN"
numberFormatInfo.NativeDigits = New String() {"០", "១", "២", "៣", "៤", "៥", "៦", "៧", "៨", "៩"}
numberFormatInfo.NegativeInfinitySymbol = "-Infinity"
numberFormatInfo.NegativeSign = "-"
numberFormatInfo.NumberDecimalDigits = 2
numberFormatInfo.NumberDecimalSeparator = "."
numberFormatInfo.NumberGroupSeparator = ","
numberFormatInfo.NumberGroupSizes = New Integer() {3, 2}
numberFormatInfo.NumberNegativePattern = 1
numberFormatInfo.PercentDecimalDigits = 2
numberFormatInfo.PercentDecimalSeparator = "."
numberFormatInfo.PercentGroupSeparator = ","
numberFormatInfo.PercentGroupSizes = New Integer() {3, 2}
numberFormatInfo.PercentNegativePattern = 0
numberFormatInfo.PercentPositivePattern = 0
numberFormatInfo.PercentSymbol = "%"
numberFormatInfo.PerMilleSymbol = "%."
numberFormatInfo.PositiveInfinitySymbol = "Infinity"
numberFormatInfo.PositiveSign = "+"
Return numberFormatInfo
End Function
---------------------------------------------------------
Private Shared Function CreateCambodianDateTimeFormatInfo() As DateTimeFormatInfo
Dim calendar As Calendar = New GregorianCalendar(GregorianCalendarTypes.Localized)
Dim dateTimeFormatInfo As DateTimeFormatInfo = New DateTimeFormatInfo
dateTimeFormatInfo.Calendar = calendar
dateTimeFormatInfo.AbbreviatedDayNames = New String() {"ច.", "អ.", "ព.", "ព្រ.", "សុ.", "ស.", "អា."}
dateTimeFormatInfo.DayNames = New String() {"ច័ន្ទ", "អង្គារ", "ពុធ", "ព្រហស្បតិ", "សុក្រ", "សៅរ៍", "អាទិត្យ"}
dateTimeFormatInfo.ShortestDayNames = New String() {"ច័ន្ទ", "អង្គារ", "ពុធ", "ព្រហស្បតិ", "សុក្រ", "សៅរ៍", "អាទិត្យ"}
dateTimeFormatInfo.AbbreviatedMonthNames = New String() {"ម.", "កុ.", "មី", "មេ.", "ឧ.", "មិ.", "កក្ក.", "សី.", "ក.", "តុ.", "វិ.", "ធ្ន", ""}
dateTimeFormatInfo.MonthNames = New String() {"មករា", "កុម្ភះ", "មីនា", "មេសា", "ឧសភា", "មិថុនា", "កក្កដា", "សីហា", "កញ្ញា", "តុលា", "វិច្ឆិកា", "ធ្នូរ", ""}
dateTimeFormatInfo.AbbreviatedMonthGenitiveNames = New String() {"មករា", "កុម្ភះ", "មីនា", "មេសា", "ឧសភា", "មិថុនា", "កក្កដា", "សីហា", "កញ្ញា", "តុលា", "វិច្ឆិកា", "ធ្នូរ", ""}
dateTimeFormatInfo.MonthGenitiveNames = New String() {"មករា", "កុម្ភះ", "មីនា", "មេសា", "ឧសភា", "មិថុនា", "កក្កដា", "សីហា", "កញ្ញា", "តុលា", "វិច្ឆិកា", "ធ្នូរ", ""}
dateTimeFormatInfo.AMDesignator = "ព្រឹក"
dateTimeFormatInfo.CalendarWeekRule = CalendarWeekRule.FirstDay
dateTimeFormatInfo.DateSeparator = "-"
dateTimeFormatInfo.FirstDayOfWeek = DayOfWeek.Monday
dateTimeFormatInfo.FullDateTimePattern = "dd MMMM yyyy HH:mm:ss"
dateTimeFormatInfo.LongDatePattern = "dd MMMM yyyy"
dateTimeFormatInfo.LongTimePattern = "HH:mm:ss"
dateTimeFormatInfo.MonthDayPattern = "dd MMMM"
dateTimeFormatInfo.PMDesignator = "ល្ងាច"
dateTimeFormatInfo.ShortDatePattern = "dd-MM-yyyy"
dateTimeFormatInfo.ShortTimePattern = "HH:mm"
dateTimeFormatInfo.TimeSeparator = ":"
dateTimeFormatInfo.YearMonthPattern = "MMMM, yyyy"
Return dateTimeFormatInfo
End Function
End Class
VB.NET:
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Globalization
Public Class PseudoTranslationCustomCulture
Public Shared Sub RegisterPseudoTranslationCulture()
CreatePseudoTranslationCultureAndRegionInfoBuilder.Register()
End Sub
Public Shared Function CreatePseudoTranslationCultureAndRegionInfoBuilder() As CultureAndRegionInfoBuilder
Dim builder As CultureAndRegionInfoBuilder = New CultureAndRegionInfoBuilder("km-KH", CultureAndRegionModifiers.None)
builder.Parent = CultureInfo.InvariantCulture
builder.CultureEnglishName = "PseudoLanguage (PseudoRegion)"
builder.CultureNativeName = "[ខ្មែរ(Cambodian)]"
builder.ThreeLetterISOLanguageName = "khm"
builder.ThreeLetterWindowsLanguageName = "khm"
builder.TwoLetterISOLanguageName = "km"
builder.RegionEnglishName = "PseudoRegion"
builder.RegionNativeName = "[ប្រទេសកម្ពុជា]"
builder.ThreeLetterISORegionName = "KHM"
builder.ThreeLetterWindowsRegionName = "KHM"
builder.TwoLetterISORegionName = "KH"
builder.IetfLanguageTag = "km-KH"
builder.IsMetric = True
' US Keyboard Layout (probably not a wise idea to change the keyboard layout)
builder.KeyboardLayoutId = 1107
' GeoId 0x200 is not currently allocated to any location
builder.GeoId = 512
builder.GregorianDateTimeFormat = CreatePseudoDateTimeFormatInfo
builder.NumberFormat = CreatePseudoNumberFormatInfo
builder.CurrencyEnglishName = "Pseudo Dollars"
builder.CurrencyNativeName = "[រៀល]"
builder.ISOCurrencySymbol = "KHM"
builder.TextInfo = CultureInfo.InvariantCulture.TextInfo
builder.CompareInfo = CultureInfo.InvariantCulture.CompareInfo
Return builder
End Function
Private Shared Function CreatePseudoNumberFormatInfo() As NumberFormatInfo
Dim numberFormatInfo As NumberFormatInfo = New NumberFormatInfo
numberFormatInfo.CurrencyDecimalDigits = 4
numberFormatInfo.CurrencyDecimalSeparator = "@"
numberFormatInfo.CurrencyGroupSeparator = "'"
numberFormatInfo.CurrencyGroupSizes = New Integer() {1}
numberFormatInfo.CurrencyNegativePattern = 3
numberFormatInfo.CurrencyPositivePattern = 3
numberFormatInfo.CurrencySymbol = "~"
numberFormatInfo.DigitSubstitution = DigitShapes.None
numberFormatInfo.NaNSymbol = "*NaN*"
numberFormatInfo.NativeDigits = New String() {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
numberFormatInfo.NegativeInfinitySymbol = "*-Infinity*"
numberFormatInfo.NegativeSign = "-"
numberFormatInfo.NumberDecimalDigits = 2
numberFormatInfo.NumberDecimalSeparator = "@"
numberFormatInfo.NumberGroupSeparator = "'"
numberFormatInfo.NumberGroupSizes = New Integer() {1}
numberFormatInfo.NumberNegativePattern = 3
numberFormatInfo.PercentDecimalDigits = 2
numberFormatInfo.PercentDecimalSeparator = "@"
numberFormatInfo.PercentGroupSeparator = "'"
numberFormatInfo.PercentGroupSizes = New Integer() {1}
numberFormatInfo.PercentNegativePattern = 2
numberFormatInfo.PercentPositivePattern = 2
numberFormatInfo.PercentSymbol = "%"
numberFormatInfo.PerMilleSymbol = "%."
numberFormatInfo.PositiveInfinitySymbol = "*Infinity*"
numberFormatInfo.PositiveSign = "+"
Return numberFormatInfo
End Function
Private Shared Function CreatePseudoDateTimeFormatInfo() As DateTimeFormatInfo
Dim calendar As Calendar = New GregorianCalendar(GregorianCalendarTypes.Localized)
Dim dateTimeFormatInfo As DateTimeFormatInfo = New DateTimeFormatInfo
dateTimeFormatInfo.Calendar = calendar
dateTimeFormatInfo.AbbreviatedDayNames = New String() {"*Sun*", "*Mon*", "*Tue*", "*Wed*", "*Thu*", "*Fri*", "*Sat*"}
dateTimeFormatInfo.DayNames = New String() {"*Sunday*", "*Monday*", "*Tuesday*", "*Wednesday*", "*Thursday*", "*Friday*", "*Saturday*"}
dateTimeFormatInfo.ShortestDayNames = New String() {"*Su*", "*Mo*", "*Tu*", "*We*", "*Th*", "*Fr*", "*Sa*"}
dateTimeFormatInfo.AbbreviatedMonthNames = New String() {"*Jan*", "*Feb*", "*Mar*", "*Apr*", "*May*", "*Jun*", "*Jul*", "*Aug*", "*Sep*", "*Oct*", "*Nov*", "*Dec*", ""}
dateTimeFormatInfo.MonthNames = New String() {"*January*", "*February*", "*March*", "*April*", "*May*", "*June*", "*July*", "*August*", "*September*", "*October*", "*November*", "*December*", ""}
dateTimeFormatInfo.AbbreviatedMonthGenitiveNames = New String() {"*Janth*", "*Febth*", "*Marth*", "*Aprth*", "*Mayth*", "*Junth*", "*Julth*", "*Augth*", "*Septh*", "*Octth*", "*Novth*", "*Decth*", ""}
dateTimeFormatInfo.MonthGenitiveNames = New String() {"*Januaryth*", "*Februaryth*", "*Marchth*", "*Aprilth*", "*Mayth*", "*Juneth*", "*Julyth*", "*Augustth*", "*Septemberth*", "*Octoberth*", "*Novemberth*", "*Decemberth*", ""}
dateTimeFormatInfo.AMDesignator = "*AM*"
dateTimeFormatInfo.CalendarWeekRule = CalendarWeekRule.FirstFullWeek
dateTimeFormatInfo.DateSeparator = "!"
dateTimeFormatInfo.FirstDayOfWeek = DayOfWeek.Tuesday
dateTimeFormatInfo.FullDateTimePattern = "yyyy MMMM dd HH:mm:ss"
dateTimeFormatInfo.LongDatePattern = "yyyy MMMM dd"
dateTimeFormatInfo.LongTimePattern = "HH:mm:ss"
dateTimeFormatInfo.MonthDayPattern = "MMMM dd"
dateTimeFormatInfo.PMDesignator = "*PM*"
dateTimeFormatInfo.ShortDatePattern = "yyyy-MM-dd"
dateTimeFormatInfo.ShortTimePattern = "HH:mm"
dateTimeFormatInfo.TimeSeparator = ":"
dateTimeFormatInfo.YearMonthPattern = "yyyy, MMMM"
Return dateTimeFormatInfo
End Function
End Class
HTML:
<%@ Page AutoEventWireup="false" CodeFile="Default.aspx.vb" Culture="auto:en-US" Inherits="_Default" Language="VB" UICulture="auto" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Size="Large" Text="WELCOME"></asp:Label><br />
<br />
<asp:Button ID="Button1" runat="server" Text="Button" /><br />
<br />
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label><br />
<asp:DropDownList ID="Language1" runat="server" AutoPostBack="True">
<asp:ListItem>Auto</asp:ListItem>
<asp:ListItem Value="th-TH">Thai</asp:ListItem>
<asp:ListItem Value="vi-VN">Vietnamese</asp:ListItem>
<asp:ListItem Value="zh-CN">Chinese(PRC)</asp:ListItem>
<asp:ListItem Value="km-KH">Khmer</asp:ListItem>
<asp:ListItem Value="bn-IN">Bangladeshi</asp:ListItem>
</asp:DropDownList> </div>
<br />
<hr />
<br />
<asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
<br />
<br />
<asp:Label ID="currencyLabel1" runat="server" Text="Label"></asp:Label>
</form>
</body>
</html>
VB.NET:
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports KhmerCambodianCustomCulture
Imports PseudoTranslationCustomCulture
Imports System.Threading
Imports System.Globalization
Partial Class _Default
Inherits System.Web.UI.Page
Protected Overrides Sub InitializeCulture()
Dim lang As String = Request("Language1")
If lang IsNot Nothing Or lang <> "" Then
If lang = "km-KH" Then
ShowCulture(New CultureInfo("km-KH"))
Else
Thread.CurrentThread.CurrentUICulture = New CultureInfo(lang)
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang)
End If
End If
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Dim money As Decimal = 65545.42
currencyLabel1.Text = String.Format("{0:c}", money)
End Sub
Private Overloads Sub ShowCulture(ByVal cultureInfo As CultureInfo)
ShowCulture(cultureInfo, New RegionInfo(cultureInfo.Name))
End Sub
Private Overloads Sub ShowCulture(ByVal cultureInfo As CultureInfo, ByVal regionInfo As RegionInfo)
KhmerCambodianCustomCulture.RegisterKhmerCambodianCulture()
KhmerCambodianCustomCulture.CreateKhmerCambodianCultureAndRegionInfoBuilder()
End Sub
End Class
As In view of IE7, in the combo box list I select: Khmer, then the error exit as follows:
Please help me to solve this problem.Server Error in '/Calendar_KHM' Application.
Culture name 'km-kh' is not supported.
Parameter name: name
[FONT=Arial, Helvetica, Geneva, SunSans-Regular, sans-serif]Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. [/FONT]
[FONT=Arial, Helvetica, Geneva, SunSans-Regular, sans-serif]Exception Details: System.ArgumentException: Culture name 'km-kh' is not supported.[/FONT]
[FONT=Arial, Helvetica, Geneva, SunSans-Regular, sans-serif]Parameter name: name[/FONT]
[FONT=Arial, Helvetica, Geneva, SunSans-Regular, sans-serif]Source Error: [/FONT]
[FONT=Arial, Helvetica, Geneva, SunSans-Regular, sans-serif]Line 14: If lang IsNot Nothing Or lang <> "" Then[/FONT]
[FONT=Arial, Helvetica, Geneva, SunSans-Regular, sans-serif]Line 15: If lang = "km-KH" Then[/FONT]
[FONT=Arial, Helvetica, Geneva, SunSans-Regular, sans-serif]Line 16: ShowCulture(New CultureInfo("km-KH"))[/FONT]
[FONT=Arial, Helvetica, Geneva, SunSans-Regular, sans-serif]Line 17: Else[/FONT]
[FONT=Arial, Helvetica, Geneva, SunSans-Regular, sans-serif]Line 18: Thread.CurrentThread.CurrentUICulture = New CultureInfo(lang)[/FONT]
[FONT=Arial, Helvetica, Geneva, SunSans-Regular, sans-serif]Source File: D:\Projects\Microsoft ASP.NET\MSDN\Learning\Calendar_KHM\Default.aspx.vb Line: 16 [/FONT]
[FONT=Arial, Helvetica, Geneva, SunSans-Regular, sans-serif]Stack Trace: [/FONT]
[FONT=Arial, Helvetica, Geneva, SunSans-Regular, sans-serif][ArgumentException: Culture name 'km-kh' is not supported.[/FONT]
[FONT=Arial, Helvetica, Geneva, SunSans-Regular, sans-serif]Parameter name: name][/FONT]
[FONT=Arial, Helvetica, Geneva, SunSans-Regular, sans-serif]System.Globalization.CultureTableRecord..ctor(String cultureName, Boolean useUserOverride) +2839437[/FONT]
[FONT=Arial, Helvetica, Geneva, SunSans-Regular, sans-serif]System.Globalization.CultureTableRecord.GetCultureTableRecord(String name, Boolean useUserOverride) +414[/FONT]
[FONT=Arial, Helvetica, Geneva, SunSans-Regular, sans-serif]System.Globalization.CultureInfo..ctor(String name, Boolean useUserOverride) +48[/FONT]
[FONT=Arial, Helvetica, Geneva, SunSans-Regular, sans-serif]System.Globalization.CultureInfo..ctor(String name) +31[/FONT]
[FONT=Arial, Helvetica, Geneva, SunSans-Regular, sans-serif]_Default.InitializeCulture() in D:\Projects\Microsoft ASP.NET\MSDN\Learning\Calendar_KHM\Default.aspx.vb:16[/FONT]
[FONT=Arial, Helvetica, Geneva, SunSans-Regular, sans-serif]ASP.default_aspx.__BuildControlTree(default_aspx __ctrl) in D:\Projects\Microsoft ASP.NET\MSDN\Learning\Calendar_KHM\Default.aspx:1[/FONT]
[FONT=Arial, Helvetica, Geneva, SunSans-Regular, sans-serif]ASP.default_aspx.FrameworkInitialize() in D:\Projects\Microsoft ASP.NET\MSDN\Learning\Calendar_KHM\Default.aspx.vb:912306[/FONT]
[FONT=Arial, Helvetica, Geneva, SunSans-Regular, sans-serif]System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +40[/FONT]
[FONT=Arial, Helvetica, Geneva, SunSans-Regular, sans-serif]System.Web.UI.Page.ProcessRequest() +86[/FONT]
[FONT=Arial, Helvetica, Geneva, SunSans-Regular, sans-serif]System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +18[/FONT]
[FONT=Arial, Helvetica, Geneva, SunSans-Regular, sans-serif]System.Web.UI.Page.ProcessRequest(HttpContext context) +49[/FONT]
[FONT=Arial, Helvetica, Geneva, SunSans-Regular, sans-serif]ASP.default_aspx.ProcessRequest(HttpContext context) +29[/FONT]
[FONT=Arial, Helvetica, Geneva, SunSans-Regular, sans-serif]System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +154[/FONT]
[FONT=Arial, Helvetica, Geneva, SunSans-Regular, sans-serif]System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +64[/FONT]
[FONT=Arial, Helvetica, Geneva, SunSans-Regular, sans-serif]Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.210 [/FONT]
Thank you
Attachments
Last edited by a moderator: