-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #4: implement support for fallback language
- Loading branch information
Showing
10 changed files
with
147 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,71 @@ | ||
using System; | ||
using I18Next.Net.Backends; | ||
using I18Next.Net.Plugins; | ||
using NUnit.Framework; | ||
|
||
namespace I18Next.Net.Tests | ||
{ | ||
[TestFixture] | ||
public class I18NextFixture | ||
{ | ||
private InMemoryBackend _backend; | ||
private I18NextNet _i18next; | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
SetupBackend(); | ||
|
||
var translator = new DefaultTranslator(_backend); | ||
_i18next = new I18NextNet(_backend, translator); | ||
|
||
} | ||
private void SetupBackend() | ||
{ | ||
var backend = new InMemoryBackend(); | ||
|
||
backend.AddTranslation("en", "translation", "exampleKey", "My English text."); | ||
backend.AddTranslation("en", "translation", "exampleKey2", "My English fallback."); | ||
backend.AddTranslation("de", "translation", "exampleKey", "Mein deutscher text."); | ||
|
||
_backend = backend; | ||
} | ||
|
||
[Test] | ||
public void English() | ||
{ | ||
_i18next.Language = "en"; | ||
Assert.AreEqual("My English text.", _i18next.T("exampleKey")); | ||
} | ||
|
||
[Test] | ||
public void German() | ||
{ | ||
_i18next.Language = "de"; | ||
Assert.AreEqual("Mein deutscher text.", _i18next.T("exampleKey")); | ||
} | ||
|
||
[Test] | ||
public void NoFallbackLanguage_MissingTranslation_ReturnsKey() | ||
{ | ||
_i18next.Language = "de"; | ||
Assert.AreEqual("exampleKey2", _i18next.T("exampleKey2")); | ||
} | ||
|
||
[Test] | ||
public void FallbackLanguageIsSet_MissingTranslation_ReturnsFallback() | ||
{ | ||
_i18next.Language = "de"; | ||
_i18next.SetFallbackLanguage("en"); | ||
Assert.AreEqual("My English fallback.", _i18next.T("exampleKey2")); | ||
} | ||
|
||
[Test] | ||
public void Test1() | ||
public void MissingLanguage_ReturnsFallback() | ||
{ | ||
Assert.Pass(); | ||
_i18next.Language = "jp"; | ||
_i18next.SetFallbackLanguage("en"); | ||
Assert.AreEqual("My English fallback.", _i18next.T("exampleKey2")); | ||
} | ||
} | ||
} |
Oops, something went wrong.