Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    DataSourceLocalization l10n i18n question (fmt tags)

    Hi Isomorphic,

    I'm doing DataSource localization according to this docs.
    The links in the docs are outdated or even 404s (links go to non-existent Java 1.4 docs). I found the corresponding Java 7 docs, but can't in no way get the .ds.xml to be localized.

    Instead, all field titles are empty. If I look at the DataSourceLoader result directly, I see lines like
    Code:
    {title:"\n\t\t\t\t<fmt:message key=\"createdBy\" xmlns:fmt=\"WEB-INF/\"/>\n\t\t\t"
    I tried setting a higher loglevel for DataSourceLoader and even ResourceBundle and PropertyResourceBundle (result: no additional logs) and also Win8 ProcessMonitor (result: only file access at Tomcat start).

    So I'm pretty confused what went wrong.

    My .ds.xmls looks like:
    Code:
    <DataSource xmlns:fmt="WEB-INF/" dbName="Oracle" ID="T_USER" serverType="sql"
        serverConstructor="com.lmscompany.lms.server.LMSSQLDataSource">
        [B]<fmt:bundle basename="com.lmscompany.lms.shared.i18n.DSXMLResources" />[/B]
        <fields>
            <field primaryKey="true" ...
            <field foreignKey="V_USER_CREATED_BY.ID" relatedTableAlias="USER_CREATED_BY" name="CREATED_BY" type="creator">
                <title>
                    <fmt:message key="createdBy" />
                </title>
            </field>
    My DSXMLResources.java looks like this
    Code:
    [B]package com.lmscompany.lms.shared.i18n;[/B]
    
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.Reader;
    import java.util.PropertyResourceBundle;
    
    public class DSXMLResources extends PropertyResourceBundle {
        public DSXMLResources(InputStream stream) throws IOException {
            super(stream);
        }
    
        public DSXMLResources(Reader reader) throws IOException {
            super(reader);
        }
    }
    I have a DSXMLResources.properties and a DSXMLResources_de.properties and the string createdBy is defined as
    Code:
    createdBy = Created by
    I also tried with test files based on the java.com ResourceBundle samples:
    Code:
    package com.lmscompany.lms.shared.i18n;
    
    import java.util.Arrays;
    import java.util.Collections;
    import java.util.Enumeration;
    import java.util.HashSet;
    import java.util.ResourceBundle;
    import java.util.Set;
    
    // default (English language, United States)
    public class MyResources extends ResourceBundle {
        public Object handleGetObject(String key) {
            if (key.equals("leadTemperature"))
                return "leadTemperature";
            if (key.equals("leadType"))
                return "leadType";
            return null;
        }
    
        public Enumeration<String> getKeys() {
            return Collections.enumeration(keySet());
        }
    
        // Overrides handleKeySet() so that the getKeys() implementation
        // can rely on the keySet() value.
        protected Set<String> handleKeySet() {
            return new HashSet<String>(Arrays.asList("leadTemperature", "leadType"));
        }
    }
    I also tried having the files directly under src (resulting in them being directly below classes in the deployed application), Nothing worked.

    Could you show some serverside code for this?
    My aim (if possible) is to have one .properties file for all .ds.xmls.
    If that's not possible, a file per .ds.xml is also OK.

    I'm using SNAPSHOT_v10.1d_2015-11-23/PowerEdition, Tomcat 7, Java 7.

    Thank you & Best regards
    Blama

    #2
    Hi Isomorphic,

    I found the reason for this:
    This is OK:
    Code:
    <title><fmt:message key="leadTemperature" bundle="com.lmscompany.lms.shared.i18n.DSXMLResources" /></title>
    This isn't:
    Code:
                <title>
                    <fmt:message key="leadTemperature" bundle="com.lmscompany.lms.shared.i18n.DSXMLResources" />
                </title>
    It seems that the title tag may just consist out of the fmt-tag, which makes using XML-formatters (the Eclipse formatter generates the latter result) impossible.

    Could you do something about this? You can also see in the DataSourceLoader result I gave in the 1st post, that it includes a lot of "\t" and "\n".
    As these don't make sense in HTML anyway, perhaps you can always trim title tags and then let the fmt-logic run? The trimming will always benefit, also for non-fmt titles that are written as titles instead of field-level attributes.

    Best regards
    Blama

    Comment


      #3
      Unfortunately, auto-trimming would prevent the case of legitimately using line breaks, which are rare but still need support.

      You might be able to avoid Eclipse' auto-formatting if you either move the bundle name out (so the tag is shorter) or disable some setting on Eclipse preferences.

      Comment


        #4
        Hi Isomorphic,

        I moved the bundle name out (was there only to test anyway, but no change). Eclipse moves every new tag to its own line and indents as needed.
        I also want to use the Eclipse formatter, which unfortunately has no option of defining how each element should be formatted (e.g. keep message tags in line with outer tag).
        Would an additional attribute trim="true/false" at <title> and <errorMessage> tags work? Or a setting in server.properties?

        I'm pretty sure that I'm not the only one that will hit this issue, so this should be covered in the docs.

        For now I'll use an ant target to regexp-replace, but this is definitely not the best solution.

        Best regards
        Blama

        Comment


          #5
          We'll take a note that the Eclipse formatter has this limitation and that we might want to work around it. In the meantime, to improve your workflow, we'd again suggest looking for some kind of setting or alternative formatter. It's quite common in XML to put an element inside another element without dropping a line, so this is not at all a weird requirement of our framework.

          Comment


            #6
            Hello all,

            in case someone wants to use Isomorphic's .ds.xml l10n in combination with the Eclipse XML formatter (like me), here is the Ant task from my build.xml I use to convert the <title>/<errorMessage>-tags to the correct format.

            Code:
                <target name="formatDSFiles" description="Remove Eclipse source formatting for two tags from .ds.xml files">
                    <echo>Reformatting title/errorMessage fmt:message-tags in war/ds directory</echo>
                    <!-- See http://forums.smartclient.com/forum/smart-gwt-technical-q-a/233127-datasourcelocalization-l10n-i18n-question-fmt-tags -->
                    <!-- Inserting tabs does not work, therefore they need to be captured -->
                    <replaceregexp preserveLastModified="true" flags="g">
                        <regexp pattern="(\t\t\t)&lt;title&gt;\r\n\t\t\t\t&lt;fmt:message key=&quot;(.*?)&quot; /&gt;\r\n\t\t\t&lt;/title&gt;" />
                        <substitution expression="\1&lt;title&gt;&lt;fmt:message key=&quot;\2&quot; /&gt;&lt;/title&gt;" />
                        <fileset dir="war/ds">
                            <include name="*.ds.xml" />
                        </fileset>
                    </replaceregexp>
                    <replaceregexp preserveLastModified="true" flags="g">
                        <regexp pattern="(\t\t\t\t\t)&lt;errorMessage&gt;\r\n\t\t\t\t\t\t&lt;fmt:message key=&quot;(.*?)&quot; /&gt;\r\n\t\t\t\t\t&lt;/errorMessage&gt;" />
                        <substitution expression="\1&lt;errorMessage&gt;&lt;fmt:message key=&quot;\2&quot; /&gt;&lt;/errorMessage&gt;" />
                        <fileset dir="war/ds">
                            <include name="*.ds.xml" />
                        </fileset>
                    </replaceregexp>
                </target>
            Best regards
            Blama

            Comment

            Working...
            X