[TIMOB-24312] Android: L() function not working in 6.0.1.GA but working as expected in 5.5.1.GA(Regression)
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2018-12-04T15:33:40.000+0000 |
Affected Version/s | Release 6.0.1 |
Fix Version/s | n/a |
Components | n/a |
Labels | n/a |
Reporter | Nazmus Salahin |
Assignee | Unknown |
Created | 2017-01-16T13:35:04.000+0000 |
Updated | 2018-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
File | Date | Size |
---|---|---|
strings.xml | 2017-01-16T13:36:59.000+0000 | 16634 |
Hey [~nsalahin], am I missing something or why don't you store you language keys in i18n/en/strings.xml?
Hi, I store language keys in i18n/en/strings.xml
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.