Contains methods and data necessary to provide localization.
Below is an example language file from Date.English.US.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 therefor required to document those conventions. Look for these at the bottom of the class's documentation.
MooTools.lang.set('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', minuteAgo: 'about a minute ago', minutesAgo: '{delta} minutes ago', hourAgo: 'about an hour ago', hoursAgo: 'about {delta} hours ago', dayAgo: '1 day ago', daysAgo: '{delta} days ago', lessThanMinuteUntil: 'less than a minute from now', minuteUntil: 'about a minute from now', minutesUntil: '{delta} minutes from now', hourUntil: 'about an hour from now', hoursUntil: 'about {delta} hours from now', dayUntil: '1 day from now', daysUntil: '{delta} days from now' });
All the above code does is register these values for the 'en-US' language for 'Date'. Date has attached an event to MooTools.lang in order to monitor these changes and update it's local store of this data. See below.
//Italian cascades to Spanish, then to British English //(this is just an example of how to do it - not a suggestion!) MooTools.lang.set('IT', 'cascade', ['IT', 'ESP', 'gbENG']);
This event is fired whenever the language is changed for the user (for instance, from "en-US" to "ESP") or whenever the current selected language is updated with new data.
Sets the current language for the user.
MooTools.lang.setLanguage(lang);
Returns the language currently in use.
MooTools.lang.getCurrentLanguage();
Retrieves a set of language properties for the current language.
MooTools.lang.get(set[, key, args]);
MooTools.lang.get('Date', 'dayAgo'); //"1 day ago" MooTools.lang.get('ordinal', 1); //"st" > as in "1st" MooTools.lang.get('Date', 'dayAgo', 'foo'); //foo is ignored MooTools.lang.get('Date'); //returns the object of key/values for Date in the current language
Sets properties for a given set in a given language.
MooTools.lang.set(lang, set, members);
MooTools.lang.set('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" });
Returns an array of languages currently supported.
MooTools.lang.list();
This documentation is released under a Attribution-NonCommercial-ShareAlike 3.0 License.