Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separating logic from the controller as requested by @csokol
- Loading branch information
1 parent
f536953
commit 24612d6
Showing
2 changed files
with
46 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.mamute.infra.locale; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Properties; | ||
import java.util.Set; | ||
|
||
public class MessagesLoader { | ||
|
||
public Map<String, String> loadBy(String locale) { | ||
Properties props = new Properties(); | ||
Map<String, String> messages = new HashMap<String, String>(); | ||
try { | ||
props.load(this.getClass().getResourceAsStream("/messages.properties")); | ||
Set<Object> keySet = props.keySet(); | ||
for (Object key : keySet) { | ||
String value = (String) props.get(key); | ||
messages.put((String) key, value); | ||
} | ||
|
||
if (!locale.equals("en")) { | ||
props.load(this.getClass().getResourceAsStream("/messages_"+locale+".properties")); | ||
keySet = props.keySet(); | ||
for (Object key : keySet) { | ||
String value = (String) props.get(key); | ||
messages.put((String) key, value); | ||
} | ||
} | ||
|
||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
return messages; | ||
} | ||
|
||
} |