Config
Table of Contents

Class

O.LocaleController

This static class has methods for localising strings or dates and for registering and setting the user interface locale.

"use strict";

( function ( NS, undefined ) {

Private Property

O.LocaleController-locales

  • Object
  • private

Stores the loaded O.Locale instances.

var locales = {
 xx: new NS.Locale({ code: 'xx' })
};

Private Property

O.LocaleController-active

The active locale.

var active = locales.xx;

var LocaleController = {

Property

O.LocaleController.activeLocaleCode

  • String

The locale code for the active locale.

activeLocaleCode: 'xx',

Method

O.LocaleController.addLocale( locale )

Registers a resource bundle with the class.

Parameters

localeO.Locale The locale instance containing translated strings, date formats etc.

Returns

O.LocaleController Returns self.

addLocale: function ( locale ) {
   locales[ locale.code ] = locale;
   return this;
 },

Method

O.LocaleController.setLocale( localeCode )

Sets a different locale as the active one. Will only have an effect if the resource bundle for this locale has already been loaded and registered with a call to addLocale. Future calls to localise() etc. will now use the resources from this locale.

Parameters

localeCodeString The code for the locale to make active.

Returns

O.LocaleController Returns self.

setLocale: function ( localeCode ) {
   if ( locales[ localeCode ] ) {
     active = locales[ localeCode ];
     this.activeLocaleCode = localeCode;
   }
   return this;
 },

Method

O.LocaleController.getLocale( localeCode )

Returns a previously added locale object.

Parameters

localeCodeString Optional The code for the locale to return. If not specified, the currently active locale will be returned.

Returns

Locale|null Returns the locale object (null if not present).

getLocale: function ( localeCode ) {
   return localeCode ? locales[ localeCode ] || null : active;
 },

Function

O.LocaleController.get( key )

Gets a property from the active locale.

Parameters

keyString The name of the property to fetch.

Returns

* The value for that key.

get: function ( key ) {
   return active[ key ];
 },

Function

O.LocaleController.localise( text )

Get a localised version of a string.

Parameters

textString The string to localise.
var_args...(String|Number) The arguments to interpolate.

Returns

String The localised string.

localise: function ( text ) {
   if ( arguments.length === 1 ) {
     var translation = active.translations[ text ];
     return translation !== undefined ? translation : text;
   } else {
     return active.translate.apply( active, arguments );
   }
 },

Function

O.LocaleController.date( date, type, utc )

Get a date or time formatted according to local conventions.

Parameters

date...(String|Number|Object) The arguments to interpolate.
typeString The type of result you want, e.g. 'shortDate', 'time', 'fullDateAndTime'.
utcBoolean Optional If true, the UTC time of this date object will be used when determining the day.

Returns

String The localised date.

date: function ( date, type, utc ) {
   return active.getFormattedDate( date, type, utc );
 },

Function

O.LocaleController.number( n )

Format a number according to local conventions. Ensures the correct symbol is used for a decimal point, and inserts thousands separators if used in the locale.

Parameters

n(Number|String) The number to format.

Returns

String The localised number.

number: function ( n ) {
   return active.getFormattedNumber( n );
 },

Function

O.LocaleController.ordinal( n )

Format an ordinal number according to local conventions, e.g. "1st", "42nd" or "53rd".

Parameters

nNumber The number to format.

Returns

String The localised ordinal.

ordinal: function ( n ) {
   return active.getFormattedOrdinal( n );
 },

Function

O.LocaleController.fileSize( bytes, decimalPlaces )

Format a number of bytes into a locale-specific file size string.

Parameters

bytesNumber The number of bytes.
decimalPlacesNumber Optional The number of decimal places to use in the result, if in MB or GB.

Returns

String The localised, human-readable file size.

fileSize: function ( bytes, decimalPlaces ) {
   return active.getFormattedFileSize( bytes, decimalPlaces );
 }
};

NS.LocaleController = NS.i18n = LocaleController;
NS.loc = LocaleController.localise;

}( O ) );
Animation
Application
Core
DataStore
DOM
DragDrop
Foundation
IO
Localisation
Selection
Parser
TimeZones
Storage
Touch
CollectionViews
UA
ContainerViews
ControlViews
PanelViews
View