Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-24312] Android: L() function not working in 6.0.1.GA but working as expected in 5.5.1.GA(Regression)

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2018-12-04T15:33:40.000+0000
Affected Version/sRelease 6.0.1
Fix Version/sn/a
Componentsn/a
Labelsn/a
ReporterNazmus Salahin
AssigneeUnknown
Created2017-01-16T13:35:04.000+0000
Updated2018-12-04T15:33:40.000+0000

Description

Hi, L() function not working on 6.0.1.GA but working as expected on 5.5.1.GA on android. Step to reproduce: 1. Create a test project. 2. Add the following code on app.js
Ti.UI.setBackgroundColor('white');
var win = Ti.UI.createWindow({
	title : 'Click window to test',
	backgroundColor : 'white',
	exitOnClose : true,
	fullscreen : false
});

win.open();

function L(text) {
	if (Ti.App.languageXML === undefined || Ti.App.languageXML === null) {
		var langFile = Ti.App.Properties.getString('last_lang'); 
		var file = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory,+langFile + '/string.xml'); 
		if (!file.exists()) {
			var langFile = "en"; // Fall back to english as the default
			file = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory,'lang/' + langFile + '/string.xml');
		}
		var xmltext = file.read().text;
		var xmldata = Titanium.XML.parseString(xmltext); // Parse the xml
		Ti.App.languageXML = xmldata; // Store the parsed xml so that we don't
										
	}

	// Get the localised string from xml file
	var xpath = "/resources/string[@name='" + text + "']/text()";
	Ti.API.info("PAROLE PATH: " + JSON.stringify(xpath));
	var result = Ti.App.languageXML.evaluate(xpath).item(0);

	if (result) {
		return result.text;
	} else {
		return text;// Return the text if localised version not found
	}
}

alert("MICRO: "+JSON.stringify(L('microscope')));

Ti.API.info("MICRO: "+JSON.stringify(L('microscope')));

win.open();
4. Add attached string.xml on i18n/en 5. Now build with 5.5.1.GA
[INFO] :   PAROLE PATH: "/resources/string[@name='microscope']/text()"
[INFO] :   MICRO: "MICROSCOPE"
6. Now build with 6.0.1.GA
[INFO] :   PAROLE PATH: "/resources/string[@name='microscope']/text()"
[INFO] :   MICRO: undefined

Attachments

FileDateSize
strings.xml2017-01-16T13:36:59.000+000016634

Comments

  1. Hans Knöchel 2017-01-16

    Hey [~nsalahin], am I missing something or why don't you store you language keys in i18n/en/strings.xml?
  2. Nazmus Salahin 2017-01-16

    Hi, I store language keys in i18n/en/strings.xml
  3. Hans Knöchel 2017-01-16

    Sorry, I don't get that. Why are you creating an own L() function to the one that already exists and handles all this? If you followed [this guide](https://wiki.appcelerator.org/display/guides2/Internationalization), the keys should work fine.

JSON Source