Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-23403] iOS: Debug exception when calling moment.locale(Ti.Locale.currentLocale)

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionCannot Reproduce
Resolution Date2019-11-14T16:25:49.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsiOS
Labelsdefect, iOS
ReporterChristy Thomas
AssigneeAngel Petkov
Created2016-05-12T13:54:32.000+0000
Updated2019-11-14T16:25:49.000+0000

Description

This is the line of code the exception is happening and name variable is "en-US", but we also use french as well and is the reason why we are calling moment.locale. require("alloy/moment/lang/" + name);
Thread [kroll$1] (Suspended (exception at line 134 in moment.js))	
	loadLocale(name) [moment.js:134]	
	locale_locales__getLocale(key) [moment.js:163]	
	locale_locales__getSetGlobalLocale(key, values) [moment.js:142]	
	Controller() [index.js:43]	
	createController(name, args) [alloy.js:232]	
	[Top-level script] [app.js:3]	
In Run mode this works fine and our date displays correctly for the locale. The example doesn't display date, but out app does. I have attached example code to demonstrate this issue. Run the app in Debug mode.

Attachments

FileDateSize
AlloyTestProjectMoment.zip2016-05-12T13:53:26.000+00008203637

Comments

  1. Angel Petkov 2016-05-31

    [~cthomas] Hello, thank you for reporting the issue. It's currently being looked in to, for the time being you can use Titanium.Locale to get the currentLocal and language, which should return the same values.
       Ti.API.info(Ti.Locale.currentLocale)
       
  2. Francois van Lille 2016-09-23

    I've found that it isn't worth the bother of trying to use the built-in distribution of moment if your app's distribution is likely to be in multiple locales and you won't have i18n translations onboard for all those locales. Instead, just head over to momentjs.com, download moment-with-locales.js and require it instead of the "alloy/moment" version... So in practice, I do the following in alloy.js:
       // in the require statement below "moment-with-locales" refers to app/lib/moment-with-locales.js, which I renamed from the moment-with-locales.min.js file downloaded from momentjs.com
       Alloy.Globals.Moment = require("moment-with-locales");
       Alloy.Globals.Moment.locale(Ti.Locale.currentLocale);
       
    And when I need to use it, simply use
       Alloy.Globals.Moment(oSomeDate).fromNow()
       
    or whatever...
  3. Alan Hutton 2019-11-14

    Unable to reproduce the issue. Axway Appcelerator Studio, build: 5.1.4.201909061933  macOS : 10.15 Node.js Version : 8.9.1 npm Version : 5.5.1 Appcelerator CLI : 7.1.1 Titanium CLI CLI Version : 5.2.1 node-appc Version : 0.2.49 Titanium SDKs : 8.2.1.GA

JSON Source