Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileReader;
- import java.io.IOException;
- import java.nio.charset.Charset;
- import java.nio.file.Files;
- import java.util.ArrayList;
- public class Main {
- public static void main(String[] args) {
- File engList = new File("/Users/alexbandtock/workspace/axa-webapp/src/main/resources/messages.properties");
- File notEngList = new File("/Users/alexbandtock/workspace/axa-webapp/src/main/resources/messages_fr.properties");
- try {
- messageBundleMissing(engList, notEngList);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- private static void messageBundleMissing(File eng, File notEng) throws IOException {
- ArrayList<String> notEngLines = new ArrayList<>();
- ArrayList<String> engKeys = new ArrayList<>();
- ArrayList<String> notEngKeys = new ArrayList<>();
- try (BufferedReader br = new BufferedReader(new FileReader(eng))) {
- String line;
- while ((line = br.readLine()) != null) {
- engKeys.add(line.trim().replace("#", "").split("=")[0]);
- }
- }
- try (BufferedReader br = new BufferedReader(new FileReader(notEng))) {
- String line;
- while ((line = br.readLine()) != null) {
- notEngKeys.add(line.trim().replace("#", "").split("=")[0]);
- notEngLines.add(line);
- }
- }
- engKeys.forEach(key -> {
- if (!notEngKeys.contains(key)) {
- String after = engKeys.get(engKeys.indexOf(key) - 1);
- int newIndex = notEngLines.indexOf(after);
- if (newIndex == -1) {
- notEngLines.add("#" + key + "=");
- } else {
- notEngLines.add(newIndex, "#" + key + "=");
- }
- }
- });
- Files.write(eng.toPath(),notEngLines, Charset.defaultCharset());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement