-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support multiple languages #125
Conversation
ce7c8ce
to
68f9fca
Compare
Okay, so I did some research and I think querying the While developing, I recognized, that some test data was outdated, so I fixed that in one commit (I also opened #126 for tracking). (EDIT: this commit was moved to #128) Greetings |
Great, thanks @niklasmohrin for your contribution! Expectation management: I hope to review this soon, but can't promise any date since there are already a few other open PRs on my TODO list. Also, currently I have to take advantage of the nice summer weather to hike and paraglide during my free days 😄 In any case, if I don't review this in the next 2-3 weeks, feel free to ping me! Also, reviews by other people are always welcome and helpful. |
68f9fca
to
22b4c73
Compare
22b4c73
to
cbf9104
Compare
c6ad95d
to
69e4208
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finally got around to review this! Here's the first round of feedback 🙂
src/main.rs
Outdated
@@ -407,6 +409,38 @@ fn main() { | |||
process::exit(0); | |||
} | |||
|
|||
// Language list according to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code would probably benefit from being moved into a dedicated function (get_language_list
). That would also be a nice target for a few unit tests (containing at least the examples from the spec).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added some tests in main.rs
. Since I didn't find a sane way to mock environment variables, I constructed the get_languages
function around the environments variables and kept the logic around the --language
flag out of it. Instead, this is handled in main
.
Let me know what you think and what other tests you want to see
73d8031
to
72d0e8d
Compare
@@ -290,6 +293,46 @@ fn get_os() -> OsType { | |||
OsType::Other | |||
} | |||
|
|||
fn get_languages( | |||
env_lang: Result<String, std::env::VarError>, | |||
env_language: Result<String, std::env::VarError>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to self: Use Option
instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, an Option<String>
would be better!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @niklasmohrin, sorry for the long delay (again)! There are a few optimizations I'd like to see (I think some of the code has potential for reducing the amount of string creation / heap allocations), but the code seems to be correct, easy to read and well tested.
I'll merge it for now and will do adjustments myself, to avoid another long ping-pong with me not being as responsive as I'd like to 🙂
Thanks for your contribution!
@@ -290,6 +293,46 @@ fn get_os() -> OsType { | |||
OsType::Other | |||
} | |||
|
|||
fn get_languages( | |||
env_lang: Result<String, std::env::VarError>, | |||
env_language: Result<String, std::env::VarError>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, an Option<String>
would be better!
The implementation follows the tldr-pages client spec: https://github.com/tldr-pages/tldr/blob/master/CLIENT-SPECIFICATION.md#language Fixes #96
Rebased and merged in 1db4b40! |
…extra _files args (#168) - Use array `commands=(...)` and `_describe` to deal with '[.md' & empty cache scenario. Fixes #166 - Hide `tldr --list` stderr (`2>/dev/null`) which breaks completion with empty cache - Remove `sed` since #112 changed commas to newlines - Add new `sed`-equivalent replacement (`:` -> `\:`) using native [ZSH `${name//pattern/repl}`](http://zsh.sourceforge.net/Doc/Release/Expansion.html#Parameter-Expansion) since colon is special character in ZSH completions - Add basic support for `-L, --language` flag from #125. In future, can consider adding extra completions maybe based on caches `pages.{lang}` folders. - Remove extraneous completion of file names for positional arguments (i.e. `'*:file:_files'`)
Fixes #96, fixes #126
Hey everybody! This is the first time I am contributing to a rust project, so please don't refrain from commenting.
I only started working on this and its not ready yet, but I wanted to open the draft to open the comment thread. I think the basic control flow is pretty close to how it will be implemented in the final version. I have not read about the standards for the
LANG
andLANGUAGE
environment variables yet. I saw that there is the env-lang crate to parse theLANG
variable, so I might use this.Should I
cargo fmt
the files that I am editing in a final commit after all the others?Let me know what you think