Closed kevinrobayna closed 9 years ago
Hi, sorry for taking this long.
There is a problem related to initialization order. The line
private static final Message msg = C10N.get(Message.class);
gets executed before the code in main(...)
, and therefore creates a Message
class that does not contain any configuration.
For c10n to work, you need to call C10N.configure(...)
prior to any calls to C10N.get(...)
method. Thus the code below will work (unless you have the other problem below):
public class MainTest {
public static void main (String [] args) {
C10N.configure(new DefaultC10NAnnotations());
Message msg = C10N.get(Message.class);
System.out.println(msg.grettins());
}
}
In relation to you second question, the other possible problem is that may arise is your default Locale
setting (you can check it out with Locale.getDefault()
). If your default locale does not match any of the locales registered in DefaultC10NAnnotations
, it will not work.
In that case you will either need to add the relevant locale setting, or setup fallback. See examples below on how to do that:
C10N.configure(new C10NConfigBase() {
@Override
protected void configure() {
//install default annotations (optional)
install(new DefaultC10NAnnotations());
//install custom @Es annotation bound to "es_ES" locale
bindAnnotation(Es.class).toLocale(new Locale("es"));
// ... or just setup c10n to fallback to @En annotation when locale does
// not match any other registered annotation, by binding it without specifying
// the locale
bindAnnotation(En.class);
}
});
Of course, you can do the set-up you have mentioned at the end of your post. However, it may cause difficulties when you update your application to use @En
annotation for English, instead of Spanish.
Oh thank you. I'm going to try it.
Related to #18
Hi there, i just saw your library and i had to try it because i think is a great idea use interface as elements to translate.
Trying a example code like:
This is my output
But it should be Hi or Привет. You know which could be my problem?
In addition i would like to add spanish annotation language to c10n i just have to modify core/src/main/java/com/github/rodionmoiseev/c10n/annotations/ adding a class named es.java and DefaultC10NAnnotations adding