View Javadoc
1   /*
2    * SPDX-FileCopyrightText: Copyright (c) 2012-2026 Yegor Bugayenko
3    * SPDX-License-Identifier: MIT
4    */
5   package com.jcabi.ssl.maven.plugin;
6   
7   import java.util.HashMap;
8   import java.util.Locale;
9   import java.util.Map;
10  
11  /**
12   * Translates word yes to different languages.
13   *
14   * @since 0.12
15   * @checkstyle MultipleStringLiteralsCheck (100 lines)
16   */
17  public final class Yes {
18      /**
19       * Map from 2-letter language codes to translations of word yes into that
20       * language.
21       */
22      private final transient Map<String, String> translations;
23  
24      /**
25       * Ctor.
26       */
27      @SuppressWarnings("PMD.ConstructorOnlyInitializesOrCallOtherConstructors")
28      public Yes() {
29          this.translations = new HashMap<String, String>();
30          this.translations.put("en", "yes");
31          this.translations.put("de", "ja");
32          this.translations.put("fr", "oui");
33          this.translations.put("ru", "да");
34          this.translations.put("es", "sí");
35          this.translations.put("ua", "так");
36          this.translations.put("jp", "はい");
37      }
38  
39      /**
40       * Translates word yes to a language.
41       * @param locale Locate specifying the language.
42       * @return Word yes translated to a language.
43       */
44      public String translate(final Locale locale) {
45          final String language = locale.getLanguage();
46          final String translation = this.translations.get(language);
47          if (translation == null) {
48              throw new IllegalArgumentException(
49                  String.format(
50                      new StringBuilder()
51                          .append("Language %s is not supported, you can create ")
52                          .append("an issue on Github and we'll fix it")
53                          .toString(),
54                      language
55                  )
56              );
57          }
58          return translation;
59      }
60  }