I'm currently working on a project for university. Basically, the task is to implement a basic library management tool (in Java, using the Spring Framework and the Java Persistence API). Part of the software requirement is to be able to add and modify book entries and store them in a database. A book has multiple properties (title, publication date, ...) and also a specific language. Now, my question is: How do I (neatly) implement that whole concept of "language"? I came up with some ideas, each with its own benefits and trade-offs:
Idea 1:
- User Input: plain text field
- Database: store language as a string (as an attribute of the
bookrelation) - Pros: very simple to implement
- Cons: languages might not be uniform ("english", "en", "English", "ENGLISH", ...), lots of room for human error (typos, ...)
Idea 2:
- User Input: drop-down / combo box
- Database: predefined language relation, containing all possible languages (e.g.
language_idas a foreign key in thebookrelation) - Pros: languages are uniform (e.g. "English", "German", "Italian", ...), little room for human error
- Cons: what is the set of all possible languages? Should/Can some languages be omitted? Is this overkill? Is there too much overhead? What format of languages should be used (human-readable: "English", "english", or more compact: "en", "en-us", ...) ?
Idea 3:
- User Input: drop-down / combo box
- Source Code: as in idea 2, but now hardcode all possible languages as enumerations in source code
- Database: convert the specific enumeration to either a string/ordinal and use it as an attribute in the
bookrelation - Pros: pros of Idea 2 + no hardcoding of language strings in source code (from
if language = "english"toif language = Language.ENGLISH) - Cons: cons of Idea 2 + how are the enumerations mapped into the database (string, ordinal , separate relation)? The enumerations and the languages in the database must be "in sync".
To me, Idea 2 might be the "most-reasonable", but I'm still not sure, whether this is actually a "good" approach. Maybe you can help me out.