Skip to content
Browse files

Locale configuration/selection from command line.

  • Loading branch information...
1 parent f435d8d commit 11b82bf2500b43904cba6ded06322d787e7016a9 @dbankier committed Aug 6, 2012
View
16 README.md
@@ -181,7 +181,7 @@ Testing / Assertions
TiShadow now support [Jasmine](http://pivotal.github.com/jasmine/) BDD tests.
Insipration taken from these two projects: [titanium-jasmine](https://github.com/guilhermechapiewski/titanium-jasmine/) and [jasmine-titanium](https://github.com/akahigeg/jasmine-titanium)
-Include your specs in the `Resources/specs` path of your project. Ensure
+Include your specs in the `Resources/spec` path of your project. Ensure
the files are ending in `_spec.js`. (Note: simply write the spec without any including/requiring the jasmine library.)
To execute the tests enter the following command:
@@ -225,6 +225,20 @@ Also the equivalent not assertions are available as well, e.g.
'notEqual', 'isNotString', 'isNotNumber', etc.
+Configurable Localisation
+-------------------------
+TiShadow now supports localisation. You can also chose the locale locale
+you wish to execute when launch your app/tests. Simply add the
+two-letter language code to your command. For example:
+
+```bash
+ tishadow en
+ tishadow update es
+ tishadow spec nl
+ tishadow spec update es
+```
+
+
Launch From Web
---------------
View
8 app/Resources/api/Localisation.js
@@ -1,13 +1,13 @@
var log = require("/api/Log");
var TiShadow = require("/api/TiShadow");
-var locale = Titanium.Locale.getCurrentLanguage();
+exports.locale = Titanium.Locale.getCurrentLanguage();
var lookup = null;
function loadFile() {
lookup = {};
- var file = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory + TiShadow.currentApp + "/" + locale + "/strings.xml");
+ var file = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory + TiShadow.currentApp + "/" + exports.locale + "/strings.xml");
if (!file.exists()) {
- log.warn(Ti.Filesystem.applicationDataDirectory + TiShadow.currentApp + "/" + locale + "/strings.xml");
- log.warn("Language file for '" + locale + "' does not exist");
+ log.warn(Ti.Filesystem.applicationDataDirectory + TiShadow.currentApp + "/" + exports.locale + "/strings.xml");
+ log.warn("Language file for '" + exports.locale + "' does not exist");
return;
}
var xml_string = file.read().text;
View
3 app/Resources/api/TiShadow.js
@@ -79,6 +79,9 @@ function loadRemoteZip(name, url, spec) {
}
Ti.App.addEventListener("tishadow:bundle", function(o) {
+ if(o.locale) {
+ require("/api/Localisation").locale = o.locale;
+ }
loadRemoteZip(o.name, "http://" + Ti.App.Properties.getString("address") + ":3000/bundle", o.spec);
});
View
6 example/Resources/app.js
@@ -4,13 +4,13 @@ var win = Ti.UI.createWindow({
exitOnClose: true
});
var label = Ti.UI.createLabel({
- text: 'Hello, World!',
- color: '#000',
+ text: L("hello.world") + "!",
+ color: 'red',
font: {
fontSize: 32,
fontWeight: 'bold'
}
});
win.add(label);
-win.open();
+win.open();
View
4 example/i18n/en/strings.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<resources>
+ <string name="hello.world">Hello World</string>
+</resources>
View
4 example/i18n/es/strings.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<resources>
+ <string name="hello.world">hola mundo</string>
+</resources>
View
2 server/app.js
@@ -40,7 +40,7 @@ app.post('/', function(req, res) {
var name = path.basename(req.body.bundle).replace(".zip","");
Logger.log("INFO", null, "New Bundle: " + req.body.bundle + " | " + name);
bundle = req.body.bundle;
- sio.sockets.emit("bundle", {name: name, spec: req.body.spec});
+ sio.sockets.emit("bundle", {name: name, spec: req.body.spec, locale: req.body.locale});
res.send("OK", 200);
});
app.post('/clear_cache', function(req,res) {
View
7 server/bin/support/api.js
@@ -26,9 +26,8 @@ function postToServer(path, data) {
exports.clearCache = function() {
postToServer("/clear_cache");
-}
+};
exports.newBundle = function(data) {
- postToServer("/", {bundle:config.bundle_file, spec: config.isSpec});
-
-}
+ postToServer("/", {bundle:config.bundle_file, spec: config.isSpec, locale: config.locale});
+};
View
8 server/bin/support/config.js
@@ -32,6 +32,14 @@ config.init = function(callback) {
config.isUpdate = process.argv[2] === "update" || process.argv[3] === "update";
config.isSpec = process.argv[2] === "spec";
+ if (!config.isUpdate && !config.isSpec) {
+ config.locale = process.argv[2];
+ } else if (config.isSpec && config.isUpdate) {
+ config.locale = process.argv[4];
+ } else {
+ config.locale = process.argv[3];
+ }
+
callback();
});
}
View
3 server/bin/tishadow
@@ -62,7 +62,7 @@ if (cmd === "server") {
file_list = fs.getList(config.resources_path,last_stat.mtime);
i18n_list = fs.getList(config.i18n_path,last_stat.mtime);
- if (file_list.files.length === 0 || i18n_list.files.length === 0) {
+ if (file_list.files.length === 0 && i18n_list.files.length === 0) {
console.log("Nothing to update.");
process.exit();
}
@@ -92,7 +92,6 @@ if (cmd === "server") {
});
i18n_list.files.forEach(function(file, idx) {
- console.log(path.join(config.i18n_path,file) + " ==> " + path.join(config.tishadow_src, file));
util.pump(fs.createReadStream(path.join(config.i18n_path,file)),fs.createWriteStream(path.join(config.tishadow_src, file)));
});

0 comments on commit 11b82bf

Please sign in to comment.
Something went wrong with that request. Please try again.