Beispiel #1
0
  private static ResourceBundle getDefaultResourceBundle(File resourceDirectory, String fileName) {
    if (Translator.defaultBundle != null) return Translator.defaultBundle;
    resourceDirectory.mkdirs();

    File bundleFile = new File(resourceDirectory, fileName);
    if (!bundleFile.exists()) {
      try {
        bundleFile.createNewFile();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
    Translator.populateDefaults(bundleFile);
    FileInputStream stream = null;
    try {
      stream = new FileInputStream(bundleFile);
      Translator.defaultBundle = new PropertyResourceBundle(stream);
    } catch (Exception e) {
      e.printStackTrace();
      Translator.defaultBundle = Translator.getFallbackResourceBundle();
    } finally {
      Closeables.closeQuietly(stream);
    }
    return Translator.defaultBundle;
  }
Beispiel #2
0
 public static String translate(String key, Locale preferredLocale, Object... msg) {
   if (instance == null) createInstance();
   return StringHelper.parseColors(
       msg.length == 0
           ? instance.translate(key, preferredLocale)
           : instance.format(key, preferredLocale, msg));
 }
Beispiel #3
0
 private void setupTranslator() {
   Locale locale = Locale.getDefault();
   String setting = Setting.LOCALE.asString();
   if (!setting.isEmpty()) {
     String[] parts = setting.split("[\\._]");
     switch (parts.length) {
       case 1:
         locale = new Locale(parts[0]);
         break;
       case 2:
         locale = new Locale(parts[0], parts[1]);
         break;
       case 3:
         locale = new Locale(parts[0], parts[1], parts[2]);
         break;
       default:
         break;
     }
   }
   Translator.setInstance(new File(getDataFolder(), "lang"), locale);
   Messaging.logTr(Messages.LOCALE_NOTIFICATION, locale);
 }