org.xnap.commons.i18n.I18n Java Examples
The following examples show how to use
org.xnap.commons.i18n.I18n.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LocalisationTest.java From phoenicis with GNU Lesser General Public License v3.0 | 6 votes |
@PrepareForTest({ I18nFactory.class, I18n.class }) @Test public synchronized void testTreeTranslatableObject() { final TreeTranslatableObject treeTranslatableObject = new TreeTranslatableObject( new SimpleTranslatableObject("input", "input"), new SimpleTranslatableObject("input", "input")); assertEquals("input", treeTranslatableObject.getItemNotToBeTranslated().getItemToBeTranslated()); assertEquals("input", treeTranslatableObject.getItemNotToBeTranslated().getItemNotToBeTranslated()); assertEquals("input", treeTranslatableObject.getItemToBeTranslated().getItemToBeTranslated()); assertEquals("input", treeTranslatableObject.getItemToBeTranslated().getItemNotToBeTranslated()); final TreeTranslatableObject translatedObject = tr(treeTranslatableObject); assertEquals("input", translatedObject.getItemNotToBeTranslated().getItemToBeTranslated()); assertEquals("input", translatedObject.getItemNotToBeTranslated().getItemNotToBeTranslated()); assertEquals("output", translatedObject.getItemToBeTranslated().getItemToBeTranslated()); assertEquals("input", translatedObject.getItemToBeTranslated().getItemNotToBeTranslated()); }
Example #2
Source File: Localisation.java From phoenicis with GNU Lesser General Public License v3.0 | 5 votes |
private static I18n getI18n() { // init only once if (i18n == null) { i18n = I18nFactory.getI18n(Localisation.class, "Messages"); } return i18n; }
Example #3
Source File: LocalisationTest.java From phoenicis with GNU Lesser General Public License v3.0 | 5 votes |
@Before public void setUp() { mockI18n = mock(I18n.class); PowerMockito.doReturn("output").when(mockI18n).tr("input"); PowerMockito.mockStatic(I18nFactory.class); PowerMockito.when(I18nFactory.getI18n(any(), anyString())).thenReturn(mockI18n); }
Example #4
Source File: LocalisationTest.java From phoenicis with GNU Lesser General Public License v3.0 | 5 votes |
@PrepareForTest({ I18nFactory.class, I18n.class }) @Test public synchronized void testSimpleTranslatableObject() { final SimpleTranslatableObject translatableObject = new SimpleTranslatableObject("input", "input"); assertEquals("input", translatableObject.getItemNotToBeTranslated()); assertEquals("input", translatableObject.getItemToBeTranslated()); final SimpleTranslatableObject translatedObject = tr(translatableObject); assertEquals("input", translatedObject.getItemNotToBeTranslated()); assertEquals("output", translatedObject.getItemToBeTranslated()); }
Example #5
Source File: LocalisationTest.java From phoenicis with GNU Lesser General Public License v3.0 | 5 votes |
@PrepareForTest({ I18nFactory.class, I18n.class }) @Test public synchronized void testSimpleTranslatableObjectWithBuilder() { final SimpleTranslatableObjectBuilder translatableObject = new SimpleTranslatableObjectBuilder.Builder() .withItemNotToBeTranslated("input").withItemToBeTranslated("input").build(); assertEquals("input", translatableObject.getItemNotToBeTranslated()); assertEquals("input", translatableObject.getItemToBeTranslated()); final SimpleTranslatableObjectBuilder translatedObject = tr(translatableObject); assertEquals("input", translatedObject.getItemNotToBeTranslated()); assertEquals("output", translatedObject.getItemToBeTranslated()); }
Example #6
Source File: LocalisationTest.java From phoenicis with GNU Lesser General Public License v3.0 | 5 votes |
@PrepareForTest({ I18nFactory.class, I18n.class }) @Test public synchronized void testTreeTranslatableCollectionObject() { final CollectionsOfTranslatableObject collectionsOfTranslatableObject = new CollectionsOfTranslatableObject( Arrays.asList("input", "input"), Arrays.asList("input", "input")); final CollectionsOfTranslatableObject translatedObject = tr(collectionsOfTranslatableObject); assertEquals(Arrays.asList("input", "input"), translatedObject.getItemNotToBeTranslated()); assertEquals(Arrays.asList("output", "output"), translatedObject.getItemToBeTranslated()); }
Example #7
Source File: I18nExample.java From gettext-commons with GNU Lesser General Public License v2.1 | 4 votes |
public static void main(String[] args) { I18n i18n = I18nFactory.getI18n(I18nExample.class, "Messages"); /* * We do two runs, the first with the orginal locale the second one * with the German locale, to see which messages are translated and * how. */ for (int i = 0; i < 2; i++) { if (i == 0) { print("First run"); } else { print("Second run"); i18n.setLocale(Locale.GERMAN); } /* * This is the method you will be using most of the time. */ print(i18n.tr("This text is marked for translation and is translated")); /* * This method marks the text for translation, but doesn't * translate. This can be used for keys which should be stored * untranslated but should be translated in the user interface. */ String mark = i18n.marktr("This text is marked for translation but not translated"); /* * See in the second run, it's never translated. */ print(mark); /* * Now you can use the text in a variable and it is correctly * translated. */ print(i18n.tr(mark)); /* * A convenience wrapper for MessageFormat.format(String, Object[]). */ print(i18n.tr("Four: {0}", new Integer(4))); /* * This method disambiguates a word which has to be translated * differently depending on how it is used. In our example the * word "chat" is translated differently to German when it is * used as a noun and as a verb. */ print(i18n.trc("chat (verb)", "chat")); print(i18n.trc("chat (noun)", "chat")); /* * I18n.trn handles plurals. The third parameter contains the number * of objects to decide which plural form to use. */ print(i18n.trn("{0} file is open", "{0} files are open", 1, new Integer(1))); print(i18n.trn("{0} file is open", "{0} files are open", 2, new Integer(2))); } }
Example #8
Source File: LocalisationTest.java From phoenicis with GNU Lesser General Public License v3.0 | 4 votes |
@PrepareForTest({ I18nFactory.class, I18n.class }) @Test public synchronized void testTrWithAString() { assertEquals("output", tr("input")); }
Example #9
Source File: LocalisationTest.java From phoenicis with GNU Lesser General Public License v3.0 | 4 votes |
@PrepareForTest({ I18nFactory.class, I18n.class }) @Test public synchronized void testTrWithNull() { assertEquals(null, tr(null)); }