marlonlom/timeago

MissingResourceExcetpion - Cant find bundle

Closed this issue · 6 comments

Getting intermittent issues where the following exception is thrown:

java.util.MissingResourceException: Can't find bundle for base name com.github.marlonlom.utilities.timeago.messages, locale en_US

Currently using v4.0.3

Hi @IndianaSloan
Are you using the locale 'en_US' for retrieving the messages? the languages are country-aware ...

@marlonlom yes, I was previously not defining the Locale as it appears to use device default Locale. However I was getting the same exception thrown except for locale eb_GB - again intermittent and not every time.

I switched to passing in an instance of TimeAgoMessages into the using() function and setting the Locale to Locale.US and getting the above reported exception

Hi @IndianaSloan,

Have you tried using the two-digit language code?
I've shared an example using the language code for getting the messages ...

var localeBylanguageTag = Locale.forLanguageTag("en")
var messages = TimeAgoMessages.Builder().withLocale(localeBylanguageTag).build()

As i said before, the languages are country-aware, for example, in this case, you must get the generic locale for english using the Locale.forLanguageTag() method/function.

I was capable to reproduce this using the https://www.jdoodle.com/online-java-compiler/ website and writing this code.

import java.util.Locale;
import com.github.marlonlom.utilities.timeago.TimeAgo;
import com.github.marlonlom.utilities.timeago.TimeAgoMessages;


public class MyClass {
    public static void main(String args[]) {
        long timeInMillis = System.currentTimeMillis();
        /* Example 01: using Locale.forLanguageTag("en") ... */
        Locale aLocale = Locale.forLanguageTag("en");
        TimeAgoMessages messages = new TimeAgoMessages.Builder().withLocale(aLocale).build();
        String text = TimeAgo.using(timeInMillis, messages);
        System.out.println("text(1) = " + text);
        /* Example 02: Using Locale.US*/
        aLocale = Locale.US;
        messages = new TimeAgoMessages.Builder().withLocale(aLocale).build();
        text = TimeAgo.using(timeInMillis, messages);
        System.out.println("text(2) = " + text);
    }
}

in the online tool, i did add the following dependencies:

com.github.marlonlom:timeago:4.0.3
org.jetbrains.kotlin:kotlin-stdlib:1.4.30

and with that, it prints the following:

text(1) = just now
text(2) = just now

@IndianaSloan
shouldn't be experiencing the crash when I use the default messages?
...
Not really,for that reason i tried the example with code before.

Since i did not get some feedback about the reported issue, im closing this one.