Created
February 20, 2020 00:13
-
-
Save YanisBft/717150c7338cc7a5d8837c28d4ab888c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static ArrayList<String> getAvailableLanguages() { | |
ArrayList<String> list = new ArrayList<String>(); | |
File dir; | |
try { | |
dir = new File(Paths.get(I18n.class.getProtectionDomain().getCodeSource().getLocation().toURI()).resolve("lang").toString()); | |
try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir.toPath(), "*.json")) { | |
for (Path file : stream) { | |
String fileName = file.getFileName().toString().substring(0, file.getFileName().toString().length() - 5); | |
list.add(fileName); | |
try (InputStream inputStream = Files.newInputStream(new File(Paths.get(I18n.class.getProtectionDomain().getCodeSource().getLocation().toURI()).resolve("lang/" + file.getFileName()).toString()).toPath())) { | |
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) { | |
Map<?, ?> map = GSON.fromJson(reader, Map.class); | |
languageNames.put(fileName, map.get("language").toString()); | |
} | |
} | |
} | |
} | |
} catch (IOException | URISyntaxException e) { | |
e.printStackTrace(); | |
} | |
return list; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment