-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
uucore: add functions to manage translations #7955
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?
Conversation
572c58e
to
3551c6f
Compare
GNU testsuite comparison:
|
GNU testsuite comparison:
|
GNU testsuite comparison:
|
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.
Pull Request Overview
This PR adds new functions and structures to manage localization and translations in the uucore package. Key changes include:
- Introduction of the locale module with functionality to initialize localization, load Fluent bundles, and retrieve localized messages.
- Updates to mod files and Cargo.toml to expose the new locale module and add necessary Fluent dependencies.
- Modifications to configuration files (deny.toml and VSCode wordlist) to support the new dependencies.
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
src/uucore/src/lib/mods/locale.rs | New localization functionality with resource loading and message formatting functions. |
src/uucore/src/lib/mods.rs | Locale module exposed. |
src/uucore/src/lib/lib.rs | Locale module publicly re-exported. |
src/uucore/Cargo.toml | Dependency changes for Fluent and related crates. |
deny.toml | Updated dependency skips relevant to Fluent usage. |
Cargo.toml | Added Fluent dependencies. |
.vscode/cspell.dictionaries/workspace.wordlist.txt | Updated wordlist for new terminology. |
Comments suppressed due to low confidence (1)
src/uucore/src/lib/mods/locale.rs:229
- [nitpick] The parameter name 'rustc_args' may be misleading since the function works with Fluent arguments for localization. Consider renaming it to 'args' or 'fluent_args' to better reflect its purpose.
rustc_args: HashMap<String, String>,
GNU testsuite comparison:
|
793d4e0
to
fc17288
Compare
let locale_path = config.get_locale_path(&try_locale); | ||
tried_paths.push(locale_path.clone()); | ||
|
||
if let Ok(ftl_string) = fs::read_to_string(&locale_path) { |
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.
What does ftl
mean?
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.
fluent
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.
in the wrong order
loaded = true; | ||
break; |
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.
Instead of a break
you could do an early return. It would make the loaded
variable obsolete.
GNU testsuite comparison:
|
Ok(bundle) | ||
} | ||
|
||
fn get_message_internal(id: &str, args: Option<FluentArgs>, default: &str) -> String { |
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 think it should be Never mind, my advice is incorrect, though I'm still not completely happy with the function name.get_internal_message
.
/// ``` | ||
pub fn get_message_with_args( | ||
id: &str, | ||
rustc_args: HashMap<String, String>, |
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 don't understand why it is prefixed with rustc
.
let mut args = FluentArgs::new(); | ||
for (k, v) in rustc_args { | ||
args.set(k, v); | ||
} |
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 think you can simplify it to:
let mut args = FluentArgs::new(); | |
for (k, v) in rustc_args { | |
args.set(k, v); | |
} | |
let args = rustc_args.into_iter().collect(); |
let locale = match detect_system_locale() { | ||
Ok(loc) => loc, | ||
Err(_) => LanguageIdentifier::from_str(DEFAULT_LOCALE) | ||
.expect("Default locale should always be valid"), | ||
}; |
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 think you can simplify it to:
let locale = match detect_system_locale() { | |
Ok(loc) => loc, | |
Err(_) => LanguageIdentifier::from_str(DEFAULT_LOCALE) | |
.expect("Default locale should always be valid"), | |
}; | |
let locale = detect_system_locale().unwrap_or_else(|_| { | |
LanguageIdentifier::from_str(DEFAULT_LOCALE).expect("Default locale should always be valid") | |
}); |
// Always ensure DEFAULT_LOCALE is in the fallback chain | ||
let default_locale: LanguageIdentifier = DEFAULT_LOCALE | ||
.parse() | ||
.map_err(|_| LocalizationError::Parse("Failed to parse default locale".into()))?; | ||
|
||
if !locales_to_try.contains(&default_locale) { | ||
locales_to_try.push(default_locale); | ||
} |
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.
Is this code necessary? In setup_localization
you already add the DEFAULT_LOCALE
as a fallback locale and thus it is always in locales_to_try
because of line 100.
No description provided.