-
Notifications
You must be signed in to change notification settings - Fork 0
Support or document localization of messages and flags #63
Comments
Comment by kbknapp This is something I'm interested in doing, but it will take some thought on how to best go about this. I'm putting it on the issue tracker, but let's get some discussion going on ways about this! |
Comment by kbknapp @kamalmarhubi I was thinking about this today, and would the YAML feature allow this? I.e. I'm thinking having a differente yaml file for each translation, and depending on which language/translation is compiled via features, you pick a different yaml file. Example: # Cargo.toml
[features]
default = ["en_US"]
en_US = []
es_ES = [] # en_US.yml
name: My Application
version: 1.0
about: An example using many languages
author: Kevin K. <[email protected]>
args:
- opt:
help: an example option
short: o
long: option
multiple: true
takes_value: true
- pos:
help: example positional with possible values
index: 1
possible_values:
- fast
- slow # es_ES.yml
name: Mi Aplicacion
version: 1.0
about: Un ejamlo util muy idiomas
author: Kevin K. <[email protected]>
args:
- opt:
help: un ejamplo de un opcion
short: o
long: opcion
multiple: true
takes_value: true
- pos:
help: un ejamplo de un posicion con valores posible
index: 1
possible_values:
- rapido
- lento // main.rs
#[cfg(feature = "en_US")]
const TRANSLATION: &'static str = "en_US.yml";
#[cfg(feature = "es_ES"]
const TRANSLATION: &'static str = "es_ES.yml";
fn main() {
let yml = load_yaml!(TRANSLATION);
let m = App::from_yaml(yml).get_matches();
} Then depending on if you compile with |
Comment by kamalmarhubi
It's not me I'm thinking about, just something a user-facing system should allow for. :-) And as for the solution, it would be much better to allow the user's locale settings to dictate the language in help. Requiring users to compile the tool with their language is non-ideal. Hooking into gettext or l20n would be a nice approach, as there's tooling for people to work on translations, and they can live outside of the binary. |
Comment by kamalmarhubi Though I guess there's a question of whether the options should be translated, or just the help... which comes up in your example. Thanks for that by the way, concrete is always good to look at! |
Comment by joshtriplett I've never seen a program that translates long option names; those are API, much like the names of functions in a library. Translating the help is a great idea, though. I'd definitely agree with hooking into gettext, to work with the massive amount of translation infrastructure and tooling built around that, rather than creating a new translation format. |
Comment by hoodie I am currently trying to localize my app using crowbook-intl which is pretty nice. Unfortunately, the fact that |
Comment by kbknapp @hoodie the strings only need to live as long as the App instance, so long as the localized strings are owned somewhere it shouldn't be an issue. Can you paste some code that's giving issues and I can either see if there's a workaround or consider fixes if appropriate. |
Comment by hoodie infact you are right, it's just a bit tricky dealing with the lifetime constraints. I built so that app is immediately passed to a closure now. |
Comment by pksunkara This would also include localization of clap strings such |
Comment by alerque I've come very close to achieving a localized CLI interface using Clap & Fluent. However there are a couple points that are a bit hackish and could use some first class support. The main ugly bit about my solution is I have to parse args twice. I have a The most useful improvement I can see would be for the derive variant of Clap (formerly StructOpt), where the documentation strings are relied on. Adding top level support for a macro that would call a function to get strings rather than using the doc strings would allow both pretty and functional setup. |
Comment by kbknapp @alerque See #1880 and if something like that would fit your use case if we implement it.
This might be useful outside of i18n context. I'm imagining a
I personally think it might be a little too much to bite off on by the 3.0 release, but there isn't any reasons we couldn't address it post 3.0 as a feature to add if everything can be fleshed out and the complexity/maint burden isn't too high. |
Comment by alerque
No worries about the 3.0 release, I want to see that go out the door with the baked in derive stuff sooner rather than later. But of course I'd love to see a follow up with the tooling for localized interfaces. ¹ Thanks for the link to #1880, that is exactly what I've needed and was hacking up by hand and messing with lighter weight argp parsing crates to handle a first pass to extract things needed for a full instantiation with Clap. |
Comment by alerque The recent Rust 1.54.0 release includes a bit I think might have a huge impact on how hard this is to implement:
|
Comment by luojia65 Is it possible to read and use current operating system's working locale settings (languages, money unit, etc.) in clap generated help messages? For example, on given operating system, users use
|
Issue by kamalmarhubi
Tuesday Jan 12, 2016 at 16:57 GMT
Originally opened as clap-rs/clap#380
Make it easy for developers to support translations of their projects.
The text was updated successfully, but these errors were encountered: