Languages.java 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. package ui.view;
  2. import java.io.BufferedReader;
  3. import java.io.FileReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.nio.charset.Charset;
  7. import utility.Util;
  8. public class Languages {
  9. static int languageVar = 0;
  10. // Language Array Positions:
  11. // ToolBar (0-16)
  12. // Tables (17-24)
  13. // Graph (25-26)
  14. // Warning PopUps (27-30)
  15. // Edit Edges Pop Up (31-34)
  16. // Search/Replace Pop Up (35-45)
  17. // Edit Edges Pop Up (46-55)
  18. // Add PopUp Tree (56-63)
  19. // Add PopUp Element (64-71)
  20. // Info for PropertyTable (72-82)
  21. // Info SimulationMenu (83-87)
  22. // Exit Pop Up (88)
  23. // Simulation ToolTip (89-93)
  24. // Image Size Slider (94)
  25. // Menu - right click on HolonObjt (95-104)
  26. public static final int right_click_create_template = 104;
  27. // to add more: increase languageSize and add them to the arrayEN
  28. /**
  29. * Number of different Language Array Positions
  30. */
  31. private static int languageSize = 105;
  32. static String[] arrayEN = {
  33. // ToolBar (0-16)
  34. "File", "New", "Open", "Save", "Edit", "Undo", "Redo", "Find/Replace", "Edit showed Information", "Options",
  35. "Reset Categories", "View", "View Size", "Help", "About Us", "Edit Edges", "Language",
  36. // Tables (17-24)
  37. "Object", "Nr.", "Device", "Energy", "Quantity", "Activated", "Field", "Information",
  38. // Graph (25-26)
  39. "None ", "Reset",
  40. // Warning PopUps (27-30)
  41. "Warning", "Do you want to save your current data?", "Do you really want to delete the Category ",
  42. "Please select a Category or an Object in order to delete something.",
  43. // Edit Edges Pop Up (31-34)
  44. "Edit Showed Informations", "Show Total Energy of Objects", "Show Connection Properties", "Cancel",
  45. // Search/Replace Pop Up (35-45)
  46. "Search for Objects", "Find", "Replace", "Direction", "Forward", "Backward", "Scope", "All", "Single",
  47. "Replace All", "Close",
  48. // Edit Edges Pop Up (46-55)
  49. "Edit Capacities of Edges", "Maximum Capacity:", "Change for all existing Edges only",
  50. "Change for new created Edges only", "Change for all existing and new created Edges", "Cancel",
  51. "Please select one of the options",
  52. "Please enter a number greater or equal 0 in the Field for Maximum Capacity", "Edit Edge Capacities",
  53. "(enter \"infinite\" for infinite Capacity)",
  54. // Add PopUp Tree (56-63)
  55. "Please enter a Name for Category ", "Please select a Category first before adding ", "Add Object Menu",
  56. "Name:", "Browse Image", "Add Element", "Delete Element", "Cancel",
  57. // Add PopUp Element (64-71)
  58. "Add Element to Object", "Element Name:", "Provided Energy:", "Amount:",
  59. "Please enter numbers in the Fields amount and Energy", "No name", "Name already given", "Cancel",
  60. // Info for PropertyTable (72-82)
  61. "Name", "Total Energy", "Manual", "Active", " is connected to", " with ID: ", "Edge: ", " to ",
  62. "Current flow", "Max. Capacity", "Status",
  63. // Info SimulationMenu (83-87)
  64. "Simulate", "Simulation Speed:", "Algorithm:", "non selected", "success",
  65. // Exit Pop Up (88)
  66. "Are you sure you want to exit?",
  67. // Simulation ToolTip (89-93)
  68. "Play", "Reset", "Forward", "Backward", "Time Slider",
  69. // Image Size Slider (94)
  70. "Image Size",
  71. // Menu - right click on HolonObjt (95-104)
  72. "Cut", "Copy", "Paste", "Delete", "Group", "Ungroup", "Track", "Untrack","Category","Create Template"};
  73. static String[] arrayES = readLanguageFile("Texts/ES.lang");
  74. static String[] arrayDE = readLanguageFile("Texts/DE.lang");
  75. static String[] arrayCZ = readLanguageFile("Texts/CZ.lang");
  76. static String[] arrayZH = readLanguageFile("Texts/ZH.lang");
  77. public static String[] getLanguage() {
  78. switch (languageVar) {
  79. case 0:
  80. return arrayEN;
  81. case 1:
  82. return arrayES;
  83. case 2:
  84. return arrayDE;
  85. case 3:
  86. return arrayCZ;
  87. case 4:
  88. return arrayZH;
  89. default:
  90. return arrayEN;
  91. }
  92. }
  93. public static void setLanguage(int i) {
  94. languageVar = i;
  95. }
  96. /**
  97. * Reads language file from jar, each line corresponds to
  98. * a position of the {@value #arrayEN}.
  99. * Lines starting with # are ignored as Comments.
  100. * Missing translations will be filled with english text.
  101. * @param path path of the file e.g. "Texts/DE.lang"
  102. * @return Array of translated String as arrayEN
  103. */
  104. private static String[] readLanguageFile(String path){
  105. String[] langArr;
  106. try {
  107. //read File from Jar
  108. InputStreamReader reader = new InputStreamReader(Util.loadStream(/*Languages.class.getClassLoader(),*/path));
  109. BufferedReader br = new BufferedReader(reader);
  110. //store Lines in Array
  111. int lineNumber = 0;
  112. langArr = new String[languageSize];
  113. for (String line = br.readLine(); line != null && lineNumber<languageSize; line = br.readLine()) {
  114. //store line in Array, # initializes Comments
  115. if (line.isEmpty() || line.startsWith("#"))
  116. continue;
  117. langArr[lineNumber]=new String(line.getBytes(Charset.defaultCharset()),"UTF-8");
  118. lineNumber++;
  119. }
  120. //missing translations? -> english
  121. while(lineNumber<languageSize){
  122. langArr[lineNumber]=arrayEN[lineNumber];
  123. lineNumber++;
  124. }
  125. reader.close();
  126. return langArr;
  127. } catch (Exception e) {
  128. System.err.print("Loading Languagepack: "+path+" failed.");
  129. //default: English
  130. return arrayEN;
  131. }
  132. }
  133. }