Hi

I am trying to reduce the compilation time of my GWT app. There are about 
160 permutations done for now and the reason is big number of 
languages/locales supported. The main idea is to get rid of the static 
compilation and replace it with dynamic loading of localized data. I have 
almost succeeded, but now I am facing the problem with linker, which does 
not expose public artifacts when I run project from IntelliJ Idea. I will 
give more details and then point where the problem is now. 

I already have the `Messages` interface and multiple `.properties` files 
with defined translations and also I am using GXT library, which also uses 
'static' internationalization. Thus the only way I can imagine myself is to 
replace the Localizable generator with my own implementation. I have 
defined it in a separate module:

<generate-with class="org.traccar.web.i18n.rebind.LocalizableGenerator">
    <when-type-assignable class="com.google.gwt.i18n.shared.Localizable" />
</generate-with>


Then in generator I simply produce a single implementation, which will use 
another class to load the strings from module's resources available under 
{module.base.url}/i18n/path/to/package/ClassName/{locale}, for example 
MyModule/i18n/com/google/gwt/i18n/client/constants/NumberConstantsImpl/ru


I intend to store the localized strings as JSON object, which will be generated 
by the 'generator' as well. Here is the code of my 'LocalizableGenerator':


JsonFactory jsonFactory = new JsonFactory();
for (GwtLocale locale : localeParams.allLocales) {
    AbstractResource.ResourceList resourceList = null;
    try {
        resourceList = ResourceFactory.getBundle(logger, targetClass, locale,
                assignableToConstants, context);
        OutputStream os = context.tryCreateResource(logger, resource + "/" + 
locale.toString());
        if (os != null) {
            JsonGenerator jg = jsonFactory.createGenerator(os, 
JsonEncoding.UTF8);
            jg.writeStartObject();
            for (String key : resourceList.keySet()) {
                AbstractResource.ResourceEntry entry = 
resourceList.getEntry(key);
                Collection<String> forms = entry.getForms();
                if (forms.isEmpty()) {
                    jg.writeStringField(key, resourceList.getString(key));
                } else {
                    jg.writeObjectFieldStart(key);
                    jg.writeStringField("null", resourceList.getString(key));
                    for (String form : forms) {
                        jg.writeStringField(form, entry.getForm(form));
                    }
                    jg.writeEndObject();
                }
            }
            jg.writeEndObject();
            jg.flush();
            GeneratedResource generatedResource = 
context.commitResource(logger, os);
            context.commitArtifact(logger, generatedResource);
        }
    } catch (MissingResourceException e) {
        throw error(logger,
                "Localization failed; there must be at least one resource 
accessible through"
                        + " the classpath in package '" + 
targetClass.getPackage().getName()
                        + "' whose base name is '"
                        + ResourceFactory.getResourceName(targetClass) + "'");
    } catch (IllegalArgumentException e) {
        // A bad key can generate an illegal argument exception.
        throw error(logger, e.getMessage());
    } catch (IOException e) {
        throw error(logger, e);
    }
}


The generation works just fine. I can see produced files in a temporary folder. 
Looks like they are included in the .war file as well when I produce it with 
maven. However, they are not visible when I run my application in SDM from 
IntelliJ Idea.


Full source code is available on github: 
https://github.com/vitalidze/traccar-web/tree/dynamic_i18n


Commit with above changes: 
https://github.com/vitalidze/traccar-web/commit/12ceb111e20bb79aa9e046b9b9db5aae5aa84ffd


Any help appreciated.

-- 
You received this message because you are subscribed to the Google Groups "GWT 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

Reply via email to