Skip to main content

Back-End Development

Sitecore Language Quirks

Abstract Code@1x.jpg

I am feeling good today and I invite you to read below and smile along with me.

[su_note note_color=”#fafafa”]All tests pass as written on Sitecore 7.1 Update 1. Isolation provided by Sitecore.FakeDb[/su_note]

The Stage

public class LanguageQuirksTest
{
private const string LanguageWithNoName = @"";

private class SmartDataProvider : DataProvider
{
// can't create an abstract DataProvider
}
}

There Is A Language With No Name

[Test]
public void ThereIsALanguageWithNoName()
{
LanguageManager.IsValidLanguageName(LanguageWithNoName)
.Should()
.BeTrue("Of course there's a language with no name");
}

A Language With No Name Has No Name

[Test]
public void ALanguageWithNoNameHasNoName()
{
var language = Language.Parse(LanguageWithNoName);

language.Should().NotBeNull("Sitecore knows there's a language with no name");

language.Name.Should().BeEmpty("A language with no name has no name. Of course!");
}

Is There Really A Language With No Name?

[Test]
public void LanguageSwitcherDoesNotAgreeWithLanguageManager()
{
Action create = () => new LanguageSwitcher(LanguageWithNoName);

create.ShouldThrow<InvalidOperationException>("Nope, there isn't. Sorry buddy.");
}

I Default To English

[Test]
public void GlobalsDefaultsToUs()
{
Globals.Load();

Globals.DefaultCulture.Name.Should().Be("en-US", "We are in US");
Globals.DefaultCulture.TwoLetterISOLanguageName.Should().Be("en", "And of course we speak English");
}

[Test]
public void SettingsDefaultsToEn()
{
Settings.DefaultLanguage.Should().Be("en", "English is the world language");
Settings.ClientLanguage.Should().Be("en", "Did I tell you that English is the world language?");
}

I Default To English and American English

[Test]
public void DataProviderKnowsOfTwoLanguages()
{
var provider = new SmartDataProvider();
var context = new CallContext(new DataManager(Database.GetDatabase("master")), 0);

LanguageCollection languages = provider.GetLanguages(context);

languages.Should().HaveCount(2);

languages.Should().Contain(Language.Parse("en"), "English is the world language");
languages.Should().Contain(Language.Parse("en-US"), "Wait... and so is American English!");

languages.Should().NotContain(Language.Parse(LanguageWithNoName), "... sorry buddy");
}

🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Brian Beckham

As a Sitecore MVP, Brian spends most of his time consulting and architecting software solutions for enterprise-level Sitecore projects.

More from this Author

Follow Us