Posted May 16, 201510 yr Hello, i have a question: How can i reade and localise data from lang files outside of jar? 1)I have a folder, where user creates lang files (named as usual (en_US for example)), and localizes some of names there using common pattern (a.name=A) 2) I think this is the best way for my case: User can create new types of items via json, and in order for name not to be m.d.name, i would like to make him able to localize names in this folder in these files... 3) I googled and searched on this forum with no results 4) I tryed to use this code, but it is not working: File lang = new File(configFolder, "lang"); lang.mkdirs(); for(File file : lang.listFiles(new FileFilter() { @Override public boolean accept(File file) { return !file.isDirectory() && file.getName().endsWith(".lang"); } })){ try{ String language = file.getName().split("/.")[0]; HashMap<String, String> map = new HashMap<String, String>(); BufferedReader br = new BufferedReader(new FileReader(file)) ; for(String line; (line = br.readLine()) != null; ) { try{ map.put(line.split("/=")[0], line.split("/=")[1]); } catch(IndexOutOfBoundsException e){ } } br.close(); LanguageRegistry.instance().injectLanguage(language, map); } catch(Exception e){ logger.error("Caught exception while parsing lang file: ", e); } } [code] 4.1) I know thatparsing is going well. (tested via console output). Thanks for help! If you have any questions - just ask! Check out my mods: BTAM Armor sets Avoid Exploding Creepers Tools compressor Anti Id Conflict Key bindings overhaul Colourfull blocks Invisi Zones
May 16, 201510 yr Author Ok, i solved it: only the problem was file.getName().split("/.")[0]; returning name with .lang in the end... Replacing it with file.getName().substring(0, 5); solved the problem... Check out my mods: BTAM Armor sets Avoid Exploding Creepers Tools compressor Anti Id Conflict Key bindings overhaul Colourfull blocks Invisi Zones
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.