Details
-
Type: Improvement
-
Status: Open
-
Priority: Minor
-
Resolution: Unresolved
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: Core
-
Labels:None
-
Environment:Multi language
-
Number of attachments :
Description
Currently there is no easy and safe way to configure another locale for the keywords in my mind.
I know that it is described here: http://jbehave.org/reference/stable/stories-in-your-language.html
But it has to be configured in several places, which might work today but not in a future version of JBehave.
Furthermore "new ParameterConverters.ExamplesTableConverter(keywords))" does not work since there is no such constructor.
So I had the idea to set this private final field by reflection to my desired German locale: org.jbehave.core.i18n.LocalizedKeywords.DEFAULT_LOCALE
See the code below for how I solved it. It works basically. But it is not nice to solve it this way, although I applied single source principle.
So I suggest that JBehave provides an dedicated API to set the default locale without JBehave users have to use reflection in order to achieve this single source language configuration.
A quick solution would be to make the "LocalizedKeywords.DEFAULT_LOCALE" public and not final. But that would not be so nice, I know.
You know your JBehave framework better than me. I hope you have an idea how to provide that API in a well designed way.
Maybe instead of "useKeywords(...)" it could be done with "useLocale(...)", just an idea.
That locale would affect keyword language and all other language dependent parts of JBehave.
Having such an API for configuring locale can be even helpful for JBEHAVE-874 issue I think, since it would be easier to realize and more safe and maintainable for future versions of JBehave.
private void setGermanLocale() { try { Field localeField = LocalizedKeywords.class.getDeclaredField("DEFAULT_LOCALE"); setFinalStatic(localeField, Locale.GERMAN); } catch (NoSuchFieldException | SecurityException e) { e.printStackTrace(); } } private void setFinalStatic(Field field, Object newValue) { field.setAccessible(true); try { Field modifiersField = Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); field.set(null, newValue); } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { throw new RuntimeException(e); } }