修改原因:在更换语言包的时候 DateFormatDropDownList 的值并不能随之更改。如:用户从zh-CN 换为 en-US 后 user.DateFormat 的
显示格式仍为yyyy年mm月dd日。
修改方法:将DateFormatDropDownList对象中Item的value改为Resource的名称,在保存的时候根据用户选择的语言获取相应的日期格式
step1 -- 为/Components/Components/ResourceManager.cs中的 GetResource 和 GetString 两个方法 分别添加一次接受Language
参数的重载
//************GetResource Method START*****************//
![](/Images/OutliningIndicators/None.gif)
private static Hashtable GetResource (ResourceManagerType resourceType)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
return GetResource(resourceType,null);
}
private static Hashtable GetResource (ResourceManagerType resourceType,string language)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
ForumContext forumContext = ForumContext.Current;
Hashtable resources;
![](/Images/OutliningIndicators/InBlock.gif)
// string defaultLanguage = ForumConfiguration.GetConfig().DefaultLanguage;
// string userLanguage = Users.GetUser().Language;
// string cacheKey = resourceType.ToString() + defaultLanguage + userLanguage;
//-> chaozi 22/09/04 -->START
string defaultLanguage = ForumConfiguration.GetConfig().DefaultLanguage;
string userLanguage;
if(language == null)
userLanguage = Users.GetUser().Language;
else
userLanguage = language;
string cacheKey = resourceType.ToString() + defaultLanguage + userLanguage;
//-> chaozi 22/09/04 -->END
![](/Images/OutliningIndicators/InBlock.gif)
// Ensure the user has a language set
//
if (userLanguage == "")
userLanguage = defaultLanguage;
// Attempt to get the resources from the Cache
//
if (forumContext.Context.Cache[cacheKey] == null)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
resources = new Hashtable();
// First load the English resouce, changed from loading the default language
// since the userLanguage is set to the defaultLanguage if the userLanguage
// is unassigned. We load the english language always just to ensure we have
// a resource loaded just incase the userLanguage doesn't have a translated
// string for this English resource.
//
LoadResource(resourceType, resources, "en-US", cacheKey);
![](/Images/OutliningIndicators/InBlock.gif)
// If the user language is different load it
//
if ("en-US" != userLanguage)
LoadResource(resourceType, resources, userLanguage, cacheKey);
}
![](/Images/OutliningIndicators/InBlock.gif)
return (Hashtable) forumContext.Context.Cache[cacheKey];
}
//************GetResource Method END*****************//
![](/Images/OutliningIndicators/None.gif)
可以根据指定的语言获取资源
//************GetString Method START*****************//
![](/Images/OutliningIndicators/None.gif)
public static string GetString(string name)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
return GetString(name,null);
}
public static string GetString(string name,string language)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
// Hashtable resources = GetResource (ResourceManagerType.String);
//->chaozi 22/09/04
Hashtable resources = GetResource (ResourceManagerType.String , language);
![](/Images/OutliningIndicators/InBlock.gif)
if (resources[name] == null)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
// LN 6/9/04: Changed to throw a forums exception
throw new ForumException(ForumExceptionType.ResourceNotFound, "Value not found in Resources.xml for: " + name);
}
return (string) resources[name];
}
![](/Images/OutliningIndicators/None.gif)
//************GetString Method END*****************//
![](/Images/OutliningIndicators/None.gif)
同理
step 2 -- 修改/Controls/Utility/DateFormatDropDownList.cs 将Value直接设置为resource的名称
Items.Add(new ListItem(AspNetForums.Components.ResourceManager.GetString("Utility_DateFormatDropDownList_F1Text"), "Utility_DateFormatDropDownList_F1"));
Items.Add(new ListItem(AspNetForums.Components.ResourceManager.GetString("Utility_DateFormatDropDownList_F2Text"), "Utility_DateFormatDropDownList_F2"));
Items.Add(new ListItem(AspNetForums.Components.ResourceManager.GetString("Utility_DateFormatDropDownList_F3Text"), "Utility_DateFormatDropDownList_F3"));
Items.Add(new ListItem(AspNetForums.Components.ResourceManager.GetString("Utility_DateFormatDropDownList_F4Text"), "Utility_DateFormatDropDownList_F4"));
Items.Add(new ListItem(AspNetForums.Components.ResourceManager.GetString("Utility_DateFormatDropDownList_F5Text"), "Utility_DateFormatDropDownList_F5"));
Items.Add(new ListItem(AspNetForums.Components.ResourceManager.GetString("Utility_DateFormatDropDownList_F6Text"), "Utility_DateFormatDropDownList_F6"));
Items.Add(new ListItem(AspNetForums.Components.ResourceManager.GetString("Utility_DateFormatDropDownList_F7Text"), "Utility_DateFormatDropDownList_F7"));
step 3 --修改 /Controls/Utility/EditProfile.cs 的 Update_Click 方法
// userToEdit.DateFormat = dateFormat.SelectedItem.Value;
//-> chaozi 22/09/04
userToEdit.DateFormat = ResourceManager.GetString(dateFormat.SelectedValue,language.SelectedItem.Value);
/Admin/SiteSettings.aspx.cs
// settings.DateFormat = DateFormat.SelectedItem.Value;
settings.DateFormat =ResourceManager.GetString(DateFormat.SelectedValue,"");