Tuesday, May 12, 2015

Localize Property Name Based on Content Language

We recently had a client request that a page property have a different display name for each language branch.  The function of the property was as an identifier and would always be used the same in the back end but the editors in each country had a different name for the property.

This isn't a particularly inspired solution, but I'm hoping to save someone else the time it took to stumble upon this.

It is possible to localize EPi property names using the built in Display attribute and keeping the translations in resources files (see this stackoverflow post here), but this is only based on the UI language in Edit/Admin mode and not on content language.

I created an EditorDescriptor that will take the string entered in the Name field and try to translate it using the registered LocalizationService (whatever that may be).  An important thing to note is the EditorDescriptorBehavior.  We have to have it as EditorDescriptorBehavior.PlaceLast to ensure that any other logic to get the Display Name (built in translation, etc) does not interfere with what we want displayed.

Code


[EditorDescriptorRegistration(TargetType = typeof(String), UIHint = SiteUIHints.LocalizedDisplay, EditorDescriptorBehavior = EditorDescriptorBehavior.PlaceLast)]
public class LocalizableDisplayEditorDescriptor : EditorDescriptor
{
   public override void ModifyMetadata(ExtendedMetadata metadata, IEnumerable<Attribute> attributes)
   {
      base.ModifyMetadata(metadata, attributes);

      Attribute attr = attributes.FirstOrDefault(a => a.GetType() == typeof(DisplayAttribute));
      if (attr != null)
      {
         string translated =                                     

             ServiceLocator.Current.GetInstance<LocalizationService().GetStringByCulture(metadata.DisplayName, 
             FallbackBehaviors.None, ContentLanguage.PreferredCulture);

         if (!string.IsNullOrWhiteSpace(translated))
            metadata.DisplayName = translated;
      }
   }
}



Usage

[UIHint(SiteUIHints.LocalizedDisplay)]
[Display(Name = "/properties/InternalId/displayname", Order = 200)]
public virtual string InternalId { get; set; }

35 comments :

  1. Howdy. Very nice web site!! Guy .. Excellent .. Superb .. I will bookmark this site and take the feeds additionally…I am glad to find a lot of helpful info here within the article. Thank you for sharing… Boulevard 88 Price

    ReplyDelete
  2. Great Article it its really informative and innovative keep us posted with new updates. its was really valuable. thanks a lot. villa for sale Nagueles

    ReplyDelete
  3. Excellent article. Very interesting to read. I really love to read such a nice article. Thanks! keep rocking. Riviere Jiak Kim Street

    ReplyDelete
  4. Mmm.. good to be here in your article or post, whatever, I think I should also work hard for my own website like I see some good and updated working in your site. House blog

    ReplyDelete
  5. You have done a great job. I will definitely dig it and personally recommend to my friends. I am confident they will be benefited from this site. General Contractor Maryland

    ReplyDelete
  6. I got what you mean, thanksfor posting .Woh I am happyto find this website through google. Las Colinas Properties For Sale

    ReplyDelete
  7. Hiya, I am really glad I have found this information. Today bloggers publish just about gossips and web and this is really annoying. A good web site with interesting content, that’s what I need. Thanks for keeping this site, I’ll be visiting it. Do you do newsletters? Can’t find it. apartemen jakarta selatan

    ReplyDelete
  8. Thank you for taking the time to publish this information very useful! Kopar at Newton

    ReplyDelete
  9. The next time I read a blog, I hope that it doesnt disappoint me as much as this one. I mean, I know it was my choice to read, but I actually thought you have something interesting to say. All I hear is a bunch of whining about something that you could fix if you werent too busy looking for attention. Assertiveness Training Brisbane

    ReplyDelete
  10. I was just browsing through the internet looking for some information and came across your blog. I am impressed by the information that you have on this blog. It shows how well you understand this subject. Bookmarked this page, will come back for more. Costa Del Sol Property For Sale

    ReplyDelete
  11. Algarve Property For Sale When your website or blog goes live for the first time, it is exciting. That is until you realize no one but you and your.

    ReplyDelete
  12. nature is definately not expensive. go on a hike with friends, or just explore a forest. there are always creeks to walk thru and all kinds of colorful plants and flowers. even frisbee golf is fun, free, and good exercise best real estate agency manila

    ReplyDelete
  13. Excellent! I thank you your contribution to this matter. It has been insightful. warehouse to let

    ReplyDelete
  14. On the off chance that you see this documentation and consider in the evaluating cycle for the property, it is insightful to consider the genuine freedom of the valuation when it was done and its significance to the current market. https://yes-mallorca-property.com

    ReplyDelete
  15. Is the property in good condition and is it in a good location? These should be crucial considerations, as you will either want to let the property, or sell it to another property investor or home-buyer. property wealth advisor

    ReplyDelete
  16. Our profit for this speculation will be driven by two essential factors: our rental salary and the energy about the property estimation. Along these lines, we should start by determining rental salary and the valuation for the property in thought. https://yes-mallorca-property.com/information/faq/general-issues/

    ReplyDelete
  17. A Property Advisor works for a business building administration organization to oversee and give office upkeep and fixes, parking garage fixes and clearing administrations, pressure washing and hydro-cleaning, mass garbage evacuation and business painting while keeping the you, the customer, exceptional through the whole cycle and guaranteeing fulfillment investment property advice

    ReplyDelete
  18. Castle hill has many caves, connected together during the Turkish occupation for military use, and these seen through guided tours. budapest rental

    ReplyDelete
  19. it has a frame with different sections or levels allowing more than one (usually two) person to sleep. The individual frames are stacked one on top of the other. If the room has limited floor space then these are a must have. You generally find these in ship cabins, army dormitories, hostels, army garrisons, summer campsites, universities, jails etc. bed with slide

    ReplyDelete
  20. They define your floor plan, divvying up the footprint of your space into multiple rooms. Walls Apartment For Rent In Hcmc support artwork, bookshelves coat hooks, mirrors, and lighting

    ReplyDelete
  21. Howdy! This article could not be written any better! Going through this article reminds me of my previous roommate! He celebrity homes continually kept preaching about this.

    ReplyDelete
  22. We Buy Houses in Savannah on your terms. We offer We buy houses Savannah, GA an alternative solution to listing your home with a real estate agent. If you need to sell your house fast in the Savannah area, we House buyers Savannah, GA are serious about buying your house!

    ReplyDelete
  23. Here at We Buy Sell my home fast Savannah, GA In Savannah, our goal is to educate homeowners about all of their selling options. If you need to sell your house in Savannah or the Sell my home fast Savannah, GA surrounding areas, we will help you learn about your options.

    ReplyDelete
  24. We Buy Houses in New Jersey on your terms. We offer an alternative solution to listing your home with a real estate agent. If you need to sell your house fast in the New Jersey area, we are serious about buying your house.Cash for houses Savannah, GA

    ReplyDelete
  25. To help protect buyers from misrepresented square footage the Real Estate Council of Alberta recently announced Calgary Luxury Homes new guidelines regarding home measurement in the province.

    ReplyDelete
  26. We take care of the management of rental and communal property of any size - regardless of whether it is apartments or commercial space. You determine the tasks that our competent employees carry out according to your specifications.Hauaverwalter Essen

    ReplyDelete
  27. Our company is currently selling properties in Albania in the areas with the highest demand by foreign and local buyers. First, we listen carefully to what our clients are looking for.Apartament for sale in Saranda

    ReplyDelete
  28. If you have a property to sell, we recommend finding a buyer for your existing property before starting your search. Early preparation is key to a successful sale – we can help you establish its market value and find you a buyer.Solihull Estate & Lettings Agents

    ReplyDelete
  29. Iranian-Realtor.com is the Persian leading real estate and rental marketplace dedicated to empowering consumers Persian Real Estate Agents Los Angeles with data, inspiration, and knowledge around the place they call home.

    ReplyDelete
  30. The bed mattress is a great place to sleep. It is a good way to keep your cheap truck mattress

    ReplyDelete
  31. Your content is nothing short of brilliant in many ways. I think this is engaging and eye-opening material. Thank you so much for caring about your content and your readers. hausverwalter duisburg

    ReplyDelete
  32. Nice post! This is a very nice blog that I will definitively come back to more times this year! Thanks for informative post. bridging loan

    ReplyDelete
  33. Buying a home is one of the most important decisions you will make, and our local experts at eXp Realty are here to make the process as easy as possible. Real Estate near Bloomsburg, Pennsylvania

    ReplyDelete
  34. Aw, this was a very nice post. Taking the time and actual effort to produce a superb article… but what can I say… I procrastinate a whole lot and never manage to get anything done.how do you become an estate agent

    ReplyDelete