{ "id": "141578", "key": "ALOY-1204", "fields": { "issuetype": { "id": "4", "description": "An improvement or enhancement to an existing feature or task.", "name": "Improvement", "subtask": false }, "project": { "id": "11113", "key": "ALOY", "name": "Alloy", "projectCategory": { "id": "10400", "description": "Tools for developing applications", "name": "Tooling" } }, "fixVersions": [], "resolution": { "id": "7", "description": "", "name": "Invalid" }, "resolutiondate": "2014-12-17T17:05:37.000+0000", "created": "2014-12-15T08:48:32.000+0000", "priority": null, "labels": [ "i18n" ], "versions": [], "issuelinks": [], "assignee": { "name": "skypanther", "key": "skypanther", "displayName": "Tim Poulsen", "active": true, "timeZone": "America/New_York" }, "updated": "2018-03-07T22:28:28.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "14203", "name": "I18N", "description": "Internationalization" } ], "description": "You can't override *L*, but you can override *Ti.Locale.getString*.\r\nHere's an example in the alloy.js :\r\n\r\n{code:javascript}\r\nvar getString = Ti.Locale.getString;\r\nTi.Locale.getString = function() {\r\n return '@' + getString.apply(this, arguments) + '@';\r\n};\r\n{code}\r\n\r\nNow a little strings.xml :\r\n\r\n{code:xml}\r\n\r\n\r\n I am test 1\r\n I am test 2\r\n I am test 3\r\n\r\n{code}\r\n\r\nAn now a simple view :\r\n\r\n{code:xml}\r\n\r\n \r\n \r\n\r\n{code}\r\n\r\nThe output of this views will be : \r\n\r\n{code}\r\n@I am test 1@\r\n@I am test 2@\r\nI am test 3\r\n{code}\r\n\r\nWhen you use an id attribute in a view (textid, titleid, etc ...), it doesn't call *Ti.Locale.getString*. So you can't override completely the behavior of L.", "attachment": [], "flagged": false, "summary": "Override L behavior and id attributes in views", "creator": { "name": "dreignier", "key": "dreignier", "displayName": "David Reignier", "active": true, "timeZone": "Europe/Berlin" }, "subtasks": [], "reporter": { "name": "sliang", "key": "sliang", "displayName": "Shuo Liang", "active": true, "timeZone": "Asia/Harbin" }, "environment": "Windows 7\r\nTitanium Studio 3.4.1.201410281727\r\n", "comment": { "comments": [ { "id": "336788", "author": { "name": "skypanther", "key": "skypanther", "displayName": "Tim Poulsen", "active": true, "timeZone": "America/New_York" }, "body": "The fact that you can do this at all in Alloy must be a quirk of Alloy. This Classic example demonstrates that you cannot extend Ti.Locale.getString() outside of Alloy.\r\n\r\n{code}\r\nvar win = Ti.UI.createWindow({\r\n layout:'vertical',\r\n backgroundColor: 'white'\r\n});\r\n\r\nvar getString = Ti.Locale.getString;\r\nTi.Locale.getString = function() {\r\n\tconsole.log('extending getString');\r\n return '@' + getString.apply(this, arguments) + '@';\r\n};\r\n\r\nwin.add(Ti.UI.createLabel({\r\n\ttop: 20,\r\n\ttext: Ti.Locale.getString('lbl1')\r\n}));\r\nwin.add(Ti.UI.createLabel({\r\n\ttop: 10,\r\n\ttext: L('lbl2')\r\n}));\r\nwin.add(Ti.UI.createLabel({\r\n\ttop: 10,\r\n\ttextid: 'lbl3'\r\n}));\r\n\r\nwin.open();\r\n{code}\r\n\r\n{code}\r\n\r\n\r\n Label 1\r\n Label 2\r\n Label 3\r\n\r\n{code}\r\n\r\nThe app shows three labels with the text Label 1, Label 2, and Label 3.\r\n\r\nOur guides specifically say [don't extend the Titanium proxies|http://docs.appcelerator.com/titanium/latest/#!/guide/Coding_Best_Practices-section-30082362_CodingBestPractices-Don%27tExtendTitaniumPrototypes]. The best way to override Ti.Locale.getString is to wrap it in a helper function. Something like:\r\n\r\n{code:title=localehelper.js}\r\nexports.getString = function(key) {\r\n\tif(typeof key === 'string') {\r\n\t\treturn \"@\" + Ti.Locale.getString(key) + \"@\";\r\n\t}\r\n\treturn '';\r\n}\r\n{code}\r\n\r\n{code:title=app.js}\r\nvar getString = require('localehelper').getString;\r\n\r\nwin.add(Ti.UI.createLabel({\r\n\ttop: 20,\r\n\ttext: getString('lbl1')\r\n}));\r\n{code}", "updateAuthor": { "name": "skypanther", "key": "skypanther", "displayName": "Tim Poulsen", "active": true, "timeZone": "America/New_York" }, "created": "2014-12-17T17:03:32.000+0000", "updated": "2014-12-17T17:03:32.000+0000" }, { "id": "336789", "author": { "name": "skypanther", "key": "skypanther", "displayName": "Tim Poulsen", "active": true, "timeZone": "America/New_York" }, "body": "Goes against best practices. Proper technique demonstrated in the comment.", "updateAuthor": { "name": "skypanther", "key": "skypanther", "displayName": "Tim Poulsen", "active": true, "timeZone": "America/New_York" }, "created": "2014-12-17T17:04:07.000+0000", "updated": "2014-12-17T17:04:07.000+0000" }, { "id": "336790", "author": { "name": "skypanther", "key": "skypanther", "displayName": "Tim Poulsen", "active": true, "timeZone": "America/New_York" }, "body": "Reopening to change resolution type", "updateAuthor": { "name": "skypanther", "key": "skypanther", "displayName": "Tim Poulsen", "active": true, "timeZone": "America/New_York" }, "created": "2014-12-17T17:05:29.000+0000", "updated": "2014-12-17T17:05:29.000+0000" }, { "id": "435355", "author": { "name": "emerriman", "key": "emerriman", "displayName": "Eric Merriman ", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Closing as invalid. If this is incorrect, please reopen.", "updateAuthor": { "name": "emerriman", "key": "emerriman", "displayName": "Eric Merriman ", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2018-03-07T22:28:28.000+0000", "updated": "2018-03-07T22:28:28.000+0000" } ], "maxResults": 4, "total": 4, "startAt": 0 } } }