Jump to content

Recommended Posts

Posted

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!

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.