Repository extension for Localization.

Aug 18, 2014 at 1:27 AM
Hi Le, your framework is really cool and we are really happy to work with it.

In this moment we are implementing a multi-language application and we want to encapsulate the translation logic inside the repository.

In our multi-language solution each our localizable entities have a child entity with its translations, and we build some special methods on our custom repository and in the service layer for returning the entity with it's strings in the current culture language.

However, we want to go a bit further an encapsulate the localization logic inside a special repository that should be used by the localizable entities. We don't want to use "special" services to obtain the localized objects...

Which is the best way to do that?

1) Creating a new localizable repository that inherits from your repository and override the methods that return localized objects?
2) Create one custom repository for each localized entity? In your solution custom repositories are extensions to your base repository, so methods can be override.
?) are there more possibilities?

Thanks for your great work and your help.
Aug 18, 2014 at 3:35 PM

Does this localized entity map to a SQL table?
Could you elaborate a bit more on what localization logic is?

Aug 20, 2014 at 12:41 AM
Edited Aug 20, 2014 at 12:42 AM
Yes, I have a localization table for each localizable entity. In the localization table are located all the localizable properties and in the main entity we have the non localizable properties. Additionally, in the main entity we have the default values. The localization table is an entity related to the main entity by a "Translations" relationship.

For instance in my main entity I have a non mappable calculated property that returns the value in the correct language or the text in the default language if isn`t translated.
    public string Name
        get { 
            string currentCultureName = Thread.CurrentThread.CurrentUICulture.Name;
            if (currentCultureName.Equals("es-CO")) { // Replace for a web.config value
                return this.DefaultName;
            } else {
                    string text = this.Translations.FirstOrDefault(t => t.LanguageCode.Equals(currentCultureName)).Name;
                    return string.IsNullOrWhiteSpace(text) ? this.Name : text;
                    return this.DefaultName;
        set {
            DefaultName = value;

In order to put this to work I need to do a eager loading of the "Tranlations" relationship. So, I create a subclass of your Repository class and added .Include("Translations") to all "retrieve" methods. For instance:
    public override IQueryable<TEntity> Queryable()
        return base.Queryable().Include("Translations").Include("Translations");
What do you think? do you have some suggestions to make the use of your repository a bit cleaner?

Thanks in advance.
Aug 20, 2014 at 6:14 AM
Edited Aug 20, 2014 at 6:15 AM
Apologize yyie, I'm still unclear of what you are trying to achieve here, if needed, you can request for a scheduled session on the Documentation page, this way I can see your actual project and files to better understand what your trying to do.
Aug 21, 2014 at 4:24 PM
Thanks Le, don't worry I made it work ... I'm not sure if is the cleanest solution but it works.

One last question ... suppose that you want to override or modify the logic of one of your repository methods ... which is the best way to go? create a sub class of your repository? or do theres another way to do it?

Thanks for your time
Aug 21, 2014 at 8:47 PM
Depends on the concern of what your adding.
  1. Business logic, you need to override the methods in your Service and add there.
  2. CRUD (database) related code, simply extend the Repository, you shouldn't need to inherit.
Aug 22, 2014 at 3:54 PM
Ok thanks, and if you need to modify one of the generic methods? For instance the Insert?
Sep 12, 2014 at 11:21 PM
You should override the Service Insert method, here you can add pre and post logic, we've add comments to where you can do this here:
Marked as answer by lelong37 on 9/12/2014 at 3:21 PM