SOLR-4364: Admin UI - Locale based number formatting

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1440014 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stefan Matheis 2013-01-29 17:34:10 +00:00
parent 6e94f43152
commit 243cb60ed2
2 changed files with 43 additions and 1 deletions

View File

@ -115,6 +115,8 @@ Optimizations
* SOLR-4284: Admin UI - make core list scrollable separate from the rest of
the UI (steffkes)
* SOLR-4364: Admin UI - Locale based number formatting (steffkes)
Other Changes
----------------------

View File

@ -175,6 +175,12 @@ var solr_admin = function( app_config )
this.core_regex_base = '^#\\/([\\w\\d-\\.]+)';
browser = {
locale : null,
language : null,
country : null
};
show_global_error = function( error )
{
var main = $( '#main' );
@ -294,6 +300,24 @@ var solr_admin = function( app_config )
this.run = function()
{
var navigator_language = navigator.userLanguage || navigator.language;
var language_match = navigator_language.match( /^(\w{2})([-_](\w{2}))?$/ );
if( language_match )
{
if( language_match[1] )
{
browser.language = language_match[1].toLowerCase();
}
if( language_match[3] )
{
browser.country = language_match[3].toUpperCase();
}
if( language_match[1] && language_match[3] )
{
browser.locale = browser.language + '_' + browser.country
}
}
$.ajax
(
{
@ -536,7 +560,23 @@ var solr_admin = function( app_config )
this.format_number = function format_number( number )
{
return ( number || 0 ).toString().replace( /\B(?=(\d{3})+(?!\d))/g, ' ' );
var sep = {
'de_CH' : '\'',
'de' : '.',
'en' : ',',
'es' : '.',
'it' : '.',
'ja' : ',',
'sv' : ' ',
'tr' : '.',
'_' : '' // fallback
};
return ( number || 0 ).toString().replace
(
/\B(?=(\d{3})+(?!\d))/g,
sep[ browser.locale ] || sep[ browser.language ] || sep['_']
);
};
};