SteamWar/BungeeCore
Archiviert
13
2
Dieses Repository wurde am 2024-08-05 archiviert. Du kannst Dateien ansehen und es klonen, aber nicht pushen oder Issues/Pull-Requests öffnen.
BungeeCore/src/de/steamwar/messages/SteamwarResourceBundle.java
Lixfel 0bf5a65850
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
Current state
Signed-off-by: Lixfel <agga-games@gmx.de>
2022-04-14 20:44:09 +02:00

56 Zeilen
2.0 KiB
Java

/*
This file is a part of the SteamWar software.
Copyright (C) 2022 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.messages;
import de.steamwar.bungeecore.Message;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
public class SteamwarResourceBundle extends PropertyResourceBundle {
private static final String BASE_PATH = "/" + "de.steamwar.messages.BungeeCore".replace('.', '/');
private static final Map<String, ResourceBundle> bundles = new HashMap<>();
public static ResourceBundle getResourceBundle(Locale locale) {
return getResourceBundle(locale.toString(), getResourceBundle(locale.getLanguage(), getResourceBundle( "", null)));
}
private static ResourceBundle getResourceBundle(String locale, ResourceBundle parent) {
return bundles.computeIfAbsent(locale, locale1 -> {
InputStream inputStream = Message.class.getResourceAsStream(BASE_PATH + ("".equals(locale) ? "" : "_" + locale) + ".properties");
if(inputStream == null)
return parent;
try {
return new SteamwarResourceBundle(inputStream, parent);
} catch (IOException e) {
return parent;
}
});
}
private SteamwarResourceBundle(InputStream stream, ResourceBundle parent) throws IOException {
super(stream);
setParent(parent);
}
}