Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-12161] Android: Localization of string names with '.'

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionFixed
Resolution Date2013-08-26T23:28:47.000+0000
Affected Version/sn/a
Fix Version/s2013 Sprint 18, 2013 Sprint 18 API, Release 3.2.0
ComponentsAndroid
Labelsandroid, localization
ReporterDavid Bankier
AssigneeHieu Pham
Created2012-12-27T05:58:46.000+0000
Updated2014-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);

Comments

  1. Hieu Pham 2013-08-21

    master PR: https://github.com/appcelerator/titanium_mobile/pull/4589
  2. Samuel Dowse 2013-11-14

    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.
  3. Michael Kåring 2014-10-10

    where and how do you redefine the L function as shown in the example?

JSON Source