[TIMOB-12161] Android: Localization of string names with '.'
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | n/a |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2013-08-26T23:28:47.000+0000 |
Affected Version/s | n/a |
Fix Version/s | 2013 Sprint 18, 2013 Sprint 18 API, Release 3.2.0 |
Components | Android |
Labels | android, localization |
Reporter | David Bankier |
Assignee | Hieu Pham |
Created | 2012-12-27T05:58:46.000+0000 |
Updated | 2014-10-10T08:56:08.000+0000 |
Description
*Issue*
It is known that the strings.xml file is less flexible in Android as it is used to generate the R.java file. (E.g. a build will fail if a string name starts with an integer or includes a '+', etc.)
The above stated, if a string name includes a '.' character, a build will succeed but replace the '.' characters with '_'.
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<string name="my.value">Hello World</string>
</resources>
Since the replacement is silent, the dev is unaware of the change so the following will not work.
alert(L("my.value"});
*Temporary Work Around*
For large code bases that cannot change the naming convention, the L function can be redefined, e.g.:
(function(object) {
if (exports.osname ==="android") {
object.L = function(lookup, defaults) {
return Ti.Locale.getString(lookup.replace(/\./g,"_"), defaults);
};
}
})(this);
master PR: https://github.com/appcelerator/titanium_mobile/pull/4589
Verified Fixed on: Mac OSX 10.9 Mavericks Titanium Studio, build: 3.2.0.201311140700 Titanium SDK, build: 3.2.0.v20131113183932 CLI: 3.2.0 Alloy: 1.3.0 Android Simulator: 2.3.3, 4.4 Localization string my.value was picked up and displayed on screen using the above code. Closing.
where and how do you redefine the L function as shown in the example?