Separating Chrome and Content
Let’s say that the dear Jennifer Aniston accepts my invitation to use Charlie to host her website. She logs in because she wants to add her newest film to the Filmography page of her website. She navigates to the English version of her Filmography page, and clicks the Edit Content button. Here is what she might see:
While that might be a fairly unexciting editor screen, it will allow Jen to update the page. She then navigates to the Russian version of her Filmography page, and clicks to edit its content. Now, what should she see?
If we have blindly implemented globalization using recommended “best practices,” we will have set the thread’s culture to Russian, so that the page content pulled from the database is the Russian version of that page. That sounds logical enough, since if Jen wants to edit the Russian version of her page, there’s no sense in setting the thread culture to French or Japanese, is there?
I disagree. If we set the thread culture to Russian, here is the page that Jen will see:
That is not want Jen wants to see. She might know how Wanted is spelled in Russian and can therefore edit the Russian version of her Filmography page, but she cannot read Russian and does not want options presented to her in that language. She wants to see the following:
What this means is that it is wrong to use thread culture as the sole means by which a webpage is localized. In order to do it right, it is necessary to distinguish between chrome and content. Chrome is the user interface stuff, such as the buttons and menus on the page, and it must be considered separately from the content of the page. That is why, in Charlie’s WebContext object, two separate cultures are exposed.
// ************************************************* // Culture Property // /// <summary> /// Gets the culture to be used in presenting the /// chrome of a webpage. /// </summary> // // ************************************************* public CultureInfo Culture { get { return this.Thread.CurrentUICulture; } } // ************************************************* // ContentCulture Property // /// <summary> /// Gets and sets the culture to be used in /// presenting the content of a webpage. /// </summary> // // ************************************************* public CultureInfo ContentCulture { get { if (this.contentCulture != null) return this.contentCulture; return this.Culture; } set { this.contentCulture = value; } } private CultureInfo contentCulture = null;
The Culture property is the culture used to present the chrome of the webpage. This is done by setting the culture of the executing thread to the preferred culture of the user, not the culture of the content to be displayed. It is the ContentCulture that is used to present the content of the page. This content culture may be the same as the chrome culture, but it may not.
This use of two separate cultures has wide-ranging implications in Charlie’s code, so I am thankful that the aardvark encouraged me to write down that globalization should be addressed very early.
by Alister Jones | Next up: Localizing the Chrome →
----
Post a Comment