This post has been migrated from www.experimentsincode.com, we apologise if some of the images or content is missing

This post has been migrated, original date 24 Jun 2009 This is for Sitecore 5.3, there is an alternative Sitecore 6 default language provider Imagine a site built in Sitecore that has multiple languages but not all pages are translated into the different language. When a visitor to the site visits a page that has not been translated they normally receive a 404 error. However you may not want this, instead you might want it to use a default language instead. The user will no longer see a 404 error but will have any missing content replaced by the default language. There are two was to do this, we can either create our own set of classes to wrap the XSLT extensions, XSLT controls and code references or we can alter the way the data is pulled from the database. I have decided to go with altering the data pulled from the database because this is less work and easier to manage. The way this solution works is that it checks every item pulled from the database to see what language versions are available for that item. If the item is missing a particular language it will then inject the default language. If you are using SQL Server the class that does the data pulling is called Sitecore.Data.SqlServer.SqlServerDataProvider and can be found in Sitecore.SqlServer.dll. Using the decorator pattern we inherit from this class like so:
    public class SqlServerDataProvider : Sitecore.Data.SqlServer.SqlServerDataProvider
    {

        public SqlServerDataProvider(string connectionString)
            : base(connectionString)
        {
        }
        protected override void LoadItemFields(string itemCondition, string fieldCondition, object[] parameters, Sitecore.Collections.SafeDictionary<ID, Sitecore.Data.DataProviders.PrefetchData> prefetchData)
        {
            base.LoadItemFields(itemCondition, fieldCondition, parameters, prefetchData);

            //set the default language to use
            Language defaultLang;
            Language.TryParse("en", out defaultLang);

            //full list of languages the site uses
            LanguageCollection coll = this.GetLanguages();

            foreach (var data in prefetchData)
            {
                if (data.Value != null)
                {
                    var uris = data.Value.GetVersionUris();
                    //check the item contains the default language before doing anything
                    if (uris.Cast<VersionUri>().Any(x => x.Language == defaultLang))
                    {
                        //get the default language fields
                        var defaultUri = uris.Cast<VersionUri>().First(x => x.Language == defaultLang);
                        //loop through each language
                        foreach (Language lang in coll)
                        {
                            //check if language doesn't exist
                            if (!uris.Cast<VersionUri>().Any(x => x.Language == lang))
                            {
                                //update language with default language values
                                FieldList fields = data.Value.GetFieldList("en", defaultUri.Version.Number);
                                foreach (var field in fields)
                                {
                                    data.Value.AddField(lang.Name, 1, field.Key, field.Value);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
Now that we have our code we need to update the web.config to use our new class. First we need to add our class as a new provider. Find the following section in the Sitecore section of the web.config.
<!-- DATA PROVIDERS -->
<dataProviders>
	 <main type="Sitecore.Data.$(database).$(database)DataProvider, Sitecore.$(database)">-->
	 	 <param ref="connections/$(1)" />
	 	 <Name>$(1)</Name>
	 </main>
Update it as shown below so that you now have two providers:
<dataProviders>
	 <main type="Sitecore.Data.$(database).$(database)DataProvider, Sitecore.$(database)">-->
	 	 <param ref="connections/$(1)" />
	 	 <Name>$(1)</Name>
	 </main>
	 <web type="Demo.Data.SqlServerDataProvider, Demo">
	 	 <param ref="connections/$(1)" />
	 	 <Name>$(1)</Name>
	 </web>
We then just need to update the relevant databases to use this class. I am assuming that only the web database will use this class. In which case find the following section in the web.config:
 <database id="web" singleInstance="true" type="Sitecore.Data.Database, Sitecore.Kernel">
	 <param desc="name">$(id)</param>
	 	 <securityEnabled>true</securityEnabled>
	 	 <dataProviders hint="list:AddDataProvider">
	 	 	 <dataProvider ref="dataProviders/main" param1="$(id)">
Update the providers list to look like this:
<database id="web" singleInstance="true" type="Sitecore.Data.Database, Sitecore.Kernel">
	 <param desc="name">$(id)</param>
	 	 <securityEnabled>true</securityEnabled>
	 	 <dataProviders hint="list:AddDataProvider">
	 	 	 <dataProvider ref="dataProviders/web" param1="$(id)">