@Test public void messageFallsBackToClosestAvailableMessage() { assertEquals("Version Deutsch Schweiz", translationService.translate(newFixedLocaleProvider(new Locale("de", "CH", "Non-Existant-Variant")), new String[] { "about.version" })); assertEquals("Only German", translationService.translate(newFixedLocaleProvider(new Locale("de", "CH", "Non-Existant-Variant")), new String[] { "only.de" })); assertEquals("Only in English", translationService.translate(newFixedLocaleProvider(new Locale("de", "CH", "Non-Existant-Variant")), new String[] { "only.en" })); }
@Test public void messageWithBasenameAndLocaleFallsBackToDefaultLocaleIfNotFound() throws Exception { // WHEN String message = translationService.translate(newFixedLocaleProvider(USERLOCALE), LEGACY_BUNDLE, new String[] { "only.en" }); // THEN assertEquals("Only in English legacy", message); }
@Test public void messageFallsBackToDefaultLanguage() { // this key doesn't exist in the french message bundle assertEquals("Version English", translationService.translate(newFixedLocaleProvider(Locale.FRENCH), new String[] { "about.version" })); }
@Test public void messageWithBasename() throws Exception { // WHEN String message = translationService.translate(newFixedLocaleProvider(USERLOCALE), LEGACY_BUNDLE, new String[] { "about.title" }); // THEN assertEquals("Das ist ein Test legacy", message); }
@Test public void givenBasenameFallbacksToDefaultLegacy() throws Exception { // WHEN String message = translationService.translate(newFixedLocaleProvider(USERLOCALE), LEGACY_BUNDLE, new String[] { "about.version" }); // THEN // This is not the behavior we want, but this is the behavior of MessagesManager. assertEquals("Version English from default bundle", message); }
@Test public void messageFallsBackToDefautLocaleFromAVariantLocale() { assertEquals("Only in English", translationService.translate(newFixedLocaleProvider(GERMAN_CH_BASEL), new String[] { "only.en" })); }
@Test public void messageWithBasenameAndLocaleFallsBackToGlobalBundleIfNotFound() throws Exception { // WHEN String message = translationService.translate(newFixedLocaleProvider(USERLOCALE), LEGACY_BUNDLE, new String[] { "only.in.global.bundle" }); // THEN assertEquals("I am only in global bundle English", message); }
@Test public void isDebugReturnsFalseWhenI18nModuleProviderIsNotReady() throws Exception { // GIVEN Provider<I18nModule> i18nModuleProvider = mock(Provider.class); given(i18nModuleProvider.get()).willThrow(RuntimeException.class); final TranslationService translationService = new TranslationServiceImpl(i18nModuleProvider, GuiceUtils.providerForInstance(mock(DefaultMessageBundlesLoader.class))); // WHEN String translatedTextWithoutDebugInformation = translationService.translate(newFixedLocaleProvider(USERLOCALE), new String[] { "about.title" }); // THEN assertThat(translatedTextWithoutDebugInformation, is("about.title")); }
@Test public void messageWithBasenameAndLocale() throws Exception { // WHEN String message = translationService.translate(newFixedLocaleProvider(Locale.ENGLISH), LEGACY_BUNDLE, new String[] { "about.title" }); // THEN assertEquals("This is a test legacy", message); }
@Test public void messageWithGermanLocale() { assertEquals("Das ist ein Titel", translationService.translate(newFixedLocaleProvider(Locale.GERMAN), new String[] { "about.title" })); }
@Test public void messageWithSwissGermanVariantLocale() { assertEquals("Titel Schweiz Basel", translationService.translate(newFixedLocaleProvider(GERMAN_CH_BASEL), new String[] { "about.title" })); }
@Test public void messageNotFound() { assertEquals("not.there", translationService.translate(newFixedLocaleProvider(GERMAN_CH_BASEL), new String[] { "not.there" })); }
@Test public void messageNotFoundWithBasename() { assertEquals("not.there", translationService.translate(newFixedLocaleProvider(GERMAN_CH_BASEL), LEGACY_BUNDLE, new String[] { "not.there" })); }
@Test public void messageWithSwissGermanLocale() { assertEquals("Titel Schweiz", translationService.translate(newFixedLocaleProvider(GERMAN_CH), new String[] { "about.title" })); }
@Test public void messageAvailableOnlyInEnglishWithSystemFallbackLanguageSetAsEnglish() { assertEquals("Only in English", translationService.translate(newFixedLocaleProvider(Locale.GERMAN), new String[] { "only.en" })); }
@Test public void messageWithFrenchLocale() { assertEquals("Ceci n'est pas un test", translationService.translate(newFixedLocaleProvider(Locale.FRENCH), new String[] { "about.title" })); }
@Test public void messageFallsBackToAvailableMessageFromVariantToCountry() { assertEquals("Version Deutsch Schweiz", translationService.translate(newFixedLocaleProvider(GERMAN_CH_BASEL), new String[] { "about.version" })); }
@Test public void debugNewI18nMissingTranslation() throws Exception { //GIVEN i18nModule.setDebug(true); // WHEN String message = translationService.translate(newFixedLocaleProvider(USERLOCALE), new String[] { "nonexisting.key" }); // THEN assertEquals("nonexisting.key\n[nonexisting.key]Locale:de", message); }
@Test public void nullKey() throws Exception { //GIVEN NullKeyGenerator keyGenerator = new NullKeyGenerator(); String[] keys = keyGenerator.keysFor(null, null, null); // WHEN translationService.translate(newFixedLocaleProvider(Locale.ENGLISH), null, keys); // THEN doesn't fail with NPE in TranslationServiceImpl.doGetMessage() }
@Test public void debugNewI18n() throws Exception { //GIVEN i18nModule.setDebug(true); // WHEN String message = translationService.translate(newFixedLocaleProvider(USERLOCALE), new String[] { "more.specific.key", "specific.key", "key" }); // THEN assertEquals("Some translation\n[more.specific.key, >specific.key<, key]Locale:en", message); }