[TIMOB-4191] Locale.getString() produces exception when underscore is used in key arg AND hint arg is used AND key does not exist in strings.xml
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Low |
Status | Closed |
Resolution | Won't Do |
Resolution Date | 2020-01-09T19:03:07.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Android |
Labels | tbs-1.8.0 |
Reporter | Paul Dowsett |
Assignee | Ingo Muschenetz |
Created | 2011-05-23T16:48:16.000+0000 |
Updated | 2020-01-09T19:03:07.000+0000 |
Description
[Ti.Locale.getString()](http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Locale.getString-method.html) produces an exception when ALL of the following conditions are present:
* a underscores (or no-doubt other non-alphanumeric characters) are used in the key parameter, in the first argument of Ti.Locale.getString()
* the hint argument of Ti.Locale.getString() is used
* key does not exist in strings.xml
The following code demonstrates this:
var win1 = Ti.UI.createWindow({
backgroundColor:"red",
exitOnClose:true,
navBarHidden:false,
title:"Main Window"
});
win1.open();
Ti.API.info(L("info0","No translation available for info0")); // translation exists - produces correct translation
Ti.API.info(L("info_0","No translation available for info_0")); // translation exists - produces correct translation
Ti.API.info(L("info1","No translation available for info1")); // translation does not exist - produces hint message
Ti.API.info(L("info_1","No translation available for info_1")); // translation does not exist - produces exception followed by hint message
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<string name="info0">Hello0</string>
<string name="info_0">Hello_0</string>
</resources>
This results in the following output:
2364 TiAPI I (kroll$1: app://app.js) [198,597] Hello0
2364 TiAPI I (kroll$1: app://app.js) [2,599] Hello_0
2364 TiAPI I (kroll$1: app://app.js) [12,611] No translation available for info1
2364 ResourceType W Failure getting entry for 0x7f040002 (t=3 e=2) in package 0 (error -75)
2364 TitaniumModule E (kroll$1: app://app.js) [9,620] Exception trying to localize string 'info_1':
2364 TitaniumModule E android.content.res.Resources$NotFoundException: String resource ID #0x7f040002
2364 TitaniumModule E at android.content.res.Resources.getText(Resources.java:201)
2364 TitaniumModule E at android.content.res.Resources.getString(Resources.java:254)
2364 TitaniumModule E at android.content.Context.getString(Context.java:183)
2364 TitaniumModule E at ti.modules.titanium.TitaniumModule.localize(TitaniumModule.java:375)
2364 TitaniumModule E at ti.modules.titanium.TitaniumModuleBindingGen$8.invoke(TitaniumModuleBindingGen.java:379)
2364 TitaniumModule E at org.appcelerator.kroll.KrollProxy$ThisMethod.invoke(KrollProxy.java:397)
2364 TitaniumModule E at org.appcelerator.kroll.KrollMethod.call(KrollMethod.java:51)
2364 TitaniumModule E at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1701)
2364 TitaniumModule E at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:854)
2364 TitaniumModule E at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:164)
2364 TitaniumModule E at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:426)
2364 TitaniumModule E at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3177)
2364 TitaniumModule E at org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:175)
2364 TitaniumModule E at org.mozilla.javascript.Context.evaluateReader(Context.java:1142)
2364 TitaniumModule E at org.appcelerator.titanium.kroll.KrollContext$DefaultEvaluator.evaluateFile(KrollContext.java:105)
2364 TitaniumModule E at org.appcelerator.titanium.kroll.KrollContext.evaluateScript(KrollContext.java:306)
2364 TitaniumModule E at org.appcelerator.titanium.kroll.KrollContext.handleEvalFile(KrollContext.java:318)
2364 TitaniumModule E at org.appcelerator.titanium.kroll.KrollContext.handleMessage(KrollContext.java:217)
2364 TitaniumModule E at org.appcelerator.titanium.TiMessageQueue.handleMessage(TiMessageQueue.java:223)
2364 TitaniumModule E at android.os.Handler.dispatchMessage(Handler.java:95)
2364 TitaniumModule E at android.os.Looper.loop(Looper.java:123)
2364 TitaniumModule E at org.appcelerator.titanium.kroll.KrollHandlerThread.run(KrollHandlerThread.java:86)
2364 TiAPI I (kroll$1: app://app.js) [24,644] No translation available for info_1
A nice workaround solution for this buggy XML based Localization in Titanium is at https://github.com/mattheworiordan/json.i18n-for-Titanium-Mobile. JSON based, and does not suffer from the same issues as the Titanium library.
It has been decided that this issue should be closed as “Won’t do.” This issue is out of date with our current supported SDK release (7.5.2.GA as of the date of closure), and out of date with mobile OS versions. Updating, or creating code may not reproduce the issue reported, or be a valid test case. If community members feel that the issue is still valid, please create a new ticket. Please reference this closed ticket number, include SDK used, comments, and code that demonstrates/reproduces the issue.