0

Is there any best practice to store a multilanguage string using the Spring / Spring boot framework? For instance, I am designing an Account class.

    public class Account {

        private String nameEn;
        private String nameDe;
        
        // getters and setters are omitted

    }

Is there an already designed class to store such kind of fields in one field on the Entity level? Or is it better to design my own class with @Embedded annotation like below?

    class MultilingualString {

        private String stringEn;
        private String stringDe;

        public String getString(String locale){
            // get string by locale like "en", "ru"
        }
    
        public String getString(Locale locale){
            // get string by locale
        }
    
    }
  • Not seeing any code, really. – GetSet Nov 04 '20 at 01:16
  • Please define i18n messages_xxx.properties in resource. Then inject MessageSource to get message info in class. Here is [guide](https://lokalise.com/blog/spring-boot-internationalization/) – jacky-neo Nov 04 '20 at 01:49
  • Well, there is `Map`, where the key is the locale, e.g. `en`, `en-US`, `de-DE`, ... --- For JPA, you'd define it as shown in this answer: [JPA Map mapping](https://stackoverflow.com/a/15061468/5221149) – Andreas Nov 04 '20 at 03:01

0 Answers0