Changeset 5409


Ignore:
Timestamp:
Sep 16, 2010, 1:32:06 PM (12 years ago)
Author:
Nicklas Nordborg
Message:

References #1510: Implement framework for externalizing strings in the gui

The framework should now be working and some items in the menu now use it. I'll continue with the menu as part of this ticket. Since the gui is very large other parts should be added as separate tickets.

Location:
trunk
Files:
8 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/config/dist/base.config

    r5336 r5409  
    188188# Set to 1 to disable auto-compression of uploaded files
    189189autocompress.disable = 0
     190
     191# Locale settings are used to customize gui text and labels
     192# locale.language =
     193# locale.country =
     194# locacle.variant =
    190195
    191196# ===============
  • trunk/doc/src/docbook/appendix/base.config.xml

    r5362 r5409  
    766766      </listitem>
    767767    </varlistentry>
     768   
     769    <varlistentry>
     770      <term><property>locale.language</property></term>
     771      <term><property>locale.country</property></term>
     772      <term><property>locale.variant</property></term>
     773      <listitem>
     774        <para>
     775          Configure the server to a specific locale. The language and
     776          country should be valid ISO codes as specified by the
     777          <ulink url="http://download.oracle.com/javase/6/docs/api/java/util/Locale.html"
     778            >java.util.Locale</ulink> documentation. The variant
     779          can be any value that is valid as part of a filename.
     780        </para>
     781
     782        <note>
     783          <para>
     784          Note that language codes are usually lower-case but country codes are
     785          upper case. Eg. <code>sv</code> is the language code for swedish, and
     786          <code>SE</code> is the country code.
     787          </para>
     788        </note>
     789
     790        <para>
     791          This configuration can be used to provide translations to some parts of the web gui.
     792          The aim is to externalize all hard-coded gui elements from the code but
     793          it's a long way before this is a reality. The default text elements of
     794          the gui are shipped within the BASE jar files and doesn't have any
     795          locale-specific dependency. This means that unless a more specific
     796          translation is provided the default texts are always used as a fallback.
     797          Most of the default texts are found in property files in the
     798          <filename>/net/sf/basedb/clients/web/resources</filename>
     799          directory inside the <filename>BASE2Webclient.jar</filename>
     800          file. Translations should be located in the same relative path
     801          either inside their own JAR file or in the <filename>WEB-INF/classes</filename>
     802          directory. The file names should be extended with the language, country
     803          and variant separated with an underscore. For example, files with a swedish
     804          translation should be named <filename>*_sv.properties</filename>, and files
     805          with a swedish translation in Finland using the 'foo' variant should be
     806          named <filename>*_sv_FI_foo.properties</filename>.
     807        </para>
     808       
     809        <note>
     810          <para>
     811            Note that it is valid to have empty values for language and/or country
     812            and still specify a variant. Underscores are NOT collapsed. For
     813            example, in a swedish translation using the 'foo' variant the
     814            files should be named <filename>*_sv__foo.properties</filename>.
     815          </para>
     816        </note>
     817       
     818        <important>
     819          <para>
     820            All files should be saved in UTF-8 format.
     821          </para>
     822        </important>
     823       
     824      </listitem>
     825    </varlistentry>
     826   
    768827    </variablelist>
    769828  </simplesect>
  • trunk/src/core/net/sf/basedb/core/Config.java

    r5384 r5409  
    2323package net.sf.basedb.core;
    2424
     25import java.util.Locale;
    2526import java.util.Properties;
    2627import java.io.FileNotFoundException;
     
    5657 
    5758  private static java.io.File configDir = null;
     59 
     60  private static Locale locale = Locale.getDefault();
    5861 
    5962  /**
     
    7982      config.load(is);
    8083      if (overridden != null) config.putAll(overridden);
     84     
    8185    }
    8286    catch (Exception ex)
     
    9094    }
    9195    isInitialised = true;
     96   
     97    // Load locale
     98    String language = getString("locale.language", "");
     99    String country = getString("locale.country", "");
     100    String variant = getString("locale.variant", "");
     101    if (language.length() > 0 || country.length() > 0 || variant.length() > 0)
     102    {
     103      locale = new Locale(language, country, variant);
     104    }
     105    else
     106    {
     107      locale = Locale.getDefault();
     108    }
    92109  }
    93110
     
    256273  }
    257274
     275  /**
     276    Get the default locale configured for the server.
     277    @since 2.16
     278  */
     279  public static Locale getLocale()
     280  {
     281    return locale;
     282  }
    258283
    259284}
  • trunk/src/core/net/sf/basedb/core/SessionControl.java

    r5384 r5409  
    5151import java.util.Date;
    5252import java.util.Iterator;
     53import java.util.Locale;
    5354import java.util.Set;
    5455import java.util.Map;
     
    18241825 
    18251826  /**
     1827    Get the locale that is curently assigned to this session control.
     1828    @return A Locale object
     1829    @since 2.16
     1830  */
     1831  public Locale getLocale()
     1832  {
     1833    return Config.getLocale();
     1834  }
     1835 
     1836  /**
    18261837    Get the value of a session setting with the specified name.
    18271838    @param name The name of the setting
  • trunk/www/include/menu.jsp

    r5370 r5409  
    22  ------------------------------------------------------------------
    33  Copyright (C) 2005 Nicklas Nordborg, Gregory Vincic
    4   Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson, Gregory Vincic
     4  Copyright (C) 2006 Jari Hkkinen, Nicklas Nordborg, Martin Svensson, Gregory Vincic
    55  Copyright (C) 2007 Nicklas Nordborg
    66
     
    5656  import="net.sf.basedb.clients.web.Base"
    5757  import="net.sf.basedb.clients.web.util.HTML"
     58  import="net.sf.basedb.clients.web.resources.Bundle"
    5859  import="net.sf.basedb.util.Values"
     60  import="net.sf.basedb.util.resources.ResourceBundleWrapper"
     61  import="net.sf.basedb.util.resources.ResourceBundleFactory"
    5962  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
    6063  import="net.sf.basedb.clients.web.extensions.JspContext"
     
    7881final String root = request.getContextPath()+"/";
    7982if ("exception".equals(name) && sc != null && sc.isLoggedIn()) name = "standard";
     83
     84final ResourceBundleWrapper common = ResourceBundleFactory.getResourceBundle(Bundle.COMMON, sc);
     85final ResourceBundleWrapper menu = ResourceBundleFactory.getResourceBundle(Bundle.MENU, sc);
    8086
    8187if ("login".equals(name))
     
    407413      >
    408414      <m:menuitem
    409         title="Home"
     415        title="<%=menu.getString("home.title")%>"
     416        tooltip="<%=menu.getString("home.tooltip")%>"
    410417        onclick="<%="Menu.openUrl('"+root+"my_base/index.jsp?ID="+ID+"')"%>"
    411418      />
    412419      <m:menuitem
    413         title="All items"
    414         tooltip="View all items that you are the owner of"
     420        title="<%=menu.getString("allitems.title")%>"
     421        tooltip="<%=menu.getString("allitems.tooltip")%>"
    415422        onclick="<%="Menu.openUrl('"+root+"views/items/index.jsp?ID="+ID+"')"%>"
    416423      />
    417424      <m:menuitem
    418         title="Trashcan"
    419         tooltip="View all items that have been marked for deletion"
     425        title="<%=menu.getString("trashcan.title")%>"
     426        tooltip="<%=menu.getString("trashcan.tooltip")%>"
    420427        onclick="<%="Menu.openUrl('"+root+"views/trashcan/index.jsp?ID="+ID+"')"%>"
    421428      />
    422429      <m:menuseparator />
    423430      <m:menuitem
    424         title="Files"
     431        title="<%=common.getString("item.files")%>"
    425432        onclick="<%="Menu.openUrl('"+root+"filemanager/index.jsp?ID="+ID+"')"%>"
    426         tooltip="<%=hasFiles ? "Manage files" : "You do not have permission to manage files"%>"
     433        tooltip="<%=menu.getString("files.tooltip", hasFiles)%>"
    427434        enabled="<%=hasFiles%>"
    428435      />
    429436      <m:menuitem
    430         title="File servers"
     437        title="<%=common.getString("item.fileservers")%>"
    431438        onclick="<%="Menu.openUrl('"+root+"filemanager/fileservers/index.jsp?ID="+ID+"')"%>"
    432         tooltip="<%=hasFileServers ? "Manage file servers" : "You do not have permission to manage file servers"%>"
     439        tooltip="<%=menu.getString("fileservers.tooltip", hasFileServers)%>"
    433440        enabled="<%=hasFileServers%>"
    434441      />
    435442      <m:menuitem
    436         title="Projects"
     443        title="<%=common.getString("item.projects")%>"
    437444        onclick="<%="Menu.openUrl('"+root+"my_base/projects/index.jsp?ID="+ID+"')"%>"
    438         tooltip="Manage projects"
     445        tooltip="<%=menu.getString("projects.tooltip", hasProjects)%>"
    439446        enabled="<%=hasProjects%>"
    440447      />
    441448      <m:menuitem
    442         title="Permission templates"
     449        title="<%=common.getString("item.permissiontemplates")%>"
    443450        onclick="<%="Menu.openUrl('"+root+"views/permissiontemplates/index.jsp?ID="+ID+"')"%>"
    444         tooltip="Manage permission templates"
     451        tooltip="<%=menu.getString("permissiontemplates.tooltip", hasPermissionTemplates)%>"
    445452        enabled="<%=hasPermissionTemplates%>"
    446453      />
    447454      <m:menuitem
    448         title="Messages"
     455        title="<%=common.getString("item.messages")%>"
    449456        onclick="<%="Menu.openUrl('"+root+"my_base/messages/index.jsp?ID="+ID+"')"%>"
    450         tooltip="<%=hasMessages ? "Read your messages" : "You do not have permission to read messages"%>"
     457        tooltip="<%=menu.getString("messages.tooltip", hasMessages)%>"
    451458        enabled="<%=hasMessages%>"
    452459      />
    453460      <m:menuitem
    454         title="Jobs"
     461        title="<%=common.getString("item.jobs")%>"
    455462        onclick="<%="Menu.openUrl('"+root+"views/jobs/index.jsp?ID="+ID+"')"%>"
    456         tooltip="<%=hasJobs ? "Check the status of your jobs" : "You do not have permission to access jobs"%>"
     463        tooltip="<%=menu.getString("jobs.tooltip", hasJobs)%>"
    457464        enabled="<%=hasJobs%>"
    458465      />
    459466      <m:menuitem
    460         title="Sessions"
     467        title="<%=common.getString("item.sessions")%>"
    461468        onclick="<%="Menu.openUrl('"+root+"views/sessions/index.jsp?ID="+ID+"')"%>"
    462         tooltip="<%=hasSessions ? "Check you login sessions" : "You do not have permission to access sessions"%>"
     469        tooltip="<%=menu.getString("sessions.tooltip", hasSessions)%>"
    463470        enabled="<%=hasSessions%>"
    464471      />
    465472      <m:menuseparator />
    466473      <m:menuitem
    467         title="Hybridizations"
     474        title="<%=common.getString("item.hybridizations")%>"
    468475        onclick="<%="Menu.openUrl('"+root+"views/hybridizations/index.jsp?ID="+ID+"')"%>"
    469         tooltip="<%=hasHybridizations ? "Manage hybridizations" : "You do not have permission to manage hybridizations"%>"
     476        tooltip="<%=menu.getString("hybridizations.tooltip", hasHybridizations)%>"
    470477        enabled="<%=hasHybridizations%>"
    471478      />
    472479      <m:menuitem
    473         title="Scans"
     480        title="<%=common.getString("item.scans")%>"
    474481        onclick="<%="Menu.openUrl('"+root+"views/scans/index.jsp?ID="+ID+"')"%>"
    475         tooltip="<%=hasScans ? "Manage scans" : "You do not have permission to manage scans"%>"
     482        tooltip="<%=menu.getString("scans.tooltip", hasScans)%>"
    476483        enabled="<%=hasScans%>"
    477484      />
    478485      <m:menuitem
    479         title="Raw bioassays"
     486        title="<%=common.getString("item.rawbioassays")%>"
    480487        onclick="<%="Menu.openUrl('"+root+"views/rawbioassays/index.jsp?ID="+ID+"')"%>"
    481         tooltip="<%=hasRawBioAssays ? "Manage raw bioassays" : "You do not have permission to manage raw bioassays"%>"
     488        tooltip="<%=menu.getString("rawbioassays.tooltip", hasRawBioAssays)%>"
    482489        enabled="<%=hasRawBioAssays%>"
    483490      />
    484491      <m:menuitem
    485         title="Experiments"
     492        title="<%=common.getString("item.experiments")%>"
    486493        onclick="<%="Menu.openUrl('"+root+"views/experiments/index.jsp?ID="+ID+"')"%>"
    487         tooltip="<%=hasExperiments ? "Manage experiments" : "You do not have permission to manage experiments"%>"
     494        tooltip="<%=menu.getString("experiments.tooltip", hasExperiments)%>"
    488495        enabled="<%=hasExperiments%>"
    489496      />
    490497      <m:menuitem
    491         title="Formulas"
     498        title="<%=common.getString("item.formulas")%>"
    492499        onclick="<%="Menu.openUrl('"+root+"views/formulas/index.jsp?ID="+ID+"')"%>"
    493         tooltip="<%=hasFormulas ? "Manage formulas" : "You do not have permission to manage formulas"%>"
     500        tooltip="<%=menu.getString("formulas.tooltip", hasFormulas)%>"
    494501        enabled="<%=hasFormulas%>"
    495502      />
    496503      <m:menuseparator />
    497504      <m:menuitem
    498         title="Reporters"
     505        title="<%=common.getString("item.reporters")%>"
    499506        onclick="<%="Menu.openUrl('"+root+"views/reporters/index.jsp?ID="+ID+"')"%>"
    500         tooltip="<%=hasReporters ? "Manage reporters" : "You do not have permission to manage reporters"%>"
     507        tooltip="<%=menu.getString("reporters.tooltip", hasReporters)%>"
    501508        enabled="<%=hasReporters%>"
    502509      />
    503510      <m:menuitem
    504         title="Reporter lists"
     511        title="<%=common.getString("item.reporterlists")%>"
    505512        onclick="<%="Menu.openUrl('"+root+"views/reporterlists/index.jsp?ID="+ID+"')"%>"
    506         tooltip="<%=hasReporterLists ? "Manage reporter lists" : "You do not have permission to manage reporter lists"%>"
     513        tooltip="<%=menu.getString("reporterlists.tooltip", hasReporterLists)%>"
    507514        enabled="<%=hasReporterLists%>"
    508515      />
     
    10231030      <m:menuitem
    10241031        visible="<%=HTML.isValidUrl(helplink)%>"
    1025         title="Help&hellip;"
     1032        title="<%=menu.getString("menu.help") + "…"%>"
    10261033        onclick="<%="window.open('"+helplink+"','Help')"%>"
    10271034      />
    10281035      <m:menuitem
    10291036        visible="<%=HTML.isValidUrl(faqlink)%>"
    1030         title="FAQ&hellip;"
     1037        title="<%=menu.getString("faq.title") + "…"%>"
    10311038        onclick="<%="window.open('"+faqlink+"','FAQ')"%>"
     1039        tooltip="<%=menu.getString("faq.tooltip") %>"
    10321040      />
    10331041      <m:menuseparator />
    10341042
    10351043      <m:menuitem
    1036         title="About&hellip;"
     1044        title="<%=menu.getString("about.title") + "…"%>"
    10371045        onclick="<%="Main.openPopup('"+root+"info/about.jsp?ID="+ID+"&page=about', 'About', 500, 350)"%>"
    10381046      />
    10391047
    10401048      <m:menuitem
    1041         title="License&hellip;"
     1049        title="<%=menu.getString("license.title") + "…"%>"
    10421050        onclick="<%="Main.openPopup('"+root+"info/about.jsp?ID="+ID+"&page=license', 'About', 500, 350)"%>"
    1043 
    10441051      />
    10451052      <m:menuitem
    10461053        visible="<%=HTML.isValidUrl(reportbuglink)%>"
    1047         title="Report a bug&hellip;"
     1054        title="<%=menu.getString("bugreport.title") + "…"%>"
    10481055        onclick="<%="window.open('"+reportbuglink+"','Reportbug')"%>"
     1056        tooltip="<%=menu.getString("bugreport.tooltip")%>"
    10491057      />
    10501058      <m:menuseparator />
    10511059      <m:menuitem
    1052         title="Base project site" onclick="<%="Menu.openUrl('http://base.thep.lu.se', 'basesite')"%>"
     1060        title="<%=menu.getString("basesite.title") + "…"%>"
     1061        onclick="<%="Menu.openUrl('http://base.thep.lu.se', 'basesite')"%>"
     1062        tooltip="<%=menu.getString("basesite.tooltip")%>"
    10531063      />
    10541064    </m:menu>
     
    11931203      <m:submenu
    11941204        subid="base"
    1195         title="BASE"
     1205        title="<%=menu.getString("menu.base")%>"
    11961206      />
    11971207      <m:submenu
    11981208        subid="view"
    1199         title="View"
     1209        title="<%=menu.getString("menu.view")%>"
    12001210      />
    12011211      <m:submenu
    12021212        subid="biolims"
    1203         title="Biomaterial LIMS"
     1213        title="<%=menu.getString("menu.biolims")%>"
    12041214      />
    12051215      <m:submenu
    12061216        subid="lims"
    1207         title="Array LIMS"
     1217        title="<%=menu.getString("menu.arraylims")%>"
    12081218      />
    12091219      <m:submenu
    12101220        subid="administrate"
    1211         title="Administrate"
     1221        title="<%=menu.getString("menu.administrate")%>"
    12121222        visible="<%=hasAdministrate%>"
    12131223      />
    12141224      <m:submenu
    12151225        subid="extensions"
    1216         title="Extensions"
     1226        title="<%=menu.getString("menu.extensions")%>"
    12171227      />
    12181228      <m:submenu
    12191229        subid="help"
    1220         title="Help"
     1230        title="<%=menu.getString("menu.help")%>"
    12211231      />
    12221232    </m:menu></div>
     
    12331243
    12341244
    1235 
Note: See TracChangeset for help on using the changeset viewer.