Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.File;
  3. import java.io.FileReader;
  4. import java.io.IOException;
  5. import java.nio.charset.Charset;
  6. import java.nio.file.Files;
  7. import java.util.ArrayList;
  8.  
  9. public class Main {
  10.  
  11. public static void main(String[] args) {
  12. File engList = new File("/Users/alexbandtock/workspace/axa-webapp/src/main/resources/messages.properties");
  13. File notEngList = new File("/Users/alexbandtock/workspace/axa-webapp/src/main/resources/messages_fr.properties");
  14. try {
  15. messageBundleMissing(engList, notEngList);
  16. } catch (IOException e) {
  17. e.printStackTrace();
  18. }
  19. }
  20.  
  21. private static void messageBundleMissing(File eng, File notEng) throws IOException {
  22. ArrayList<String> notEngLines = new ArrayList<>();
  23. ArrayList<String> engKeys = new ArrayList<>();
  24. ArrayList<String> notEngKeys = new ArrayList<>();
  25. try (BufferedReader br = new BufferedReader(new FileReader(eng))) {
  26. String line;
  27. while ((line = br.readLine()) != null) {
  28. engKeys.add(line.trim().replace("#", "").split("=")[0]);
  29. }
  30. }
  31. try (BufferedReader br = new BufferedReader(new FileReader(notEng))) {
  32. String line;
  33. while ((line = br.readLine()) != null) {
  34. notEngKeys.add(line.trim().replace("#", "").split("=")[0]);
  35. notEngLines.add(line);
  36. }
  37. }
  38. engKeys.forEach(key -> {
  39. if (!notEngKeys.contains(key)) {
  40. String after = engKeys.get(engKeys.indexOf(key) - 1);
  41. int newIndex = notEngLines.indexOf(after);
  42. if (newIndex == -1) {
  43. notEngLines.add("#" + key + "=");
  44. } else {
  45. notEngLines.add(newIndex, "#" + key + "=");
  46. }
  47. }
  48. });
  49.  
  50. Files.write(eng.toPath(),notEngLines, Charset.defaultCharset());
  51. }
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement