File tree Expand file tree Collapse file tree
src/com/maxprograms/javapm Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -25,15 +25,22 @@ private Messages() {
2525 }
2626
2727 public static String getString (String key ) {
28+ String resourceName = "javapm" ;
2829 try {
2930 if (props == null ) {
3031 Locale locale = Locale .getDefault ();
31- String extension = "en" .equals (locale .getLanguage ()) ? ".properties"
32- : "_" + locale .getLanguage () + ".properties" ;
33- if (Messages .class .getResource ("javapm" + extension ) == null ) {
32+ String language = locale .getLanguage ();
33+ String extension = "_" + language + ".properties" ;
34+ // check if there is a resource for full language code
35+ if (Messages .class .getResource (resourceName + extension ) == null ) {
36+ // if not, check if there is a resource for language only
37+ extension = "_" + language .substring (0 , 2 ) + ".properties" ;
38+ }
39+ if (Messages .class .getResource (resourceName + extension ) == null ) {
40+ // if not, use the default resource
3441 extension = ".properties" ;
3542 }
36- try (InputStream is = Messages .class .getResourceAsStream ("javapm" + extension )) {
43+ try (InputStream is = Messages .class .getResourceAsStream (resourceName + extension )) {
3744 try (InputStreamReader reader = new InputStreamReader (is , StandardCharsets .UTF_8 )) {
3845 props = new Properties ();
3946 props .load (reader );
You can’t perform that action at this time.
0 commit comments