-
-
Notifications
You must be signed in to change notification settings - Fork 629
[Project Fluent] Basic internationalization support (would close PR #2553) #2674
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
base: main
Are you sure you want to change the base?
[Project Fluent] Basic internationalization support (would close PR #2553) #2674
Conversation
ab56d20
to
3edb09c
Compare
@@ -54,7 +54,11 @@ fn render_not_found(subcommand: &str, bin: &str) -> StyledStr { | |||
let _ = write!(output, "{error}error:{error:#} "); | |||
let _ = write!( | |||
output, | |||
"unrecognized subcommand '{invalid}{subcommand}{invalid:#}' " | |||
"{} ", |
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 is an awkward example but maybe helps show where extra steps are required (e.g. a simple non-literal/const string would be wrapped by t!(..)
and done)
description = "macro library for atuin" | ||
|
||
rust-version = { workspace = true } | ||
version = "18.5.0-beta.2" |
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.
TODO: this seems to be a cargo-i18n issue that it cannot accept non-literal versions.
That said, running cargo i18n
doesn't actually seem to be necessary.
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.
But might need an upstream change in cargo-i18n to fix :/
3edb09c
to
7ea4f77
Compare
This pull request has been mentioned on Atuin Community. There might be relevant details there: |
@@ -4,7 +4,7 @@ edition = "2024" | |||
description = "client library for atuin" | |||
|
|||
rust-version = { workspace = true } | |||
version = { workspace = true } | |||
version = "18.5.0-beta.2" |
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.
(see below: if it is not easy to address the cargo-i18n
issue then I'm fairly sure we can ignore it - either way will restore these before merge)
7ea4f77
to
b4cdb63
Compare
# source code for gettext system, and the primary fallback language | ||
# (for which all strings must be present) when using the fluent | ||
# system. | ||
fallback_language = "en-US" |
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.
part of me would love to force en-GB 😏
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'll be honest, it was en-GB until a commit or two ago, so ... :D
That said, it may be an gentle way to encourage a wide sample, as more people will spot that is falling back to -ise spellings instead of correctly picking up US locales, than the other way around 🤔
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.
generally pretty happy with the direction here - thanks for taking it on!
use slugify::slugify; | ||
|
||
#[proc_macro] | ||
pub fn tl(tokens: TokenStream) -> TokenStream { |
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've generally been pretty against macros in our codebase but in this case I think it makes sense
obv this is just a draft but for the final version I'd really appreciate it if you could thoroughly document what's going on with the code here, just to make it as approachable as possible for future contributors! 🙏
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.
Of course - will do! This was the main point against fluent-rs, alongside activity, as their macro (for conceptual reasons) requires slug-strings in the codebase rather than human readable ones, so using it means one of:
- a wrapper macro to go from human-readable to slugs
- switching all translatable strings to slugs
- another idea I had not thought of
2 has the downside of making things like making UI bugs harder to see in reviews, and grepping for error messages harder, as well as more visual change to existing code when making strings translatable, so I thought that was probably too much friction. On the other hand, as mentioned, 1 adds custom magical machinery, a new macro module, and somewhat undermines fluent's own differentiating motivation from gettext (although, of course, it is still possible to use it in the intended way on a case-by-case basis).
However, one other benefit of fluent is that it is a standard and seems to be supported by (for example) Weblate - it might even be possible to get a free instance on their libre-project plan, if desired.
Alternative approach to #2553. Not closing that just yet, but keen for feedback either way.
After thinking about the discussion on the Forum, the biggest challenge is that a lot of small changes brings risk. This is a suggestion:
Suggestion: tidy-up, PR and merge this to provide i18n support. Once that is in a release and there is no negative feedback and folks confirm that the single example works OK, then PR 2., which is roughly the minimal set of common translatable strings. Less than that, and there's too much English leaking through to get buy-in, any more and the PR is oversized.
NB: there is a commit in 2. with English translations - note that it covers the full set of changes in 3. so most of them can be ignored in the near-term (happy to split it in two parts - one for 2. and one for 3.).
This PR does not add any translatable strings except one. Changes 2. and 3. only translate the crates
atuin-common
andatuin-client
, plusinspector.rs
andinteractive.rs
in theatuin
crate.How to test
This PR has only one translatable string, to make sure it works and breaks nothing, as the main challenge is to get the machinery in without regressions. However, using https://github.com/philtweir/fork-atuin/tree/feature/i18n-support-fluent-basic, you can build and take the interactive search as a minimal test.
In this PR, the only visible change should be:
vs
How translatability is implemented
Adding
t!(...)
everywhere appropriate, in some places accounting for static return values, and then progressively adding translations to*.flt
files as people wish to (separately) PR.Notes
t!(...)
can take arguments (e.g. translate%{time} ago
) it does not return&'static str
so, for FilterMode, I usedlazy_static
and elsewhere, switched toString
or otherwise worked-around.cargo-i18n
docs) - this means a newatuin_macro
package (if this is a hard no, please say and I will try new ideas!)./i18n
folder (this has a side-benefit/downside that the same string will be translated the same way in all crates)Checks