Announcement

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

    Default language for i18n of datasources

    Hi there,

    working on localizing our datasources. I am wondering about setting default language. In our case, Swedish is the most common language. I would therefor like the _sv file to be the 'default', fallback language file, rather than the default .properties.

    Is there a way to specify this?

    EDIT: Nvm, apparently i have to have an _en properties file, a Swedish one, and then put Swedish again in the Default one. Alternatively, i could set default system locale to Swedish, but i want Swedish to be the default only for these bundles...
    Last edited by mathias; 28 Jun 2018, 22:57.

    #2
    Hi mathias,

    another solution: Specify yourself what should be loaded for what user agent locale.

    Make your main HTML page JSP and do sth like this:
    Code:
        String userLanguage = null;
    
        // Try to get the user language from the cookie
        Cookie cookie = null;
        Cookie[] cookies = null;
        cookies = request.getCookies();
        if (cookies != null) {
            for (int i = 0; i < cookies.length; i++) {
                cookie = cookies[i];
                if ("lang".equals(cookie.getName())) {
                    userLanguage = cookie.getValue();
                }
                if (!"de".equals(userLanguage) && !"en".equals(userLanguage) && !"da".equals(userLanguage)) {
                    userLanguage = null;
                }
            }
        }
        // If it was not possible to get the user language from the cookie, try to get from the request headers.
        if (userLanguage == null && request.getLocale() != null && request.getLocale().getLanguage() != null) {
            userLanguage = request.getLocale().getLanguage().toLowerCase();
        }
    
        // Default to English if nothing or unknown language found
        if (!"de".equals(userLanguage) && !"en".equals(userLanguage) && !"da".equals(userLanguage)) {
            userLanguage = "en";
        }
    and

    Code:
    <!DOCTYPE html><%@include file="frameworkVersion.jsp" %><%@include file="lastDSFileChange.jsp" %><%@include file="dataSources.jsp" %>
    <html>
        <head>
            <meta http-equiv="content-type" content="text/html; charset=UTF-8">
            <meta name="gwt:property" content="locale=[B]<%=userLanguage %>[/B]">
    ...
    <script src="myproj/sc/DataSourceLoader<%=version %>&amp;lastDSChange=<%=dsLastChangedISO %>&amp;loggedInUserName=<%=loggedInUserName %>&amp;[B]locale=<%=userLanguage %>[/B]&amp;dataSource=<%=outputDataSources()%>"></script>
    That way, you control for the application as well as the DataSources how they should be localized.
    You could also build more advanced fallback strategies, if a requested language is not present.
    Imagine a user requests de_ch and you don't have de. Then instead of en, you fallback to fr, which might make sense in Switzerland.

    Please note that you will also need this at the beginning of your main Java file in order to prevent the Servlets to just take the incoming request header's language in operation.
    Code:
            RPCManager.setActionURL(RPCManager.getActionURL() + "?locale=" + Helper.getCookieOrBrowserLanguage());
            DataSource.setLoaderURL(DataSource.getLoaderURL() + "?locale=" + Helper.getCookieOrBrowserLanguage());
    This way you can build a user configured application language setting that does not depend on request headers.

    Best regards
    Blama

    Comment


      #3
      Hey Blama, as always appreciate you trying to help! :)

      Your suggestion is exactly how i do it, which works well. Maybe i was not 100% clear - my issue is rather with which file is used for the locale:

      I set the locale as you suggest based on my application's user account settings from the database. The way property files works is that, say a user has Swedish locale, the _sv property file is used. If the locale property file is not found, the 'default' file is used.

      Rather than have English in the default property file, i wondered if there was a way to specify that "if a language key is not found for the locale, use the _sv"-locale as default, without having to redefine the system wide default locale, since i need that to stay in English because of other parts of the system. I hope it makes sense.

      My usecase for this is that i have the datasources in Swedish only right now, and if i forget a string somewhere, i want it to default back to the Swedish. But i guess i'll just be extra careful that all strings are indeed localized, and have Swedish strings in the default property file as well.

      Comment


        #4
        Hi mathias,

        I think Isomorphic is just using the default Java Locale system here. I don't think it is possible to configure a per-language fallback here, neither in Java, nor in SmartGWT, which would need to give you access to this configuration.
        Please note that this thread is also about a more developer controlled ds.xml l10n.

        Best regards
        Blama

        Comment


          #5
          Blama is correct, further, we don't even understand the desire. If you force the locale to Swedish by the mechanisms that already exist, then it will look for Swedish strings first. If something is missing in your Swedish locale, it will indeed fall back to English, but what's the alternative, returning blank? That doesn't seem better.

          Comment


            #6
            The reason for me thinking about this is simply that we're a small company and i want to minimize the impact of any mistakes that might occur in the localization files. But again, i guess i'll just be super careful. Thanks for your feedback!

            Comment

            Working...
            X