简体   繁体   中英

Optimizing jar file size (images) when developing java client supporting multiple languages

I am developing the Java client which should support several languages. For translation of the text I use Java ResourceBoundle and it works okay.

Now the problem is with images. The client should load around 50 images which are specific cards for a board game. Each image has a title. So if I have N languages I should prepare 50*N images and put then into the jar file.

Each language support would add around 1 Mb to the size of jar file.

Do you think I should

  1. Generate jar which support all the languages?
  2. Generate many jars which would support English and a local language?
  3. Have one set of image without titles and attach title to the image using Java JLabel?

I advise another option altogether.

Have a set of images without text, and use AWT's Graphics2D to add the text in the necessary language (as opposed to doing so with a JLabel).

Graphics2D g = imageBase.createGraphics();
// color, font, etc settings
g.drawString("title", 0, 0);
g.dispose();

You can modify the parameters of g.drawString as necessary to draw the correct title at the correct coordinates. If you wish to center the title, you can find a nice tutorial here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM