GWT/SmartGWT adding new language at Runtime - java

I am using SmartGWT 3.0 and GWT 2.5. I know most of everything is pretty much compiled into corresponding javascripts by GWT. And this applies to i18n property files as well.
However i was looking for a way in which i can dynamically add a new language support by simply adding a new property file in the appropriate package.
I have tried that but it doesn't seem to work. Looking for any work around for this.
Thanks,
Vicky

I also need something like this, because i dont want to recompile my application for message changes all the time, also i dont want to increase compile permutation.
I am thinking following solution will be close enought to replace Message interface
Implement a servlet which will return Map of values from server according to locale langauge
Implement the message interface which will return values by calling the servlet with the locale language, and return values from the internal map.
Use ETag caching for the servlet response in order to cache the message texts on the client side.
I am not sure if this will solve the issue but it seems easy and good solution to me.
I am looking for any comments for the given solution or possible solutions for how not to increase compile permutations and need for compile each time a resource changes.

Related

Validating Java MessageFormat strings

I'm working on a Play 2 app which is being translated. Play uses Java's MessageFormat behind the scenes so I have a fair number of property values, ala:
my.interface.key={0,choice,0#{0} families|1#1 family|1<{0,number,integer} families}
I just received back a translation of this in the form:
my.interface.key={0,choix,0#{0} familles|1#1 famille|1<{0,nombre,entier} familles}
If it's not obvious, some bits of that should not have been translated, but mistakes will happen from time to time. That's fair enough, but I'm sure there must be a way of validating these strings prior to my app crashing at runtime with a IllegalArgumentException: unknown format type at ... exception. Preferably with a Git commit hook, or even an SBT build task.
If I was to hack this up myself I would probably make a tool to read these property files and check that, for each value, running MessageFormat.format(value) doesn't blow up.
Ideally I could do this via a Perl (or Python) script. Sadly, the only non-Java library I can find - Text::MessageFormat on CPAN - doesn't seem to support the most error-prone formats, such as pluralisation.
Can anyone suggest a more sensible approach based on existing tooling before I dive in?
We had a similar problem. Our solution was to create classes that model the structure of the message format, then use XML to define the messages in our message bundle.
If the translator uses an XML editor then there is some hope they won't "break" the structure of the message.
See this answer for details.

Eclipse-RCP: Getting Resourcebundles using custom ResourceBundle.Control

We load our translations from our database. To retrieve the bundles we have a custom java.util.ResourceBundle.Control.
To translate our e4 RCP application, I already created a TranslationService, which I add to the root context using an addon. That was no problem (only that I had to copy 95% of BundleTranslationProvider because I did not see any other way).
Now I want to use the new Message Extension (coming with Eclipse Luna) to translate the rest. As far as I can see from the sources of the default MessageFactoryServiceImpl, there does not seem to be an easy way to inject my ResourceBundle.Control there either.
In the linked blog series, the use case of getting the resource bundles from a database is described, but solved by using class based resource bundles. This is no option, because I can't implement a class for every resource bundle and every locale. The reason for loading the resource bundles from the database is to be able to deploy translations into new languages without redeploying the application.
Is the only way to achive this by creating my own IMessageFactoryService by copying 99% of the default MessageFactoryServiceImpl, just to pass our Control into the calls to ResourceBundleHelper?
After some investigation on this, I found a way that you are able to support your use case without modifying or copying code a lot.
You need to exchange the BundleLocalization to load the ResourceBundle your way. In your case by using your custom ResourceBundle.Control. By doing this you override that the platform is looking for the ResourceBundle specified by the MANIFEST.
At the moment you will also have to implement a custom TranslationService that uses your BundleLocalization. The existing BundleTranslationProvider does not take the BundleLocalization out of the context. And you will need to copy a lot of code there, because getBundle() is private. I will discuss possible modifications with the developers.
You can find an example here: https://github.com/fipro78/e4classbasedtranslation
Hope that helps you to solve your specific requirement.
AFAIK ResourceBundle.Control is used to load ResourceBundles. In the new Message Extension we use a custom ResourceBundle.Control to enable the loading of ResourceBundles in the OSGi context, and it is configurable via annotations.
AFAICS exchanging the ResourceBundle.Control will break any other use case supported by the new Message Extension.
The question is, why do you use a custom ResourceBundle.Control instead of creating a class based ResourceBundle? I haven't tried it yet, but maybe it is possible to create only the base ResourceBundle (without Locale information) and determine the Locale in another way than using getLocale().
But without knowing what you are doing in your custom ResourceBundle.Control, I don't know what to answer and what to suggest. Of course we could open the API for that, but as I said before, then every other plugin that makes use of the default implementation will fail.
Maybe you can give some hints on what you are doing exactly and I can show you a way to achieve your goal in another way.

GWT client global configuration values

I need to store a few configuration parameters on the client side of my GWT app--I'm only using the client side of the framework. I just want to store things like an API access URL base.
Ideally, it would be nice if this were dynamically read, but I can live with having the values statically baked in on every compilation.
When scouring the web for answers, I kept running into all the deferred binding and locale management stuff. I don't care about any of that. I just want to set some property like api.url and read it from the Java code. Failing that, I'd like to set it in an external JavaScript file and read it in from the main generated JS code somehow. However, keeping it simple is an important goal; I don't want to go down the path of some Rube Goldberg-esque JSNI monstrosity.
Is there any means of accomplishing that with some sort of properties files, or a simple JSNI import mechanism? Or am I pretty much stuck with using a Constants-based configuration class (which still requires a recompile to bake in)?
This is what you're looking for: http://www.gwtproject.org/articles/dynamic_host_page.html
In order to escape from the compilations each time when configuration changed i would like to suggest the RPC call of configuration parameters in onmodule load.
In onsuccess you can assign those parameters to your Gwt static variables,those available throughout the Gwt code.
This may reduce the pain,you can change the parameters on serverside and deploy again,No Need To Compile each time for a single line change.
You can define a property on the module xml. Like this:
<define-property values="desenv, production" name="environment"/>
<set-property name="environment" value="production"/>

Use Spring-Data-Rest to return response as XML instead of JSON

Spring-data-rest is currently RC1 (heading for GA July 16), but the documentation is still a little sketchy. So far all the example code I find shows responses defaulting to JSON, but I need XML, and ideally either XML or JSON based on ACCEPT header. I found one source in some comments in a DZone link that indicate XML is going to be supported. But that was posted during the M2 release, before RC1. I don't see anything in the Issues under the project either.
So does anybody know how to make either RC1 (or SNAPSHOT) produce XML instead of or in addition to JSON.
I wish there was an easy answer to producing XML in Spring Data REST, but I haven't found one yet. We defaulted to using JSON because we figured that's a super easy and lightweight "protocol" for transmitting objects and will work good enough for most cases.
There are a couple of problems with XML that we haven't found reasonable answers for:
How do I represent an object in XML? Do I use the property name as the element name or do I use a standard element name and put the property name in an attribute?
Where do I identify the type of the property (whether it's complex or simple, a Long, a BigInteger or what have you)?
Do I dispense with all the custom mapping information and just use JAXB or Spring OXM?
What do I do about links? Do I use the Atom namespace link element?
If I'm using Atom already, then why not use an Atom representation for everything?
Since answering these questions will necessarily involve more community input than we've had yet since the project is so new, I was thinking we'd wait until a post-1.0 release to add XML support. Priorities could obviously change if there's enough momentum in that direction, but I just don't see it happening in the next week.
There is some machinery you can override (this is just a Spring MVC application, after all) to produce any kind of a response you want. If you use the latest snapshot and override the RepositoryRestMvcConfiguration.contentNegotiatingViewResolver() method, you can provide an entirely different representation of the DTO coming out of the exporter. This is referred to in the wiki. You'll have to check the source code of JsonView to get the necessary details on what the DTO looks like internally, but it would be relatively easy to replace JsonView with MyOwnXmlView.
NOTE: This will only work for the current version of the REST exporter. The GA version will have different machinery to render output. I'll be providing hooks for doing whatever types of output rendering one wants to do, though, so you should be able to override output rendering by setting a property on the configuration. If you create a View subclass for this version, it will likely only be a matter of changing it to an HttpMessageConverter for the GA version.
Well with latest Spring IO Platform we can achieve this and with IO Platform we
dont need to worry about version also.
Have posted how to achieve in another stack overflow link as below :
Spring Boot REST with XML Support

Is it possible to make Class.forName("") flexible?

before asking, please understand that my english is not good.
I'm using Class.forName(...) class in a servlet programming. when I access the servlet, I get a row of detailed controller information from Database indicating which controller to use.
This is Class.forName(...) I coded:
Class c = Class.forName(row.getControllerInfo);
c.newInstance();
This works fine, but there's a problem, i'm using Eclipse. The problem is that when I modified the Controller file, the changed contents were not applied to the server.,,.
Probably the easiest way is not to support dynamic loading. Much better to achieve something like dynamic update by supporting multiple servers. For development, you could get around redeploy delays by using JRebel (there might be others).
If you really do want dynamic loading of classes then the answer is "class loaders". I suggest having a look at those, and come back with any specific questions.
If I understood your problem true,
When you change any file of your project, you must deploy your project to server. If you use server from eclipse, republish may solve your problem.
have you tried clean - re-built and then deploying your application?

Categories

Resources