isis-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dan Haywood <...@haywood-associates.co.uk>
Subject Re: Translating enum values?
Date Tue, 29 Sep 2015 19:11:51 GMT
good stuff, glad you got it sorted.

cheers
Dan

On 29 September 2015 at 19:22, Burbach, Matthias <Matthias.Burbach@tui.de>
wrote:

> Thank you so much, I missed this indeed. Additionally, by debugging more
> deeply I found the correct way of specifying the translation keys for
> public class Item {
>         public enum ItemGroup { KeyUser };
> }
>
> which is:
>
> #: domainapp.dom.simple.Item$ItemGroup#KeyUser
> msgid "Keyuser"
> msgstr "Key User"
>
>
>
> Am 29.09.15 17:52 schrieb "Dan Haywood" unter
> <dan@haywood-associates.co.uk>:
>
> >One thing to do, in case you missed it, is to ensure that the translation
> >service mode so it is in read mode.  Otherwise you'll just see the
> >original
> >keys as the untranslated values.
> >
> >from the manual [1]:
> >
> >If the service is running in the normal read mode, then it simply provides
> >translations for the locale of the current user. This means locates the
> >appropriate .po file (based on the requesting userĀ¹s locale), finds the
> >translation and returns it.
> >
> >If however the service is configured to run in write mode, then it instead
> >records the fact that the message was requested to be translated (a little
> >like a spy/mock in unit testing mock), and returns the original message.
> >The service can then be queried to discover which messages need to be
> >translated. All requested translations are written into the .pot file.
> >
> >To make the service as convenient as possible to use, the service
> >configures itself as follows:
> >if running in prototype mode deployment type
> ><http://isis.apache.org/guides/rg.html#_rg_runtime_deployment-types> or
> >during integration tests, then the service runs in *write* mode, in which
> >case it records all translations into the .pot file. The .pot file is
> >written out when the system is shutdown.
> >if running in server (production) mode deployment type
> ><http://isis.apache.org/guides/rg.html#_rg_runtime_deployment-types>,
> then
> >the service runs in *read* mode. It is also possible to set a
> >configuration
> >setting in isis.properties to force read mode even if running in prototype
> >mode (useful to manually test/demo the translations).
> >
> >When running in write mode the original text is returned to the caller
> >untranslated. If in read mode, then the translated .po files are read and
> >translations provided as required.
> >
> >To switch between modes, use the -t flag to WebServer [2] or specify in
> >web.xml
> >
> >HTH
> >Dan
> >
> >[1]
> http://isis.apache.org/guides/ug.html#__code_translationservicepo_code
> >[2] http://isis.apache.org/guides/ug.html#_ug_deployment_cmd-line
> >[3] http://isis.apache.org/guides/rg.html#_using_the_wicket_viewer
> >
> >
> >
> >On 29 September 2015 at 16:43, Burbach, Matthias <Matthias.Burbach@tui.de
> >
> >wrote:
> >
> >> Line 144 does get hit indeed by the following call stack and
> >> translationContext is domainapp.dom.simple.Item$ItemGroup#KeyUser for
> >> example, and friendlyNameOfEnum is Keyuser for example.
> >> But on the UI it has no effect, KeyUser is still presented as Keyuser,
> >> although I put these lines into
> >> file translations-en.po:
> >> #: domainapp.dom.simple.Item$ItemGroup#KeyUser
> >> msgid "Key User"
> >> msgstr "Key User"
> >>
> >>
> >> I cannot easily track down whether the value is looked up but not used
> >> then or if the lookup already fails because my Maven was not successfull
> >> in downloading all the sources needed for debugging.
> >> Will need to download the missing jars later when there is more time for
> >> it.
> >>
> >>
> >>EnumValueSemanticsProvider<T>(ValueSemanticsProviderAndFacetAbstract<T>).
> >>di
> >> splayTitleOf(Object, Localization) line: 217
> >> TitleFacetUsingParser.title(ObjectAdapter, Localization) line: 57
> >> TitleFacetUsingParser.title(ObjectAdapter, ObjectAdapter, Localization)
> >> line: 62
> >>
> >>ObjectSpecificationDefault(ObjectSpecificationAbstract).getTitle(ObjectAd
> >>ap
> >> ter, ObjectAdapter, Localization) line: 405
> >>
> >>ObjectSpecificationDefault(ObjectSpecificationAbstract).getTitle(ObjectAd
> >>ap
> >> ter, Localization) line: 399
> >> DomainObjectContainerDefault.titleOf(Object) line: 91
> >> IsisSystem.translateServicesAndEnumConstants() line: 266
> >> IsisSystem.init() line: 144
> >> IsisInjectModule.provideIsisSystem(DeploymentType, IsisSystemFactory,
> >> AppManifest) line: 139
> >> NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not
> >> available [native method]
> >> NativeMethodAccessorImpl.invoke(Object, Object[]) line: 62
> >> DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 43
> >> Method.invoke(Object, Object...) line: 497
> >> ProviderMethod<T>.get() line: 104
> >> InternalFactoryToProviderAdapter<T>.get(Errors, InternalContext,
> >> Dependency<?>, boolean) line: 40
> >> ProviderToInternalFactoryAdapter$1.call(InternalContext) line: 46
> >> InjectorImpl.callInContext(ContextualCallable<T>) line: 1031
> >> ProviderToInternalFactoryAdapter<T>.get() line: 40
> >> Scopes$1$1.get() line: 65
> >> InternalFactoryToProviderAdapter<T>.get(Errors, InternalContext,
> >> Dependency<?>, boolean) line: 40
> >> SingleFieldInjector.inject(Errors, InternalContext, Object) line: 53
> >> MembersInjectorImpl<T>.injectMembers(T, Errors, InternalContext,
> >>boolean)
> >> line: 110
> >> MembersInjectorImpl$1.call(InternalContext) line: 75
> >> MembersInjectorImpl$1.call(InternalContext) line: 73
> >> InjectorImpl.callInContext(ContextualCallable<T>) line: 1024
> >> MembersInjectorImpl<T>.injectAndNotify(T, Errors, boolean) line: 73
> >> MembersInjectorImpl<T>.injectMembers(T) line: 60
> >> InjectorImpl.injectMembers(Object) line: 944
> >> DomainApplication(IsisWicketApplication).init() line: 256
> >> DomainApplication.init() line: 64
> >> DomainApplication(Application).initApplication() line: 823
> >> WicketFilter.init(boolean, FilterConfig) line: 424
> >> WicketFilter.init(FilterConfig) line: 351
> >> FilterHolder.initialize() line: 138
> >> ServletHandler.initialize() line: 852
> >> WebAppContext(ServletContextHandler).startContext() line: 298
> >> WebAppContext.startWebapp() line: 1349
> >> WebAppContext.startContext() line: 1342
> >> WebAppContext(ContextHandler).doStart() line: 741
> >> WebAppContext.doStart() line: 505
> >> WebAppContext(AbstractLifeCycle).start() line: 68
> >> Server(ContainerLifeCycle).start(LifeCycle) line: 132
> >> Server.start(LifeCycle) line: 387
> >> Server(ContainerLifeCycle).doStart() line: 114
> >> Server(AbstractHandler).doStart() line: 61
> >> Server.doStart() line: 354
> >> Server(AbstractLifeCycle).start() line: 68
> >> WebServerBootstrapper.bootstrap(Injector) line: 91
> >> WebServer.run(String[]) line: 107
> >> WebServer.main(String[]) line: 71
> >> WebServer.main(String[]) line: 25
> >>
> >>
> >>
> >>
> >> Am 29.09.15 16:40 schrieb "Dan Haywood" unter
> >> <dan@haywood-associates.co.uk>:
> >>
> >> >Good stuff, nice bit of investigation.  I wrote that stuff, but had
> >> >forgotten about it.
> >> >
> >> >So, if you put a breakpoint on line 144 [1], does it get hit?
> >> >
> >> >Also, it looks like if you define a title() method returning a
> >> >TranslatableString, then that will get called instead, with a slightly
> >> >different context being used for the lookup of the translation [2]
> >> >
> >> >Let me know what you find out...
> >> >
> >> >Dan
> >> >
> >> >[1]
> >> >
> >>
> >>
> https://github.com/apache/isis/blob/isis-1.9.0/core/metamodel/src/main/ja
> >>v
> >>
> >>>a/org/apache/isis/core/metamodel/facets/object/choices/enums/EnumValueSe
> >>>ma
> >> >nticsProvider.java#L144
> >> >[2]
> >> >
> >>
> >>
> https://github.com/apache/isis/blob/isis-1.9.0/core/metamodel/src/main/ja
> >>v
> >>
> >>>a/org/apache/isis/core/metamodel/facets/object/choices/enums/EnumValueSe
> >>>ma
> >> >nticsProvider.java#L126
> >> >
> >> >
> >> >
> >> >On 29 September 2015 at 15:34, Burbach, Matthias
> >><Matthias.Burbach@tui.de
> >> >
> >> >wrote:
> >> >
> >> >> I found this as a hint it may exist in 1.9.0 (the version which I am
> >> >> using): https://issues.apache.org/jira/browse/ISIS-1106
> >> >>
> >> >> EnumValueSemanticsProvider:
> >> >>
> >> >>      @Override
> >> >>      protected String titleString(final Object object, final
> >> >>Localization
> >> >> localization) {
> >> >> +        final TranslationService translationService =
> >> >> getDependencyInjector().lookupService(TranslationService.class);
> >> >> +
> >> >>          if (titleMethod != null) {
> >> >> -            final TranslationService translationService =
> >> >> getDependencyInjector().lookupService(TranslationService.class);
> >> >>              // sadness: same as in TranslationFactory
> >> >>              final String translationContext =
> >> >> titleMethod.getDeclaringClass().getName() + "#" +
> >>titleMethod.getName()
> >> >>+
> >> >> "()";
> >> >>
> >> >> @@ -135,7 +137,11 @@ public class EnumValueSemanticsProvider<T
> >>extends
> >> >> Enum<T>> extends ValueSemantic
> >> >>              }
> >> >>          }
> >> >>
> >> >> -        return object.toString();
> >> >> +        // simply translate the enum constant's name
> >> >> +        Enum<?> objectAsEnum = (Enum<?>) object;
> >> >> +        final String translationContext =
> >>object.getClass().getName() +
> >> >> "#" + objectAsEnum.name();
> >> >> +        final String friendlyNameOfEnum =
> >> >> Enums.getFriendlyNameOf(objectAsEnum.name());
> >> >> +        return translationService.translate(translationContext,
> >> >> friendlyNameOfEnum);
> >> >>      }
> >> >>
> >> >>
> >> >>
> >> >> Am 29.09.15 16:29 schrieb "Dan Haywood" unter
> >> >> <dan@haywood-associates.co.uk>:
> >> >>
> >> >> >Um, I'm not 100% certain this is implemented, actually.  Sorry
about
> >> >>that.
> >> >> >I'll double check this evening.
> >> >> >
> >> >> >If you want to raise a ticket anyway, that'll be fine.  If it turns
> >>out
> >> >> >there is a way then at the very least it would still need to be
> >> >> >documented...
> >> >> >
> >> >> >Thx
> >> >> >Dan
> >> >> >
> >> >> >
> >> >> >
> >> >> >On 29 September 2015 at 15:24, Burbach, Matthias
> >> >><Matthias.Burbach@tui.de
> >> >> >
> >> >> >wrote:
> >> >> >
> >> >> >> Hi,
> >> >> >> I am trying to translate enum values like so, but it has no
> >>effect.
> >> >> >>
> >> >> >> package domainapp.dom.simple;
> >> >> >> ...
> >> >> >> public class Item implements Comparable<Item> {
> >> >> >> ...
> >> >> >>
> >> >> >> //region > item group (property)
> >> >> >>         public enum ItemGroup {
> >> >> >>   KeyUser,
> >> >> >>   Provider,
> >> >> >>   Unit
> >> >> >>         }
> >> >> >>         private ItemGroup itemGroup;
> >> >> >>     @javax.jdo.annotations.Column(allowsNull = "false")
> >> >> >>     public ItemGroup getItemGroup() {return itemGroup;}
> >> >> >>     public void setItemGroup(final ItemGroup itemGroup)
> >> >>{this.itemGroup
> >> >> >>=
> >> >> >> itemGroup;}
> >> >> >>     //endregion
> >> >> >> ...
> >> >> >>
> >> >> >> }
> >> >> >>
> >> >> >> file translations-en.po:
> >> >> >> ...
> >> >> >> #: domainapp.dom.simple.Item$ItemGroup#KeyUser
> >> >> >> msgid "Key User"
> >> >> >> msgstr "Key User"
> >> >> >> ...
> >> >> >>
> >> >> >>
> >> >> >> I am not sure if this feature exists at all or if am just
using it
> >> >> >> wrongly, there some hints out there but not very clear to
me.
> >> >> >>
> >> >> >> Regards,
> >> >> >> Matthias
> >> >> >>
> >> >> >>
> >> >>
> >> >>
> >>
> >>
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message