Example usage for java.util Locale GERMAN

List of usage examples for java.util Locale GERMAN

Introduction

In this page you can find the example usage for java.util Locale GERMAN.

Prototype

Locale GERMAN

To view the source code for java.util Locale GERMAN.

Click Source Link

Document

Useful constant for language.

Usage

From source file:io.github.felsenhower.stine_calendar_bot.main.CallLevelWrapper.java

public CallLevelWrapper(String[] args) throws IOException {
    String username = null;/*  w  w w  .jav a  2 s  .co m*/
    String password = null;
    boolean echoPages = false;
    Path calendarCache = null;
    Path outputFile = null;
    boolean echoCalendar = false;

    // These temporary options don't have descriptions and have their
    // required-value all set to false
    final Options tempOptions = getOptions();

    final CommandLineParser parser = new DefaultParser();
    CommandLine cmd = null;
    StringProvider strings = null;

    // Get the StringProvider
    try {
        cmd = parser.parse(tempOptions, args, true);
        if (cmd.hasOption("language")) {
            String lang = cmd.getOptionValue("language").toLowerCase();
            if (lang.equals("de")) {
                strings = new StringProvider(Locale.GERMAN);
            } else {
                strings = new StringProvider(Locale.ENGLISH);
                if (!lang.equals("en")) {
                    System.err.println(strings.get("HumanReadable.CallLevel.LangNotRecognised", lang));
                }
            }
        } else {
            strings = new StringProvider(new Locale(Locale.getDefault().getLanguage()));
        }
    } catch (Exception e) {
        strings = new StringProvider(Locale.ENGLISH);
    }

    this.strings = strings;
    this.cliStrings = strings.from("HumanReadable.CallLevel");
    this.messages = strings.from("HumanReadable.Messages");
    this.appInfo = strings.from("MachineReadable.App");

    // Get the localised options, with all required fields enabled as well.
    // Note that we are not yet applying the options to any command line,
    // because we still want to exit if only the help screen shall be
    // displayed first, but of course, we do need the localised options
    // here.
    this.isLangInitialised = true;
    this.options = getOptions();

    try {
        // If no arguments are supplied, or --help is used, we will exit
        // after printing the help screen
        if (cmd.hasOption("help") || (cmd.hasOption("language") && cmd.getOptions().length == 1)) {
            printHelp();
        }

        cmd = parser.parse(this.options, args, false);

        username = cmd.getOptionValue("user");

        // URL-decode the password (STiNE doesn't actually allow special
        // chars in passwords, but meh...)
        password = URLDecoder.decode(cmd.getOptionValue("pass"), "UTF-8");
        // Double-dash signals that the password shall be read from stdin
        if (password.equals("--")) {
            password = readPassword(messages.get("PasswordQuery"), messages.get("PasswordFallbackMsg"));
        }

        echoPages = cmd.hasOption("echo");

        // the cache-dir argument is optional, so we read it with a default
        // value
        calendarCache = Paths
                .get(cmd.getOptionValue("cache-dir", strings.get("MachineReadable.Paths.CalendarCache")))
                .toAbsolutePath();

        // output-argument is optional as well, but this time we check if
        // double-dash is specified (for echo to stdout)
        String outputStr = cmd.getOptionValue("output", strings.get("MachineReadable.Paths.OutputFile"));
        if (outputStr.equals("--")) {
            echoCalendar = true;
            outputFile = null;
        } else {
            echoCalendar = false;
            outputFile = Paths.get(outputStr).toAbsolutePath();
        }

    } catch (UnrecognizedOptionException e) {
        System.err.println(messages.get("UnrecognisedOption", e.getOption().toString()));
        this.printHelp();
    } catch (MissingOptionException e) {
        // e.getMissingOptions() is just extremely horribly designed and
        // here is why:
        //
        // It returns an unparametrised list, to make your job especially
        // hard, whose elements may be:
        // - String-instances, if there are single independent options
        // missing (NOT the stupid Option itself, just why????)
        // - OptionGroup-instances, if there are whole OptionGroups missing
        // (This time the actual OptionGroup and not an unparametrised Set
        // that may or may not contain an Option, how inconsequential).
        // - Basically anything because the programmer who wrote that
        // function was clearly high and is most probably not to be trusted.
        //
        // This makes the job of actually displaying all the options as a
        // comma-separated list unnecessarily hard and hence leads to this
        // ugly contraption of Java-8-statements. But hey, at least it's not
        // as ugly as the Java 7 version (for me at least).
        // Sorry!
        // TODO: Write better code.
        // TODO: Write my own command line interpreter, with blackjack and
        // hookers.
        try {
            System.err.println(messages.get("MissingRequiredOption", ((List<?>) (e.getMissingOptions()))
                    .stream().filter(Object.class::isInstance).map(Object.class::cast).map(o -> {
                        if (o instanceof String) {
                            return Collections.singletonList(options.getOption((String) o));
                        } else {
                            return ((OptionGroup) o).getOptions();
                        }
                    }).flatMap(o -> o.stream()).filter(Option.class::isInstance).map(Option.class::cast)
                    .map(o -> o.getLongOpt()).collect(Collectors.joining(", "))));
            this.printHelp();
        } catch (Exception totallyMoronicException) {
            throw new RuntimeException("I hate 3rd party libraries!", totallyMoronicException);
        }
    } catch (MissingArgumentException e) {
        System.err.println(messages.get("MissingRequiredArgument", e.getOption().getLongOpt()));
        this.printHelp();
    } catch (ParseException e) {
        System.err.println(messages.get("CallLevelParsingException", e.getMessage()));
    }

    this.username = username;
    this.password = password;
    this.echoPages = echoPages;
    this.calendarCache = calendarCache;
    this.outputFile = outputFile;
    this.echoCalendar = echoCalendar;
}

From source file:org.projectforge.core.QueryFilter.java

/**
 * Locale is needed for lucene stemmers (hibernate search).
 * @return//from   ww w .  jav  a 2s. c  o  m
 */
public Locale getLocale() {
    if (locale == null) {
        return Locale.GERMAN;
    }
    return locale;
}

From source file:org.marketcetera.util.log.I18NMessageProviderTest.java

@Test
public void retrievals() {
    assertEquals("Hello", TestMessages.PROVIDER.getText(TestMessages.HELLO_MSG));
    assertEquals("Hello World!", TestMessages.PROVIDER.getText(TestMessages.HELLO_TITLE, "World"));
    assertEquals("Bonjour", TestMessages.PROVIDER.getText(Locale.FRENCH, TestMessages.HELLO_MSG));
    assertEquals("Bonjour Le Monde!",
            TestMessages.PROVIDER.getText(Locale.FRENCH, TestMessages.HELLO_TITLE, "Le Monde"));

    Locale saved = Locale.getDefault();
    try {/*w w  w. j a va2  s  .c om*/
        Locale.setDefault(Locale.ROOT);
        assertEquals("Hello", TestMessages.PROVIDER.getText(Locale.GERMAN, TestMessages.HELLO_MSG));
        Locale.setDefault(Locale.JAPANESE);
        assertEquals("Hello", TestMessages.PROVIDER.getText(Locale.GERMAN, TestMessages.HELLO_MSG));
        Locale.setDefault(Locale.FRENCH);
        assertEquals("Bonjour", TestMessages.PROVIDER.getText(Locale.GERMAN, TestMessages.HELLO_MSG));
    } finally {
        Locale.setDefault(saved);
    }

    assertEquals("Hello a {0} 'a' \"a\" b!", TestMessages.PROVIDER.getText(TestMessages.HELLO_ECHO, "a", "b"));
    assertEquals("Bonjour a {0} 'a' \"a\" {1}!",
            TestMessages.PROVIDER.getText(Locale.FRENCH, TestMessages.HELLO_ECHO, "a"));
    assertEquals("Bonjour a {0} 'a' \"a\" b!",
            TestMessages.PROVIDER.getText(Locale.FRENCH, TestMessages.HELLO_ECHO, "a", "b", "c"));

    assertEquals("There are no orders ma'am.", TestMessages.PROVIDER.getText(TestMessages.CHOICE_MSG, 0));
    assertEquals("There is just one order ma'am.", TestMessages.PROVIDER.getText(TestMessages.CHOICE_MSG, 1));
    assertEquals("There are 2 orders ma'am.", TestMessages.PROVIDER.getText(TestMessages.CHOICE_MSG, 2));

    assertEquals("Pas des ordres ma'am.",
            TestMessages.PROVIDER.getText(Locale.FRENCH, TestMessages.CHOICE_MSG, 0));
    assertEquals("Seulemont un ordre ma'am.",
            TestMessages.PROVIDER.getText(Locale.FRENCH, TestMessages.CHOICE_MSG, 1));
    assertEquals("Il y a 2 ordres ma'am.",
            TestMessages.PROVIDER.getText(Locale.FRENCH, TestMessages.CHOICE_MSG, 2));

    assertEquals("Hello {0}!", TestMessages.PROVIDER.getText(TestMessages.HELLO_TITLE, (Object[]) null));
    assertEquals("Hello null!", TestMessages.PROVIDER.getText(TestMessages.HELLO_TITLE, (Object) null));

    ActiveLocale.setProcessLocale(Locale.FRENCH);
    assertEquals("Bonjour", TestMessages.PROVIDER.getText(TestMessages.HELLO_MSG));
    assertEquals("Bonjour Le Monde!", TestMessages.PROVIDER.getText(TestMessages.HELLO_TITLE, "Le Monde"));
}

From source file:com.sun.faces.demotest.cardemo.TestCarDemo.java

/**
 * <p>Load the main page.  Assumptions: there are exactly four
 * buttons, in a certain order, to select each locale.  For each
 * button, press it, and call doStoreFront() on the result.</p>
 *//*from w w  w  .ja  v  a  2s  . c  o m*/

public void testCarDemo() throws Exception {

    // for each of the language links run the test
    HtmlPage page = (HtmlPage) getInitialPage();
    List buttons = getAllElementsOfGivenClass(page, null, HtmlSubmitInput.class);
    HtmlSubmitInput button = null;
    int i, j = 0;
    Locale[] locales = { Locale.ENGLISH, Locale.GERMAN, Locale.FRENCH, new Locale("es", "") };

    for (i = 0; i < locales.length; i++) {
        resources = ResourceBundle.getBundle("carstore.bundles.Resources", locales[i]);
        carBundles = new ResourceBundle[carBundleNames.length];
        for (j = 0; j < carBundleNames.length; j++) {
            carBundles[j] = ResourceBundle.getBundle(carBundleNames[j], locales[i]);
        }

        button = (HtmlSubmitInput) buttons.get(i);
        if (log.isTraceEnabled()) {
            log.trace("Running test for language: " + button.asText());
        }
        doStoreFront((HtmlPage) button.click());
    }
}

From source file:org.techytax.helper.AmountHelper.java

public static String formatWithEuroSymbol(BigDecimal amount) {
    DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.GERMAN);
    otherSymbols.setDecimalSeparator(',');
    otherSymbols.setGroupingSeparator('.');
    DecimalFormat df = new DecimalFormat(" ###,###,###,##0.00", otherSymbols);
    return df.format(amount.doubleValue());
}

From source file:org.owasp.webgoat.service.LabelServiceTest.java

@Test
@WithMockUser(username = "guest", password = "guest")
public void withLocale() throws Exception {
    when(labelProvider.getLabels(Locale.GERMAN)).thenReturn(Maps.newHashMap("key", "value"));
    mockMvc.perform(MockMvcRequestBuilders.get(URL_LABELS_MVC).param("lang", "de")).andExpect(status().isOk())
            .andExpect(jsonPath("key", CoreMatchers.is("value")));
}

From source file:de.jfachwert.pruefung.NumberValidator.java

private static Locale guessLocale(String value) {
    return value.matches("\\d+(\\.\\d{3})*(,\\d+)?") ? Locale.GERMAN : Locale.ENGLISH;
}

From source file:org.omnaest.i18nbinder.internal.facade.I18nFacadeTest.java

@Test
public void testSimilarNamedResources() {
    Locale locale = Locale.GERMAN;
    I18nFacade i18nFacade = new I18nFacade(locale);
    assertEquals("wert1", i18nFacade.I18n.Sub1.Shared.getMyPropertyKey1());
    assertEquals("wert3", i18nFacade.I18n.Sub2.Shared.getMyPropertyKey3());
}

From source file:com.robestone.hudson.compactcolumns.CompactColumnsTest.java

public void testDateFormats() {
    doTestDateFormats(Locale.US, DateFormat.SHORT, "6/24/10");
    doTestDateFormats(Locale.US, DateFormat.MEDIUM, "Jun 24, 2010");
    doTestDateFormats(Locale.GERMAN, DateFormat.SHORT, "24.06.10");
}

From source file:de.unentscheidbar.validation.DefaultMessageTextGetterTest.java

@Test
public void testDefaultMessageTexts() {

    Locale[] locales = { Locale.ROOT, Locale.GERMAN };

    Reflections r = new Reflections(new ConfigurationBuilder()
            .setUrls(ClasspathHelper.forPackage(ClassUtils.getPackageName(Validators.class)))
            .setScanners(new ResourcesScanner(), new SubTypesScanner(false)));

    Collection<Class<? extends Id>> defaultMessageClasses = Collections2.filter(
            r.getSubTypesOf(ValidationMessage.Id.class), Predicates.and(IS_NOT_ABSTRACT, IsTestClass.NO));
    Assert.assertTrue("Suspiciously few message ID classes found", defaultMessageClasses.size() > 10);

    MessageTextGetter mtg = Validation.defaultMessageTextGetter();

    for (Class<? extends Id> idClass : defaultMessageClasses) {
        /* only works with enums atm (all default message ids are enums) */
        if (!idClass.isEnum()) {
            Assert.fail("Cannot test " + idClass.getName());
        }/*from w  ww.  j  av  a2 s. co m*/
        for (Id id : idClass.getEnumConstants()) {
            for (Locale locale : locales) {
                Assert.assertTrue("Missing default message text for " + locale + " -> "
                        + id.getClass().getName() + " -> " + id.name(), mtg.hasText(id, locale));
            }
        }
    }
}