Skip to content

Commit

Permalink
draft configurable locale
Browse files Browse the repository at this point in the history
  • Loading branch information
abretaud committed Jan 9, 2018
1 parent 60e0b3a commit c5fa911
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 13 deletions.
41 changes: 28 additions & 13 deletions client/galaxy/scripts/utils/localization.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,35 @@ define(["i18n!nls/locale"], function(localeStrings) {
// =============================================================================
/** Simple string replacement localization. Language data from galaxy/scripts/nls */

// support both requirejs and webpack from the same file
// if loaded via webpack, it will be a different format than via requirejs - convert
if (localeStrings.hasOwnProperty("__root")) {
//console.debug( 'amdi18n+webpack localization for ' + locale + ' loaded' );
var locale =
typeof navigator === "undefined"
? "__root"
: (navigator.language || navigator.userLanguage || "__root").toLowerCase();
localeStrings =
localeStrings["__" + locale] || localeStrings["__" + locale.split("-")[0]] || localeStrings.__root;

// } else {
// console.debug( 'i18n+requirejs localization for ' + locale + ' loaded' );
function onloadLocaleConfig() {
// Wait until Galaxy.config is loaded.
if (Galaxy.config && localeStrings.hasOwnProperty("__root")) {
var global_locale = Galaxy.config.default_locale ? Galaxy.config.default_locale.toLowerCase() : false;

var extra_user_preferences = {};
if (Galaxy.user && Galaxy.user.attributes.preferences && 'extra_user_preferences' in Galaxy.user.attributes.preferences) {
extra_user_preferences = JSON.parse(Galaxy.user.attributes.preferences.extra_user_preferences);
}

var user_locale = 'localization|locale' in extra_user_preferences ? extra_user_preferences['localization|locale'].toLowerCase() : false;

var nav_locale =
typeof navigator === "undefined"
? "__root"
: (navigator.language || navigator.userLanguage || "__root").toLowerCase();

console.debug('global_locale: ' + global_locale);
console.debug('user_locale: ' + user_locale);
console.debug('nav_locale: ' + nav_locale);

localeStrings =
localeStrings["__" + user_locale] || localeStrings["__" + global_locale] || localeStrings["__" + nav_locale] || localeStrings["__" + nav_locale.split("-")[0]] || localeStrings.__root;
} else {
setTimeout(onloadLocaleConfig, 100);
}
}
onloadLocaleConfig();

// TODO: when this is no longer necessary remove this, i18n.js, and the resolveModule in config

// -----------------------------------------------------------------------------
Expand Down
8 changes: 8 additions & 0 deletions config/galaxy.ini.sample
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,14 @@ nglims_config_file = tool-data/nglims.yaml
# standard).
#pretty_datetime_format = $locale (UTC)

# Default localization for Galaxy UI.
# Allowed values are listed at the end of client/galaxy/scripts/nls/locale.js.
# With the default value (auto), the locale will be automatically adjusted to
# the user's navigator language.
# Users can override this settings in their user preferences if the localization
# settings are enabled in user_preferences_extra_conf.yml
#default_locale = auto

# URL (with schema http/https) of the Galaxy instance as accessible within your
# local network - if specified used as a default by pulsar file staging and
# Jupyter Docker container for communicating back with Galaxy via the API.
Expand Down
14 changes: 14 additions & 0 deletions config/user_preferences_extra_conf.yml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,17 @@ preferences:
checked: false
value: false
help: If you select yes, you will be able to select for each tool and workflow run if you would like to use this feature.

localization:
description: Localization
inputs:
- name: locale
label: Prefered language
type: select
required: False
options:
- [Navigator default, auto]
- [Chinese, zh]
- [English, en]
- [French, fr]
- [Japanese, ja]

0 comments on commit c5fa911

Please sign in to comment.