
Contains methods and data necessary to provide localization.
Below is an example language file from Locale.en-US.Date.js. Note that some members are arrays (months and days), others are strings, and one is even a function. Also note that some of the strings contain notation for variable substitution. Each class establishes it's own conventions for the language file that is required and is therefore required to document those conventions. Look for these at the bottom of the class's Locale documentation.
Locale.define('en-US', 'Date', { months: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], days: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'], dateOrder: ['month', 'date', 'year', '/'], AM: "AM", PM: "PM", //members can be functions; these will be executed and passed any arguments with .get(member[,args]) ordinal: function(dayOfMonth){ return (dayOfMonth > 3 && dayOfMonth < 21) ? 'th' : ['th', 'st', 'nd', 'rd', 'th'][Math.min(dayOfMonth % 10, 4)]; }, lessThanMinuteAgo: 'less than a minute ago' });
This event is fired whenever the current locale is changed for the user (for instance, from "en-US" to "es-ES") or whenever the current selected locale is updated with new data.
Locale.addEvent('change', function(name){ alert('Youre locale settings changed to ' + name); });
Defines properties for a given set in a given language.
Locale.define(name, set, data); // or Locale.define(name, set, key, value);
Locale.define('en-US', 'Date', { months: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], days: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'], dateOrder: ['month', 'date', 'year', '/'], AM: "AM", PM: "PM" });
Sets the current locale for the user.
Locale.use(name);
Locale.use('nl-NL');
Returns the locale name currently in use.
Locale.getCurrent();
Locale.getCurrent().name // 'en-US'
Retrieves a set of locale properties for the current language or the whole set.
Locale.get(key[, args]);
Set.key
. This will use Object.getFromPath for nested properties.Locale.get('Date.dayAgo'); //"1 day ago" Locale.get('Date.nested.property'); // the get method is using Object.getFromPath to find properties Locale.get('Date.ordinal', 1); //"st" > as in "1st" Locale.get('Date.dayAgo', 'foo'); //foo is ignored Locale.get('Date'); //returns the object of key/values for Date in the current language
.
' in the key argument can be used to find nested properties.It often occurs that localization data is based on another language.
For example Spanish in Argentina has many similarities with Spanish
or Number formatting in Europe is the same for lots of Europe countries.
Therefore it is possible to inherit another locale data from another
language. Locale.get
will search trough the inherited locale names
until a property is set.
Locale.inherit(name, parent[, set]);
Locale.inherit('es-AR', 'es-ES'); // Only inherit for a specific data set Locale.inherit('de-CH', 'de-DE', 'Number');
Returns an array of languages currently supported.
Locale.list();
© Linux.ria.ua, 2008-2024 |