-
Notifications
You must be signed in to change notification settings - Fork 36
Localization
sergeyshushlyapin edited this page May 20, 2015
·
10 revisions
Important:
If you are running Sitecore 7.5 or higher, consider using
Sitecore.Abstractions.ITranslateinterface from theSitecore.Abstractionsassembly.
FakeDb supports a simple localization mechanism. You can call the static Sitecore.Globalization.Translate.Text() method and receive a fake localized version of the original text.
There are a couple of options how the text may look like:
-
Translate.Text("Hi!")returns"Hi!*"ifFakeDb.AutoTranslateistrue -
Translate.Text("Hi!")returns"en:Hi!"ifFakeDb.AutoTranslatePrefixis{lang}: -
Translate.Text("Hi!")returns"Hi!_en"ifFakeDb.AutoTranslateSuffixis_{lang}
There are a couple of ways to enable the auto translation:
- Set the
FakeDb.AutoTranslate*settings statically in theApp.configfile - Set the settings dynamically in tests using the
db.Configurationcontext
using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db())
{
db.Configuration.Settings.AutoTranslate = true;
string translatedPhrase = Sitecore.Globalization.Translate.Text("Welcome!");
// note the '*' symbol at the end of the translated phrase
Xunit.Assert.Equal("Welcome!*", translatedPhrase);
}using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db())
{
db.Configuration.Settings.AutoTranslate = true;
db.Configuration.Settings.AutoTranslatePrefix = "{lang}:";
var lang = Sitecore.Globalization.Language.Parse("da");
// translate by the given language
string translatedPhrase
= Sitecore.Globalization.Translate.TextByLanguage("Welcome!", lang);
Xunit.Assert.Equal("da:Welcome!", translatedPhrase);
}