locked
DD Futures and Resource Files RRS feed

  • Question

  • User19825367 posted

    I am playing arond with the DD Futures and I have the resource files working...but it only works for the default resource file.

    I have created two resource files in App_GlobalResources: Resources.resx and Resources.fr.resx

    I have created a base class page that inherits from Page.  I have overriden InitializeCulture in the base class page

    public class CMTBasePage : System.Web.UI.Page
    {
    protected override void InitializeCulture()
    {
    System.Threading.
    Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("fr-CA");
    }
    }

    I have created a CustomPage in the CustomPage folder that inherits from my base class page.

     I have added the following attribute to my partial class:

    [LocalizedDisplayName(typeof(Resources.Resources), "UserTable_DisplayName")]

     When I view the application in a browser I am seeing the value from my default resource file and not the fr one...even though I am setting the current culture to fr-CA.

    Any ideas?

     Regards,
    Joel.

    Thursday, September 25, 2008 1:25 PM

All replies

  • User19825367 posted

    Well I figured it out...

     I was only setting the CurrentCulture and not CurrentUICulture as well...[:$]

    System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("fr-CA"); 
    System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("fr-CA");

    All is good now...

    Joel.

    Saturday, September 27, 2008 10:03 AM
  • User19825367 posted

    Nope...that only solved the problem partially...

    All of the non-dynamic elements are translating properly when switching between cultures but the Dynamic Table and Column names are only changing intermittently...I haven't found a pattern yet to explain why sometimes it works and other times it doesn't.

    Does the UI get cached?  Could that be the problem?  I have not specified any caching options.  Is DD caching info automatically?

    Any help would be greatly appreciated!

    Regards,
    Joel.

    Sunday, September 28, 2008 10:44 AM
  • User1641955678 posted

    Hi Joel,

    There is a caching issue is SP1, and the new attribute is supposed to address it.  But I think we missed some changes in the templates.  In list.aspx, try changing <%= table.DisplayName%> to <%= table.GetDisplayName() %> (and similar change in the other PageTemplates).  If you still see cases that don't work, could you specify exactly what pieces of the UI it is?  i.e. what page, and where in the page?

    thanks!
    David

    Thursday, October 2, 2008 4:40 PM
  • User19825367 posted

    Woo Hoo!!!

     Alright!  Changing it to table.GetDisplayName() did the trick for the table name!  I only checked the list page for now...if I find any more anomalies I will post them here.

     I tried doing something similar for the column:

    Metadata...
    [LocalizedDisplayName(typeof(Resources.WebResources), "UserTable_UserName")]

    public object UserName { get; set; }

    HTML..

    <asp:DynamicField DataField="UserName" HeaderText="<%= column.GetDisplayName() %>"/>

    This however is only returning a blank...the column name is not filling in in the header of the column.

    Any ideas on this one?

    Thanks for all your help David!

    Regards,
    Joel.

     EDIT:

    I've also just noticed that if I try to use the GetDisplayName method on the table object in the Page_Load (in order to set the page title appropriately) I am getting the following compile time error: 
     'System.Web.DynamicData.MetaTable' does not contain a definition for 'GetDisplayName' and no extension method 'GetDisplayName' accepting a first argument of type 'System.Web.DynamicData.MetaTable' could be found (are you missing a using directive or an assembly reference?) 

    Thursday, October 2, 2008 9:05 PM
  • User19825367 posted

    So, does anyone have any ideas on how to localize Column Names or why table.GetDisplayName() would work in the HTML but not in the code behind?

    Regards,
    Joel.

    Saturday, October 4, 2008 10:14 AM
  • User1641955678 posted

    Joel, GetDisplayName is an extension method.  Make sure that you have a 'using Microsoft.Web.DynamicData' in your code behind in order to call it

    David

    Sunday, October 5, 2008 10:41 PM
  • User1641955678 posted

    As for your other question, the problem is that you can't use <%= %> for the attribute.  So when you write HeaderText="<%= column.GetDisplayName() %>", you actually get the literal string "<%= column.GetDisplayName() %>" as your header text.  It looks blank because the browser hides it, but you'll see it if you View Source...

    David

    Sunday, October 5, 2008 10:48 PM
  • User19825367 posted

    Yes, of course!  I should have noticed I was missing the using statement.

    Thank you!

    Joel.

    Monday, October 6, 2008 6:45 AM
  • User19825367 posted

    Hi David,

    Ok, so other than linking to the RowCreated event and setting the header text manually from the resource file, do you see a better way of doing this?  Is there a more declaritive way like for the Table Name?

    Thanks for your help.

    Joel

    Monday, October 6, 2008 7:09 AM
  • User-330204900 posted

    Hi Joel, why don't you write your own extension methos based on the ones in DD Futures:

    /// <summary>
    /// Gets the value of the Description property of a DescriptionAttribute associated with the given column.
    /// </summary>
    /// <param name="column">the column</param>
    /// <returns>The Description property of the DescriptionAttribute, or the default value.</returns>
    public static string GetDescription(this MetaColumn column)
    {
    	var description = column.GetAttribute<DESCRIPTIONATTRIBUTE>();
    	return description == null ? column.Description : description.Description;
    }
    
    /// <summary>
    /// Gets the value of the DisplayName property of a DisplayNameAttribute associated with the given column.
    /// </summary>
    /// <param name="column">the column</param>
    /// <returns>The DisplayName property of the DisplayNameAttribute, or the default value.</returns>
    public static string GetDisplayName(this MetaColumn column)
    {
    	var displayName = column.GetAttribute<DISPLAYNAMEATTRIBUTE>();
    	return displayName == null ? column.DisplayName : displayName.DisplayName;
    }
    

    you could do your I18N in there [:D]

    Monday, October 6, 2008 8:14 AM
  • User19825367 posted

    Great idea Steve.  I will give that a shot.

    I'll let you know how it goes.

    Joel.

    Monday, October 6, 2008 8:20 AM