Skip to content

Instantly share code, notes, and snippets.

Last active Feb 11, 2016
What would you like to do?
Set Moment locale to the Titanium SDK Ti.Locale.currentLocale
var moment = require('alloy/moment');
// First add languages that support your application
var languages = ['ru', 'nl', 'fr', 'fr-ca'];
// Full language list:
// You must explicit way to require language files in order to compiler saw their.
function selectLanguage(lang) {
// Not all locales with country code has corresponding file in the alloy/moment.
// So we will use first 2-letter language code as insurance.
[lang.split('-')[0], lang.toLowerCase()].forEach(function(lang) {
if(languages.indexOf(lang) !== -1) {
exports.selectLanguage = selectLanguage;
var moment = require('alloy/moment');
var mod = require('momentLang');'current locale:', Ti.Locale.currentLocale);'current language:', moment.lang(), 'date:', moment().format('L'));
mod.selectLanguage(Ti.Locale.currentLocale);'current language:', moment.lang(), 'date:', moment().format('L'));
// Ask user for language or select as you need (Ti.Locale.currentLocale).
// Letter case does not matter.
mod.selectLanguage('fr-ca');'current language:', moment.lang(), 'date:', moment().format('L'));
mod.selectLanguage('fr');'current language:', moment.lang(), 'date:', moment().format('L'));
mod.selectLanguage('nl-BE');'current language:', moment.lang(), 'date:', moment().format('L'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment