Bugzilla – Bug 8752
Add "getstring" CLI command
Last modified: 2009-09-08 09:12:35 UTC
I would like to see a "translate" CLI command that takes string code (as from strings.txt) as an input and returns the localized string. This would greatly enhance the capability to build interfaces from JavaScript or native interfaces since you don't have to go through TT and pre-store values and you don't have to know upfront what your string codes would be. One example: in iPeng I have a scanner page that shows progress on the database scan. I have to pre-store all "XXX_PROGRESS" values there even though XXX is something returned by the CLI so with this command I could just construct the XXX_PROGRESS identifier and get the string value. This would be useful for any 3rd party controller app plus for the Default skin and Jive I suppose.
Ah... forgot to submit this request myself. Could come in handy in some web skins, too. Let's discuss some more ideas: what about a "batch" mode, where you can get several translations at once? eg. getstring BRIGHTNESS getstring BRIGHTNESS:Helligkeit getstring HOME,INFORMATION,EDIT getstring HOME:Hauptmenü,INFORMATION:Information,EDIT:Bearbeiten Hmm... I'll have to check the CLI specs to see how this could best be done.
changing summary to better fit the internal command
Created attachment 3635 [details] "getstring" CLI command getstring HOME,PLUGIN_RANDOMPLAY,SOME_TOKEN Please give it a try and let me know whether this does what you're looking for.
Can I apply this to a "build" version of the server or do I have to use a SVN version? If it's the latter I'll try tomorrow. But looks good and I like the "batch" mode. How are the results encoded? Just asking because of Erland's "%"-issue.
If you have a patch tool you can apply it to any version. Otherwise it's simple enough to just copy the content into the corresponding files. Just remove the leading + signs.
OK, tried it, and it's about what I'm looking for. If it can translate, it translates -> good If it cannot, it returns the tag -> good It returns the result in a hash -> good It works with plugins -> good But the "batch mode" doesn't seem to work, at least with JSON/RPC. I can hand over several parameter but only the first one gets returned. -> bad. I'll add a bit of logging. [08-07-22 00:56:55.1396] Slim::Web::JSONRPC::handleURI (73) handleURI(Slim::Web::HTTP::ClientConn=GLOB(0x68faef4)) [08-07-22 00:56:55.1400] Slim::Web::JSONRPC::handleURI (108) POST data: [{"id": 1, "method": "slim.request", "params": ["01:01:01:01:01:01", ["getstring", "MUSICIP_PROGRESS", "IPENG_WEEKDAY_SEL", "MUSTBEINVALID", "SLEEPING_IN_X_MINUTES"]]}] [08-07-22 00:56:55.1449] Slim::Web::JSONRPC::handleURI (126) JSON parsed procedure: { id => 1, method => "slim.request", params => [ "01:01:01:01:01:01", [ "getstring", "MUSICIP_PROGRESS", "IPENG_WEEKDAY_SEL", "MUSTBEINVALID", "SLEEPING_IN_X_MINUTES", ], ], } [08-07-22 00:56:55.1457] Slim::Web::JSONRPC::requestMethod (308) requestMethod([ "01:01:01:01:01:01", [ "getstring", "MUSICIP_PROGRESS", "IPENG_WEEKDAY_SEL", "MUSTBEINVALID", "SLEEPING_IN_X_MINUTES", ], ]) [08-07-22 00:56:55.1478] Slim::Web::JSONRPC::requestMethod (330) Parsing command: Found client [01:01:01:01:01:01] [08-07-22 00:56:55.1523] Slim::Web::JSONRPC::requestMethod (352) Dispatching... [08-07-22 00:56:55.1528] Slim::Web::JSONRPC::requestWrite (398) requestWrite() [08-07-22 00:56:55.1531] Slim::Web::JSONRPC::generateJSONResponse (278) generateJSONResponse() [08-07-22 00:56:55.1542] Slim::Web::JSONRPC::writeResponse (224) JSON response: { id => 1, method => "slim.request", params => [ "01:01:01:01:01:01", [ "getstring", "MUSICIP_PROGRESS", "IPENG_WEEKDAY_SEL", "MUSTBEINVALID", "SLEEPING_IN_X_MINUTES", ], ], result => { # tied Tie::IxHash MUSICIP_PROGRESS => "MusicIP Import", }, } [08-07-22 00:56:55.1545] Slim::Web::JSONRPC::writeResponse (237) JSON raw response: [{"params":["01:01:01:01:01:01",["getstring","MUSICIP_PROGRESS","IPENG_WEEKDAY_SEL","MUSTBEINVALID","SLEEPING_IN_X_MINUTES"]],"method":"slim.request","id":"1","result":{"MUSICIP_PROGRESS":"MusicIP Import"}}]
you'll have to send the tokens as one string. Probably a bit confusing... [ "getstring", "MUSICIP_PROGRESS,IPENG_WEEKDAY_SEL,SLEEPING_IN_X_MINUTES", ],
OK, works fine then. Wouldn't it be simpler to use separate parameters? I mean: from an application point of view: I don't really care if I have to concatenate strings or arrays but all the other CLI commands use separate parameters. Or would that become to many of those? The return hashes separate them, too, in the end (which is the important point)
Thanks for the feedback. The current implementation imho is very simple and easy, not only to do the queries manually, but programmatically too. JSON responses result in a hash indexed by the tags. I don't see any advantage splitting the parameters into separate values, but clearly it would be more complicated to use.
change 21980
Verified with SqueezeCenter Version: 7.2 - 22900
This bug has been fixed in the 7.3.0 release version of SqueezeCenter! Please download the new version from http://www.slimdevices.com/su_downloads.html if you haven't already. If you are still experiencing this problem, feel free to reopen the bug with your new comments and we'll have another look.
Reduce number of active targets for SC