This is a little script I wrote to automatically scour a git repo's source code and extract i18n strings.
It searches specifically for gettext-style __()
calls, which happen to be used by @mashpie's i18n-node and @jeresig's i18n-node-2 (which I'm using), but which are also used by other tools.
It searches for these strings in a pretty liberal way that works with JavaScript, CoffeeScript, and probably most other similar languages: it just looks for (non-word character), __
, either (
or whitespace, followed by a single- or double-quoted string.
It takes these strings and updates a JSON file with them, showing you strings that have been added and removed since the last run. This JSON format is the same as used by the above mentioned modules and others, so there should be no conflicts.
Example run:
$ ./scripts/i18n._coffee
Reading current strings...
31 current strings found.
Searching files for strings...
14 matching files found.
Extracting strings from files...
32 total strings found.
3 strings added:
- Log In
- Log in
- Log Out
2 strings removed:
- Login
- Logout
This tool probably isn't perfect, but it gives me peace of mind knowing that forgetting a code path will no longer mean missed strings. It doesn't have to replace the runtime updating of these tools; it supplements them nicely.
This tool is written in Streamline syntax, but the only async part (besides the file I/O, which doesn't have to be) is the call to git. You could easily rewrite this without Streamline if you just wrap the rest in a function and pass that as a callback to exec()
.
Feedback welcome! If you try this out, let me know how you like it. Cheers.
It seems like you only check for single quoted string matches in line 74, I think to also work with double quoted string, the line needs to be adjusted to: