/** * Get the message written in the current locale. * * @return the message */ public String getMessageString() { return this.message.text(this.parameters); }
public static Set<String> getLocalizationProblems( Locale locale ) { return I18n.getLocalizationProblems(CommonI18n.class, locale); } }
public static Set<Locale> getLocalizationProblemLocales() { return I18n.getLocalizationProblemLocales(CommonI18n.class); }
private String rawText( Locale locale ) { assert locale != null; localize(i18nClass, locale); // Check if text exists String text = localeToTextMap.get(locale); if (text != null) { return text; } // If not, there was a problem, so throw it within an exception so upstream callers can tell the difference between normal // text and problem text. throw new SystemFailureException(problem(locale)); }
@Test public void shouldNotHaveLocalicationProblemIfPropertyDuplicate() { I18n.initialize(TestI18nDuplicateProperty.class); TestI18nDuplicateProperty.testMessage.text("test"); assertThat(I18n.getLocalizationProblems(TestI18nDuplicateProperty.class).isEmpty(), is(true)); assertThat(I18n.getLocalizationProblemLocales(TestI18nDuplicateProperty.class).isEmpty(), is(true)); }
@Test public void shouldGetLocalizationProblemsForDefaultLocaleIfNoLocaleSupplied() { I18n.initialize(TestI18nUnusedProperty.class); TestI18nUnusedProperty.testMessage.text("test"); assertThat(I18n.getLocalizationProblems(TestI18nUnusedProperty.class, null).isEmpty(), is(false)); }
@Test public void shouldHaveProblemIfMissingLocalization() { I18n.initialize(TestI18nMissingLocalization.class); assertThat(TestI18nMissingLocalization.testMessage.hasProblem(), is(true)); String problem = TestI18nMissingLocalization.testMessage.problem(); assertThat(problem, is(CommonI18n.i18nLocalizationProblems.text(TestI18nMissingLocalization.class, Locale.getDefault()))); System.out.println("Problem: " + problem); }
@Test public void shouldNotHaveProblems() throws Exception { for (Field fld : i18nClass.getDeclaredFields()) { if (fld.getType() == I18n.class && (fld.getModifiers() & Modifier.PUBLIC) == Modifier.PUBLIC && (fld.getModifiers() & Modifier.STATIC) == Modifier.STATIC && (fld.getModifiers() & Modifier.FINAL) != Modifier.FINAL) { I18n i18n = (I18n)fld.get(null); if (i18n.hasProblem()) { fail(i18n.problem()); } } } // Check for global problems after checking field problems since global problems are detected lazily upon field usage Set<Locale> locales = I18n.getLocalizationProblemLocales(i18nClass); if (!locales.isEmpty()) { for (Locale locale : locales) { Set<String> problems = I18n.getLocalizationProblems(i18nClass, locale); try { assertThat(problems.isEmpty(), is(true)); } catch (AssertionError error) { fail(problems.iterator().next()); } } } }
@Test public void shouldNotHaveLocalizationProblemsAfterInitializationButBeforeLocalization() { I18n.initialize(TestI18nUnusedProperty.class); assertThat(I18n.getLocalizationProblems(TestI18nUnusedProperty.class, null).isEmpty(), is(true)); assertThat(I18n.getLocalizationProblemLocales(TestI18nUnusedProperty.class).isEmpty(), is(true)); }
/** * @return The problem encountered while localizing this internationalization object to the default locale, or * <code>null</code> if none was encountered. */ public String problem() { return problem(null); }
@Test public void shouldHaveProblemIfPropertyDuplicate() { I18n.initialize(TestI18nDuplicateProperty.class); assertThat(TestI18nDuplicateProperty.testMessage.hasProblem(), is(true)); String problem = TestI18nDuplicateProperty.testMessage.problem(); assertThat(problem, notNullValue()); System.out.println("Problem: " + problem); }
@Test public void shouldBeLocalizedIfAskedForProblem() { I18n.initialize(TestI18nDuplicateProperty.class); TestI18nDuplicateProperty.testMessage.problem(); assertThat(TestI18nDuplicateProperty.testMessage.localeToTextMap.get(Locale.getDefault()), notNullValue()); assertThat(TestI18nDuplicateProperty.testMessage.localeToProblemMap.get(Locale.getDefault()), notNullValue()); }
&& (fld.getModifiers() & Modifier.FINAL) != Modifier.FINAL) { I18n i18n = (I18n)fld.get(null); if (i18n.hasProblem()) { fail(i18n.problem());
@Test public void shouldNotHaveLocalicationProblemIfPropertyMissing() { I18n.initialize(TestI18nMissingProperty.class); TestI18nMissingProperty.testMessage1.text("test"); assertThat(I18n.getLocalizationProblems(TestI18nMissingProperty.class).isEmpty(), is(true)); assertThat(I18n.getLocalizationProblemLocales(TestI18nMissingProperty.class).isEmpty(), is(true)); }
/** * @return The problem encountered while localizing this internationalization object to the default locale, or * <code>null</code> if none was encountered. */ public String problem() { return problem(null); }
private String rawText( Locale locale ) { assert locale != null; localize(i18nClass, locale); // Check if text exists String text = localeToTextMap.get(locale); if (text != null) { return text; } // If not, there was a problem, so throw it within an exception so upstream callers can tell the difference between normal // text and problem text. throw new SystemFailureException(problem(locale)); }
@Test public void shouldHaveProblemIfPropertyMissing() { I18n.initialize(TestI18nMissingProperty.class); assertThat(TestI18nMissingProperty.testMessage1.hasProblem(), is(true)); String problem = TestI18nMissingProperty.testMessage1.problem(); assertThat(problem, notNullValue()); System.out.println("Problem: " + problem); }
public UuidAlreadyExistsException( String repositorySourceName, UUID uuid, String pathAsString, String workspaceName ) { super(repositorySourceName, GraphI18n.nodeAlreadyExistsWithUuid.text(uuid, pathAsString, workspaceName)); }
@Test public void shouldHaveLocalicationProblemIfMissingLocalization() { I18n.initialize(TestI18nMissingLocalization.class); TestI18nMissingLocalization.testMessage.text(); assertThat(I18n.getLocalizationProblems(TestI18nMissingLocalization.class).size(), is(1)); assertThat(I18n.getLocalizationProblems(TestI18nMissingLocalization.class).iterator().next(), is(CommonI18n.i18nLocalizationFileNotFound.text(TestI18nMissingLocalization.class.getName()))); assertThat(I18n.getLocalizationProblemLocales(TestI18nMissingLocalization.class).size(), is(1)); assertThat(I18n.getLocalizationProblemLocales(TestI18nMissingLocalization.class).iterator().next(), is(Locale.getDefault())); }
public static Set<String> getLocalizationProblems( Locale locale ) { return I18n.getLocalizationProblems(CommonI18n.class, locale); } }