3

In Android, final strings are stored in a strings.xml file, which makes it easy to update text, reuse strings and to translate an app to a different locale -- because everything is in one place.

However, in all the examples that I have seen of desktop applications all the strings have been hardcoded into each class.

Is hardcoding strings into files standard practice for desktop applications? Or is there a better way to do this?

asked Jan 2, 2014 at 21:52
3
  • What types of strings? names of things to use in reflection? keys to hashes? values displayed as part of a view? Commented Jan 2, 2014 at 21:57
  • @Michael - mostly values displayed as parts of views Commented Jan 2, 2014 at 22:00
  • 1
    They're likely ignoring i18n... and should be using ResourceBundle.getBundle(base,locale) Commented Jan 2, 2014 at 22:11

1 Answer 1

3

What you're referring to is called internationalization (often abbreviated as i18n), which in desktop Java is accomplished by creating properties files for each locale, then using resource bundles to get strings from those files as needed (see this tutorial). It's not universally used, because there is some setup involved, and it's shorter to type "greetings" compared to messages.getString("greetings"). Usually you only see it when people actually need to have their program translated into different languages.

You can hard code strings in Android too, if you want, but they emphasized using the xml from the start in all their documentation and tutorials, and set up the tools to make it easier.

answered Jan 2, 2014 at 22:16
1
  • I'll look into this - It certainly looks better to me than putting all the strings directly into the code. Commented Jan 2, 2014 at 22:29

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.