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

1public class LanguageQuirksTest
2{
3private const string LanguageWithNoName = @"";
4 
5private class SmartDataProvider : DataProvider
6{
7// can't create an abstract DataProvider
8}
9}

There Is A Language With No Name

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

A Language With No Name Has No Name

1[Test]
2public void ALanguageWithNoNameHasNoName()
3{
4var language = Language.Parse(LanguageWithNoName);
5 
6language.Should().NotBeNull("Sitecore knows there's a language with no name");
7 
8language.Name.Should().BeEmpty("A language with no name has no name. Of course!");
9}

Is There Really A Language With No Name?

1[Test]
2public void LanguageSwitcherDoesNotAgreeWithLanguageManager()
3{
4Action create = () => new LanguageSwitcher(LanguageWithNoName);
5 
6create.ShouldThrow<InvalidOperationException>("Nope, there isn't. Sorry buddy.");
7}

I Default To English

1[Test]
2public void GlobalsDefaultsToUs()
3{
4Globals.Load();
5 
6Globals.DefaultCulture.Name.Should().Be("en-US", "We are in US");
7Globals.DefaultCulture.TwoLetterISOLanguageName.Should().Be("en", "And of course we speak English");
8}
9 
10[Test]
11public void SettingsDefaultsToEn()
12{
13Settings.DefaultLanguage.Should().Be("en", "English is the world language");
14Settings.ClientLanguage.Should().Be("en", "Did I tell you that English is the world language?");
15}

I Default To English and American English

1[Test]
2public void DataProviderKnowsOfTwoLanguages()
3{
4var provider = new SmartDataProvider();
5var context = new CallContext(new DataManager(Database.GetDatabase("master")), 0);
6 
7LanguageCollection languages = provider.GetLanguages(context);
8 
9languages.Should().HaveCount(2);
10 
11languages.Should().Contain(Language.Parse("en"), "English is the world language");
12languages.Should().Contain(Language.Parse("en-US"), "Wait... and so is American English!");
13 
14languages.Should().NotContain(Language.Parse(LanguageWithNoName), "... sorry buddy");
15}

🙂

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