Skip to content
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

当代码注释中包含代码块的时候,将代码也翻译了,效果很不理想 #237

Open
tu6ge opened this issue Sep 20, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@tu6ge
Copy link

tu6ge commented Sep 20, 2024

截屏2024-09-20 15 51 05

截图是目前的效果,因为 rust 语言的注释中,可以包含代码,所以针对rust的代码块能不能做下区分呢,别翻译这块呢

@tu6ge
Copy link
Author

tu6ge commented Sep 20, 2024

原始内容如下

//! Value must be a valid email address, supported `String`, and other types always return false.
//!
//! # Examples
//! ```
//! # use serde::Serialize;
//! # use valitron::{available::{Email, MessageKind}, Validatable, Validator};
//! #[derive(Serialize, Debug)]
//! struct Input {
//!     email: String,
//!     password: String,
//! }
//!
//! let input = Input {
//!     email: String::from("user"),
//!     password: String::default(),
//! };
//! let err = input
//!     .validate(
//!         Validator::new()
//!             .rule("email", Email)
//!     )
//!     .unwrap_err();
//!
//! assert!(matches!(
//!     err.get("email").unwrap()[0].kind(),
//!     MessageKind::Email
//! ));
//!
//! let input = Input {
//!     email: String::from("[email protected]"),
//!     password: String::from("bar"),
//! };
//! input
//!     .validate(
//!         Validator::new()
//!             .rule("email", Email)
//!     )
//!     .unwrap();
//! ```

rust代码的注释也可能是这种情况

/// ```
/// let a = "foo";
/// ```

我可以参与代码贡献,但是我现在看到代码里注释很少,如果可以的话,可以提供一些思路,或者方向,我自己完成这块的改进

@intellism
Copy link
Owner

收到,注释内的代码判断目前做的比较粗糙。只是简单判断了下,是否跳过翻译。
后续优化下Rust的代码判断。

@intellism intellism added the bug Something isn't working label Sep 20, 2024
@intellism
Copy link
Owner

原始内容如下

//! Value must be a valid email address, supported `String`, and other types always return false.
//!
//! # Examples
//! ```
//! # use serde::Serialize;
//! # use valitron::{available::{Email, MessageKind}, Validatable, Validator};
//! #[derive(Serialize, Debug)]
//! struct Input {
//!     email: String,
//!     password: String,
//! }
//!
//! let input = Input {
//!     email: String::from("user"),
//!     password: String::default(),
//! };
//! let err = input
//!     .validate(
//!         Validator::new()
//!             .rule("email", Email)
//!     )
//!     .unwrap_err();
//!
//! assert!(matches!(
//!     err.get("email").unwrap()[0].kind(),
//!     MessageKind::Email
//! ));
//!
//! let input = Input {
//!     email: String::from("[email protected]"),
//!     password: String::from("bar"),
//! };
//! input
//!     .validate(
//!         Validator::new()
//!             .rule("email", Email)
//!     )
//!     .unwrap();
//! ```

rust代码的注释也可能是这种情况

/// ```
/// let a = "foo";
/// ```

我可以参与代码贡献,但是我现在看到代码里注释很少,如果可以的话,可以提供一些思路,或者方向,我自己完成这块的改进

思路:在这里判断注释内是否包含代码,如何是原文显示还是跳过翻译:

return compileBlock(this._block, this._currDocument.languageId);

@tu6ge
Copy link
Author

tu6ge commented Sep 23, 2024

奇怪的是,这个问题只出现了一次,后来再也没出现过,不知道如何复现问题,无从下手解决

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants