Introducing ti-i18n

Alloy has an badly documented extract-i18n command to extract keys from L() and Ti.Locale.getString() calls in TSS and JS source files. This command will be deprecated soon as Appcelerator wants to keep their CLI’s lean and mean. The upcoming 3.2 version of the Titanium CLI will introduce hooks so the community can add and support supplementary functions instead.

Both stand-alone and hook

I’ve just published a NPM package that does exactly the same as alloy extract-i18n, but which will be extended soon with more features for both Alloy and Classic projects. You can install ti-i18n over NPM:

It can run stand-alone, but also hook itself into the new Titanium CLI:

How to hook a command?

Want to hook into the new Titanium CLI yourself? Simply add the directory that contains one or more custom commands to the paths.commands config like this:

As you can see in ti-i18n’s module.js around line 95, this is exactly what I do when you call ti-i18n hook.

How to write a command?

The names of the files in the folder you add will be available as commands under ti <command>. Each file needs to export a title and description property as well as a config and run method. Take a look at ti-i18n’s hooks/i18n.js to see how that looks. For ti-i18n, the file reads the actual subcommands, args, options and flags from module.js.

How to combine both stand-alone and hook?

The entry-point for the stand-alone version of ti-i18n is cli.js. As you can see it uses the popular commander seen in TiShadow and the Alloy CLI. Again, it reads the actual configuration from module.js, but since that uses the format for Titanium CLI hooks, it parses that to instructions for the commander program. This way, I keep my configuration DRY. I should probably write up a separate module for this so you can too :)