Note that there are some explanatory texts on larger screens.

plurals
  1. POResourceBundle reads from 2 Properties files at the same time
    text
    copied!<p>in my project I have 2 <code>properties files</code> that are used for internationalization. I use <code>ResourceBundle</code> with <code>Locale</code> parameter and I store the keys from properties files in a collection. Unfortunately in the collection are stored combined keys from both files. I just want keys from a single file depending on the locale. In my case the Locale is "bg_BG". The properties files are: </p> <pre><code>time_intervals.properties </code></pre> <p><img src="https://i.stack.imgur.com/jiAOy.png" alt="enter image description here"></p> <pre><code>time_intervals_bg.properties </code></pre> <p><img src="https://i.stack.imgur.com/U5Qr3.png" alt="enter image description here"></p> <p>And this is how I am reading them:</p> <pre><code>public List&lt;SelectItem&gt; getTimeSpentList() { timeSpentList = new ArrayList&lt;SelectItem&gt;(); FacesContext context = FacesContext.getCurrentInstance(); ResourceBundle bundle = ResourceBundle.getBundle("properties.time_intervals", context.getViewRoot().getLocale()); Enumeration&lt;String&gt; time_interval_keys = bundle.getKeys(); List&lt;String&gt; sortedKeys = new ArrayList&lt;String&gt;(); while(time_interval_keys.hasMoreElements()) { String key = time_interval_keys.nextElement(); sortedKeys.add(key); } Collections.sort(sortedKeys, new Comparator&lt;String&gt;() { @Override public int compare(String o1, String o2) { if (o1.charAt(1) != ' ') { return -1; } else if (o2.charAt(1) != ' ') { return 1; } return o1.compareTo(o2); } }); for (String key : sortedKeys) { timeSpentList.add(new SelectItem(key)); } if (timeSpentList == null || timeSpentList.isEmpty()) { timeSpentList.add(new SelectItem("")); return timeSpentList; } return timeSpentList; } </code></pre> <p>The problem here is that in <code>Enumeration&lt;String&gt; time_interval_keys</code> I get combined keys from both properties files after calling the <code>bundle.getKeys()</code> but I want ONLY values from one of them. Please help.</p> <p>P.S. Please let me know if anything is not clear about my explanations and about the code. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload